π The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(agent-execute): omit removed sampling params for Fable 5 / Opus 4.8 / Opus 4.7 (#2357) (#2358)
Mr. Makb12788777a64
diff --git a/v3/@claude-flow/cli/__tests__/sampling-params-2357.test.ts b/v3/@claude-flow/cli/__tests__/sampling-params-2357.test.tsnew file mode 100644index 0000000000..919dc53f1c--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/sampling-params-2357.test.ts@@ -0,0 +1,111 @@+/**+ * Regression test for #2357 (Finding A): callAnthropicMessages always sent+ * `temperature` (default 0.7), but the adaptive-thinking family β Fable 5,+ * Opus 4.8, Opus 4.7 β removed temperature/top_p/top_k. The API rejects the+ * request with 400 "temperature: Extra inputs are not permitted", so+ * agent_execute / workflow_run / the WASM-agent Anthropic path could not+ * call any current frontier model when an ANTHROPIC_API_KEY was set.+ *+ * Pin the contract: sampling params are omitted for models that reject them,+ * and unchanged (including the 0.7 default) for models that still accept+ * them. The Ollama / OpenRouter OpenAI-compat paths are out of scope β they+ * accept temperature.+ */++import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';+import {+ callAnthropicMessages,+ modelRejectsSamplingParams,+} from '../src/mcp-tools/agent-execute-core.js';++describe('modelRejectsSamplingParams (#2357)', () => {+ it.each([+ 'claude-fable-5',+ 'claude-opus-4-8',+ 'claude-opus-4-7',+ ])('rejects sampling params for %s', (m) => {+ expect(modelRejectsSamplingParams(m)).toBe(true);+ });++ it('covers dated snapshots of the same family', () => {+ expect(modelRejectsSamplingParams('claude-opus-4-8-20260301')).toBe(true);+ });++ it.each([+ 'claude-sonnet-4-6',+ 'claude-haiku-4-5-20251001',+ 'claude-opus-4-6', // pre-4.7 Opus still accepts sampling params+ ])('keeps sampling params for %s', (m) => {+ expect(modelRejectsSamplingParams(m)).toBe(false);+ });+});++describe('callAnthropicMessages request body (#2357)', () => {+ const captured: Array<Record<string, unknown>> = [];+ const savedEnv = { ...process.env };++ beforeEach(() => {+ captured.length = 0;+ process.env.ANTHROPIC_API_KEY = 'sk-ant-test-not-real';+ delete process.env.RUFLO_PROVIDER;+ delete process.env.OPENROUTER_API_KEY;+ delete process.env.OLLAMA_API_KEY;+ vi.stubGlobal(+ 'fetch',+ vi.fn(async (_url: string, opts: { body: string }) => {+ const body = JSON.parse(opts.body) as Record<string, unknown>;+ captured.push(body);+ return {+ ok: true,+ json: async () => ({+ id: 'msg_test',+ model: body.model,+ content: [{ type: 'text', text: 'ok' }],+ stop_reason: 'end_turn',+ usage: { input_tokens: 1, output_tokens: 1 },+ }),+ };+ })+ );+ });++ afterEach(() => {+ vi.unstubAllGlobals();+ process.env = { ...savedEnv };+ });++ it.each([+ 'claude-fable-5',+ 'claude-opus-4-8',+ 'claude-opus-4-7',+ ])('omits temperature for %s (the API 400s otherwise)', async (model) => {+ const r = await callAnthropicMessages({ prompt: 'ping', model, maxTokens: 8 });+ expect(r.success).toBe(true);+ expect(captured[0]).not.toHaveProperty('temperature');+ });++ it('still sends the 0.7 default for models that accept sampling params', async () => {+ await callAnthropicMessages({ prompt: 'ping', model: 'claude-sonnet-4-6', maxTokens: 8 });+ expect(captured[0]).toHaveProperty('temperature', 0.7);+ });++ it('honors an explicit temperature for accepting models', async () => {+ await callAnthropicMessages({+ prompt: 'ping',+ model: 'claude-haiku-4-5-20251001',+ temperature: 0.2,+ maxTokens: 8,+ });+ expect(captured[0]).toHaveProperty('temperature', 0.2);+ });++ it('drops even an explicit temperature for frontier models (would 400)', async () => {+ await callAnthropicMessages({+ prompt: 'ping',+ model: 'claude-fable-5',+ temperature: 0.9,+ maxTokens: 8,+ });+ expect(captured[0]).not.toHaveProperty('temperature');+ });+});diff --git a/v3/@claude-flow/cli/src/mcp-tools/agent-execute-core.ts b/v3/@claude-flow/cli/src/mcp-tools/agent-execute-core.tsindex 78421de4b4..eda5830638 100644--- a/v3/@claude-flow/cli/src/mcp-tools/agent-execute-core.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/agent-execute-core.ts@@ -69,6 +69,16 @@ const MODEL_MAP: Record<string, string> = {inherit: DEFAULT_ANTHROPIC_MODEL,};+// #2357 β the adaptive-thinking family (Fable 5, Opus 4.8, Opus 4.7) removed+// the sampling parameters (temperature/top_p/top_k); the Anthropic API+// returns 400 "Extra inputs are not permitted" when any is present.+// Prefix-match so dated snapshots (e.g. claude-opus-4-8-YYYYMMDD) are+// covered. Applies only to the direct Anthropic path β the Ollama/OpenRouter+// OpenAI-compat paths accept temperature and are unchanged.+export function modelRejectsSamplingParams(model: string): boolean {+ return /^claude-(fable-5|opus-4-8|opus-4-7)/.test(model);+}+export interface AnthropicCallInput {prompt: string;systemPrompt?: string;@@ -150,7 +160,13 @@ export async function callAnthropicMessages(input: AnthropicCallInput): Promise<body: JSON.stringify({model,max_tokens: input.maxTokens || 1024,- temperature: typeof input.temperature === 'number' ? input.temperature : 0.7,+ // #2357 β omit temperature for models that reject sampling params+ // (Fable 5 / Opus 4.8 / Opus 4.7 β 400 "Extra inputs are not+ // permitted"); keep the 0.7 default unchanged for models that still+ // accept it (sonnet / haiku / opus β€4.6).+ ...(modelRejectsSamplingParams(model)+ ? {}+ : { temperature: typeof input.temperature === 'number' ? input.temperature : 0.7 }),// #8 prompt caching (hermes-agent pattern): mark the (often large,// stable) system prompt as an ephemeral cache breakpoint so repeated// agent_execute calls with the same system prompt hit Anthropic's