Skip to content

llmModel - #1214

Merged
isamu merged 1 commit into
receptron:mainfrom
isamu:toolsllmModel
Aug 17, 2025
Merged

isamu merged 1 commit into
receptron:mainfrom
isamu:toolsllmModel

Conversation

@isamu

@isamu isamu commented Aug 17, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added model selection support for tool-enabled LLM calls and tool-response generation in workflows, enabling consistent model control across steps.
  • Bug Fixes

    • Improved stability when handling tool messages to prevent rare crashes caused by missing or malformed prior entries.

@coderabbitai

coderabbitai Bot commented Aug 17, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Two 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

Cohort / File(s) Summary
Anthropic tool-message safety
llm_agents/anthropic_agent/src/anthropic_agent.ts
Uses optional chaining (last?.role, last?.content?.[0]?.type) when converting OpenAI tool messages to Anthropic format to avoid runtime errors when prior entries are absent or malformed. No other logic altered.
Tools agent model param wiring
llm_agents/tools_agent/src/tools_agent.ts
Adds params.model=":llmModel" to llmCallWithTools and toolsResponseLLM node inputs alongside existing dataStream wiring; no control-flow or other field 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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • tools #1213 — Touches the same convOpenAIToolsToAnthropicToolMessage function, adjusting its tool-message mapping logic.
  • fix response of tools agent #1209 — Modifies llmCallWithTools/toolsResponseLLM nodes and their message/result wiring in tools_agent.ts.
  • Tools palla #1212 — Refactors the same workflow nodes to support streaming/tool orchestration; overlaps with model/stream param paths.

Poem

A nibble of code, a carrot of care,
I hopped through messages, minding the air—
If no last crumb, I won’t despair;
I pass the model, neat and fair.
Tools now chat with LLM flair—
Thump-thump! Shipping bugs beware. 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
llm_agents/tools_agent/src/tools_agent.ts (1)

7-12: Agents must consume the model parameter
Our scan of the entire llm_agents/ directory shows zero destructuring or use of model from params/config, so the passed llmModel.value is 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 a model field so it shows up in the spec.
  • Workflow graphs
    • Ensure all calls to these agents include params.model in 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 errors

If 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 JSON

During 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 compatibility

Minor 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 exists

Slight 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’ accumulator

The 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.

📥 Commits

Reviewing files that changed from the base of the PR and between f9f84fd and a09de02.

📒 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 fix

Avoids 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 addition

Plumbs 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 — LGTM

Ensures the second LLM call (post tool-results) uses the same model setting.

@isamu
isamu merged commit 05b49a4 into receptron:main Aug 17, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant