Skip to content

fix response of tools agent - #1209

Merged
isamu merged 1 commit into
receptron:mainfrom
isamu:toolsData
Aug 15, 2025
Merged

isamu merged 1 commit into
receptron:mainfrom
isamu:toolsData

Conversation

@isamu

@isamu isamu commented Aug 15, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added a toolsResults field to outputs, aggregating per-tool invocation results (agent, function, and data) while preserving existing messages.
  • Refactor
    • Streamlined tool-call handling with improved buffering and aggregation for clearer final results.
  • Tests
    • Updated expectations to include toolsResults for single and multiple tool calls and added a new test to validate the aggregated result.

@coderabbitai

coderabbitai Bot commented Aug 15, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Renames llmToolAgentCallMap to llmToolAgentRunner. Adds buffering (toolCallAgentResultsBuffer) and per-call result collection (toolCallAgentResults). Rewires message/result propagation to toolCallResultMessages and toolsResponseLLM. Introduces mergedLllmToolAgentRunner aggregating toolsResults and messages. Updates tests to expect a top-level toolsResults array alongside existing tools messages.

Changes

Cohort / File(s) Summary
Tools agent orchestration update
llm_agents/tools_agent/src/tools_agent.ts
Renamed node to llmToolAgentRunner; added toolCallAgentResultsBuffer and toolCallAgentResults; replaced toolCallMessagesResult with toolCallAgentResults/toolCallResultMessages; updated toolsResponseLLM inputs; added mergedLllmToolAgentRunner aggregating toolsResults and messages; updated final result wiring; minor formatting cleanup.
Tests adjusted for aggregated results
llm_agents/tools_agent/tests/test_tools.ts
Updated expectations to include top-level toolsResults array; added coverage for single and multiple tool invocations; preserved existing tools.messages checks.

Sequence Diagram(s)

sequenceDiagram
  participant ToolsAgent as llmToolAgentRunner
  participant ToolCall as toolCallAgent
  participant Push as pushAgent (toolCallAgentResults)
  participant Msgs as toolCallResultMessages
  participant LLM as toolsResponseLLM
  participant Merge as mergedLllmToolAgentRunner
  participant Result as result

  ToolsAgent->>ToolCall: Invoke per tool call
  ToolCall-->>Push: Emit {agent, func, data}
  Push-->>ToolsAgent: Append to toolCallAgentResultsBuffer
  ToolsAgent->>Msgs: Build messages from buffer
  Msgs-->>LLM: Provide messages
  LLM-->>ToolsAgent: toolsResponseResultMessages
  ToolsAgent->>Merge: Copy {toolsResults, messages}
  Merge-->>Result: Provide final aggregated output
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • add test #1187 — Adjusts tools_agent tests asserting tool-call outputs, overlapping with the new toolsResults aggregation.
  • Tools iterator #1207 — Changes the same tool-call loop and node wiring (runner rename, aggregation and routing) aligned with this PR’s flow updates.

Poem

I buffered the tools in a tidy queue,
Results in a basket, messages too.
Hops through the runner, quick as a wink,
Merge at the finish, carrots in sync.
Thump goes the tail—tests pass anew! 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

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

@isamu
isamu merged commit 69d0f32 into receptron:main Aug 15, 2025

@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

🧹 Nitpick comments (4)
llm_agents/tools_agent/src/tools_agent.ts (3)

61-67: Seed the loop state from input to avoid empty-loop edge case

llmToolCalls is initialized with value: [] and updated from :llmToolCall.array. Depending on resolution precedence between nested inputs and node declarations, this can shadow the incoming input (llmToolAgentRunner.inputs.llmToolCalls) and start the loop with an empty array.

Recommend explicitly seeding the node from the nested input to make the loop behavior unambiguous.

Proposed change:

-          llmToolCalls: {
-            value: [],
-            update: ":llmToolCall.array",
-          },
+          llmToolCalls: {
+            // Seed from nested input to avoid shadowing/empty init
+            value: ":llmToolCalls",
+            update: ":llmToolCall.array",
+          },

If value does not support references in your DSL, introduce a small copy node before the loop to initialize state from the nested input, and reference that node in while and shiftAgent.


79-85: Validate dynamic agent resolution derived from LLM output

The agent is selected via the LLM-supplied name (split by --). This is flexible, but if the LLM (or upstream mapping) ever emits an unexpected agent id, you could attempt to invoke a non-whitelisted agent.

  • Suggest: validate the extracted agent and func against the provided tools schema or a whitelist before invocation; otherwise, short-circuit with a controlled error/tool-fail message.

I can propose a small guard node that checks membership in the allowed tools list and emits a safe error message if it’s not allowed. Want me to draft it?


98-120: Tool result message construction is coherent; consider dedup of extra fields

Message payload includes content plus extra { agent, arg, func, data }. This mirrors toolsResults and is useful for debugging. If output size is a concern, consider trimming duplication (e.g., omit data here and rely on toolsResults), but that’s optional.

llm_agents/tools_agent/tests/test_tools.ts (1)

326-406: tests: non-empty initial messages are handled; consider adding a malformed tool test

test tools 3 ensures prior messages are preserved and the loop still behaves. As an enhancement, consider a test where the tool name is malformed or unknown to confirm graceful failure (ties to the validation suggestion in src).

I can add a test that emits an unexpected tool name and asserts a safe error result instead of invoking an arbitrary agent. Want me to draft it?

📜 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 27ef541 and c6f3ccb.

📒 Files selected for processing (2)
  • llm_agents/tools_agent/src/tools_agent.ts (5 hunks)
  • llm_agents/tools_agent/tests/test_tools.ts (2 hunks)
🔇 Additional comments (8)
llm_agents/tools_agent/src/tools_agent.ts (6)

45-55: Rename and gating are sensible; nested runner reads cleanly

Renaming to llmToolAgentRunner and gating on tool_calls improves clarity and avoids unnecessary nested execution.


68-71: Result buffering is a good addition

toolCallAgentResultsBuffer with update → :toolCallAgentResults.array is a clear way to accumulate per-call outputs across iterations.


86-97: Per-call result envelope matches tests and improves downstream UX

Pushing { data, agent, func } into toolCallAgentResults is consistent with the new toolsResults expectation. Nice.


127-139: Rewiring LLM messages to consume toolCallResultMessages is correct

Feeding toolsResponseLLM with aggregated messages and pushing the LLM response back into the stream achieves the iterative tool-call loop correctly.


144-150: Merged sink (messages + toolsResults) is a solid interface upgrade

Providing a mergedLllmToolAgentRunner with both messages and toolsResults simplifies the result node and aligns with test expectations.


155-156: Result selection logic is correct; preserves no-tools behavior

arrayFindFirstExistsAgent over justTextMessagesResult first, then merged tool runner, maintains backward compatibility for no-tool cases.

llm_agents/tools_agent/tests/test_tools.ts (2)

154-207: tests: toolsResults shape and contents are asserted precisely

The added assertion for tools.toolsResults in test tools 1 correctly validates agent, func, and data payload for a single tool call.


235-324: tests: multiple tool calls are covered with correct interleaving

test tools 2 verifies:

  • Two tool calls in tool_calls
  • Interleaved assistant responses after each tool message
  • toolsResults includes both calls with correct ordering

Good coverage for the multi-call path.

This was referenced Aug 17, 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