diff --git a/src/config/index.ts b/src/config/index.ts index 5ffcf97..2907474 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -24,7 +24,7 @@ export function parseLLMConfig(config: LLMConfig): Required { baseURL: config.baseURL ?? DEFAULT_BASE_URL, apiKey: config.apiKey ?? DEFAULT_API_KEY, modelName: config.modelName ?? DEFAULT_MODEL_NAME, - temperature: config.temperature ?? 0.0, + temperature: config.temperature ?? 0.5, // higher randomness helps auto-recovery maxTokens: config.maxTokens ?? 4096, maxRetries: config.maxRetries ?? LLM_MAX_RETRIES, } diff --git a/src/llms/OpenAIClient.ts b/src/llms/OpenAIClient.ts index 95df2da..0c4a041 100644 --- a/src/llms/OpenAIClient.ts +++ b/src/llms/OpenAIClient.ts @@ -5,6 +5,12 @@ import { InvokeError, InvokeErrorType } from './errors' import type { InvokeResult, LLMClient, Message, OpenAIClientConfig, Tool } from './types' import { zodToOpenAITool } from './utils' +// Claude's openAI-API has different format for some fields +const CLAUDE_PATCH = { + tool_choice: { type: 'tool', name: 'AgentOutput' }, + thinking: { type: 'disabled' }, +} + export class OpenAIClient implements LLMClient { config: OpenAIClientConfig @@ -21,7 +27,7 @@ export class OpenAIClient implements LLMClient { const openaiTools = Object.entries(tools).map(([name, tool]) => zodToOpenAITool(name, tool)) // 2. Detect if Claude (auto-compatibility) - // const isClaude = this.config.model.toLowerCase().includes('claude') + const isClaude = this.config.model.toLowerCase().startsWith('claude') // 3. Call API let response: Response @@ -34,18 +40,21 @@ export class OpenAIClient implements LLMClient { }, body: JSON.stringify({ model: this.config.model, - messages, - parallel_tool_calls: false, - tools: openaiTools, - tool_choice: 'required', - // tool_choice: { type: 'function', function: { name: 'my_function' } }, - // reasoning_effort: 'minimal', - // verbosity: 'low', - - // Claude doesn't support tool_choice: 'required', auto-omit - // ...(isClaude ? {} : { tool_choice: 'required' }), temperature: this.config.temperature, max_tokens: this.config.maxTokens, + messages, + + tools: openaiTools, + // tool_choice: 'required', + tool_choice: { type: 'function', function: { name: 'AgentOutput' } }, + + // model specific params + + // reasoning_effort: 'minimal', + // verbosity: 'low', + parallel_tool_calls: false, + + ...(isClaude ? CLAUDE_PATCH : {}), }), signal: abortSignal, })