Repository navigation
llmModel - #1214
llmModel#1214
Conversation
WalkthroughTwo updates: a defensive check in Anthropics tool-message conversion avoids accessing properties on an undefined previous message, and the tools agent’s graph nodes now pass a model parameter to LLM call paths. Changes
Sequence Diagram(s)sequenceDiagram
participant Orchestrator as ToolsAgent Graph
participant Call as llmCallWithTools
participant LLM as LLM Provider
participant Tools as Tools Runtime
participant Resp as toolsResponseLLM
Orchestrator->>Call: inputs(messages, tools, params: {model, dataStream})
Call->>LLM: invoke(model, messages, tools, stream)
LLM-->>Call: tool_calls / assistant response
Call-->>Tools: execute tool_calls
Tools-->>Resp: tool results
Orchestrator->>Resp: inputs(messages, results, params: {model, dataStream})
Resp->>LLM: follow-up invoke(model, messages+tool_results, stream)
LLM-->>Resp: assistant response
Resp-->>Orchestrator: final response
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
llm_agents/tools_agent/src/tools_agent.ts (1)
7-12: Agents must consume themodelparameter
Our scan of the entirellm_agents/directory shows zero destructuring or use ofmodelfromparams/config, so the passedllmModel.valueis currently ignored. Please address the following before merging:
- llm_agents/tools_agent/src/tools_agent.ts
- In your agent handler, add something like:
const { /* other params */, model } = { ...params, ...(config || {}) }; // … then pass `model` into the LLM call- Agent schemas
- In each agent’s
info.inputs.properties, declare amodelfield so it shows up in the spec.- Workflow graphs
- Ensure all calls to these agents include
params.modelin their inputs.
🧹 Nitpick comments (5)
llm_agents/anthropic_agent/src/anthropic_agent.ts (5)
88-96: Harden JSON parsing for response_format to prevent runtime errorsIf the model emits non-JSON text when response_format is requested, JSON.parse will throw and fail the whole call. Wrap in try/catch.
- const responseFormat = (() => { - if (maybeResponseFormat && text) { - const parsed = JSON.parse(text); - if (typeof parsed === "object" && parsed !== null) { - return parsed; - } - } - return null; - })(); + const responseFormat = (() => { + if (maybeResponseFormat && text) { + try { + const parsed = JSON.parse(text); + if (typeof parsed === "object" && parsed !== null) { + return parsed; + } + } catch { + // ignore non-JSON text + } + } + return null; + })();
316-318: Guard JSON.parse for streamed tool_use input to avoid crashing on malformed/incomplete JSONDuring streaming, malformed JSON (or empty partials) would throw. Prefer a safe fallback.
- if (streamResponse.content[index].type === "tool_use") { - streamResponse.content[index].input = JSON.parse(partial); - } + if (streamResponse.content[index].type === "tool_use") { + try { + streamResponse.content[index].input = partial ? JSON.parse(partial) : {}; + } catch { + // Fallback: surface raw string if JSON is malformed + streamResponse.content[index].input = partial ?? ""; + } + }
51-75: Fix “Anthoropic” typo; add alias for backward compatibilityMinor typo in exported symbol and error message. Rename to anthropicTool2OpenAITool and keep the old name as an alias to avoid breaking imports. Also fix the error string.
-export const anthoropicTool2OpenAITool = (response: Response) => { +export const anthropicTool2OpenAITool = (response: Response) => { const contentText = response.content .filter((c): c is Anthropic.TextBlock => c.type === "text") .map((b) => b.text ?? "") .join(" "); @@ return { role: response.role, content: contentText }; }; +// Backward-compatibility alias (typo retained for existing imports) +export const anthoropicTool2OpenAITool = anthropicTool2OpenAITool;- const message = anthoropicTool2OpenAITool(response); + const message = anthropicTool2OpenAITool(response);- throw new Error("Anthoropic no response"); + throw new Error("Anthropic no response");Also applies to: 87-87, 310-310
142-148: Only add a text block when assistant text existsSlight efficiency/readability improvement: avoid emitting an empty "text" block.
- const content: { type: string; text?: string; id?: string; name?: string; input?: unknown }[] = [ - { - type: "text", - text: message.content, - }, - ]; + const content: { type: string; text?: string; id?: string; name?: string; input?: unknown }[] = []; + if (message.content) { + content.push({ + type: "text", + text: message.content, + }); + }
251-253: Remove unused ‘contents’ accumulatorThe local contents array is built but never read. Safe to drop.
- const contents = []; const partials = [];- if (messageStreamEvent.type === "content_block_delta" && messageStreamEvent.delta.type === "text_delta") { - const token = messageStreamEvent.delta.text; - contents.push(token); + if (messageStreamEvent.type === "content_block_delta" && messageStreamEvent.delta.type === "text_delta") { + const token = messageStreamEvent.delta.text; if (filterParams && filterParams.streamTokenCallback && token) {Also applies to: 281-284
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
llm_agents/anthropic_agent/src/anthropic_agent.ts(1 hunks)llm_agents/tools_agent/src/tools_agent.ts(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build (24.x)
- GitHub Check: build (22.x)
🔇 Additional comments (3)
llm_agents/anthropic_agent/src/anthropic_agent.ts (1)
164-170: Safer optional-chaining on previous entry — good defensive fixAvoids a potential crash when the previous tmp entry is missing or malformed.
llm_agents/tools_agent/src/tools_agent.ts (2)
22-24: Passing model through to the LLM call path — good additionPlumbs llmModel into the first LLM node alongside dataStream. Non-breaking and aligns with agents that accept a model param.
110-112: Model param forwarded for the follow-up LLM turn — LGTMEnsures the second LLM call (post tool-results) uses the same model setting.
Summary by CodeRabbit
New Features
Bug Fixes