Repository navigation
fix response of tools agent - #1209
Conversation
WalkthroughRenames 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
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 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
🧹 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 casellmToolCalls 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 outputThe 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 fieldsMessage 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 testtest 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.
📒 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 cleanlyRenaming to llmToolAgentRunner and gating on tool_calls improves clarity and avoids unnecessary nested execution.
68-71: Result buffering is a good additiontoolCallAgentResultsBuffer 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 UXPushing { data, agent, func } into toolCallAgentResults is consistent with the new toolsResults expectation. Nice.
127-139: Rewiring LLM messages to consume toolCallResultMessages is correctFeeding 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 upgradeProviding 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 behaviorarrayFindFirstExistsAgent 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 preciselyThe 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 interleavingtest 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.
Summary by CodeRabbit