Skip to content

Tools iterator - #1207

Merged
isamu merged 5 commits into
receptron:mainfrom
isamu:toolsIterator
Aug 15, 2025
Merged

isamu merged 5 commits into
receptron:mainfrom
isamu:toolsIterator

Conversation

@isamu

@isamu isamu commented Aug 15, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Support multiple tool invocations in a single interaction with per-call message accumulation and selection of the first non-empty result (considers initial text path alongside tool responses).
  • Refactor

    • Reorganized the tool invocation flow into a loop-driven, multi-step pipeline and simplified final result aggregation by removing legacy gating.
  • Tests

    • Updated tests for multi-step tool chains, array-based tool calls, renamed scenarios, and adjusted expected assistant messages (adds initial user message in no-tool cases).
  • Chores

    • Package version bumped to 1.0.3.

@coderabbitai

coderabbitai Bot commented Aug 15, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Refactors the tools agent to run multiple tool invocations in a loop, accumulate per-call messages and results, and route the final aggregation from either the initial text path or collected tool responses. Tests updated to use array-based tool_calls and per-call data payloads.

Changes

Cohort / File(s) Summary
Agent workflow refactor
llm_agents/tools_agent/src/tools_agent.ts
Adds top-level llmAgent and textMessagesResult; replaces mapAgent with a nestedAgent loop over llmToolCalls; introduces toolCallAgent, toolCallMessagesResult, toolsResponseLLM, and toolsResponseResultMessages; accumulates per-call messages/results; removes legacy nodes (mergedData, toolsResult, toLLMToolCallAgentResponse); updates final result inputs to use llmToolAgentCallMap.toolsResponseResultMessages.messages.
Tests update for multi-tool flow
llm_agents/tools_agent/tests/test_tools.ts
Converts test doubles to return multi-step tool_calls arrays and per-call data payloads; replaces skipNext with explicit data; adjusts assistant content logic for tool outcomes; adds multi-step fixtures and expectations (e.g., chained getWeather → textSpeach); ensures initial user message presence in applicable scenarios.
Package metadata
llm_agents/tools_agent/package.json
Bumps package version from 1.0.2 to 1.0.3 (metadata-only change).

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant ToolsAgent
  participant textMessagesResult
  participant llmAgent
  participant llmToolAgentCallMap
  participant toolCallAgent
  participant toolsResponseLLM
  participant toolsResponseResultMessages
  participant FinalAggregator

  User->>ToolsAgent: input text
  ToolsAgent->>textMessagesResult: build messages [user, current llmCallWithTools]
  ToolsAgent->>llmAgent: send messages
  llmAgent-->>ToolsAgent: assistant message with tool_calls[]
  ToolsAgent->>llmToolAgentCallMap: start loop over llmToolCalls

  loop For each llmToolCall
    llmToolAgentCallMap->>toolCallAgent: assemble per-call payload (arg, func, tool_call, data)
    toolCallAgent-->>llmToolAgentCallMap: toolCallMessagesResult.messages
    llmToolAgentCallMap->>toolsResponseLLM: feed per-call messages
    toolsResponseLLM-->>toolsResponseResultMessages: per-call LLM output
  end

  ToolsAgent->>FinalAggregator: choose first non-empty from text path or toolsResponseResultMessages
  FinalAggregator-->>User: final result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • update test #1189: Implements and tests multi-step tool invocation handling in llm_agents/tools_agent; directly overlaps with the multi-call test and agent changes.
  • add test #1187: Modifies the agent/tests around tool_calls and response wiring; aligns with the looped invocation and message accumulation updates.

Poem

I hop through calls, one, two, then three,
Bundle messages snug as a leaf on a tree.
Each tool returns a nibble of truth,
I gather and stitch them, a rabbit in sooth.
Hooray — results stitched into harmony. 🐰✨


📜 Recent 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 b712ffe and c6fe438.

📒 Files selected for processing (1)
  • llm_agents/tools_agent/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • llm_agents/tools_agent/package.json
⏰ 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)
✨ Finishing Touches
🧪 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: 1

🧹 Nitpick comments (1)
llm_agents/tools_agent/tests/test_tools.ts (1)

72-78: Guard against non-string tool contents in success message

last.content is assumed to be a string. For resilience (e.g., if a tool returns an object), coerce to string.

-        content: "success " + last.content,
+        content: "success " + (typeof last.content === "string" ? last.content : JSON.stringify(last.content)),
📜 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 fcfd4e4 and b712ffe.

📒 Files selected for processing (2)
  • llm_agents/tools_agent/src/tools_agent.ts (2 hunks)
  • llm_agents/tools_agent/tests/test_tools.ts (10 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • llm_agents/tools_agent/src/tools_agent.ts
🔇 Additional comments (6)
llm_agents/tools_agent/tests/test_tools.ts (6)

14-16: LGTM: tool responses now include data payloads

Including structured data in tool results aligns with the new multi-step flow and matches expectations asserted in the tests’ extra.data field.

Also applies to: 22-24


36-42: LGTM: array-based tool_calls for multi-step flows

Returning an array of tool calls (with unique ids and arguments) cleanly models the multi-tool sequence and improves extensibility for future steps.

Also applies to: 45-56


117-120: LGTM: initial user message is persisted

Capturing the initial user message in the transcript improves traceability in the “no tools” scenario.


165-169: LGTM: single-tool path expectations are consistent

The sequence (assistant tool_calls → tool result with extra payload → assistant success) accurately reflects the updated loop-driven pipeline.

Also applies to: 175-187, 191-191


65-69: Do not remove top-level tool / tool_calls — they're consumed by tools_agent

tools_agent references both keys, so removing the top-level fields would break consumers.

  • llm_agents/tools_agent/src/tools_agent.ts — line ~36 references ":llmCallWithTools.tool.id" (justTextMessagesResult).
  • llm_agents/tools_agent/src/tools_agent.ts — lines ~47–53 reference/forward ":llmCallWithTools.tool_calls" (llmToolAgentCallMap → inputs.llmToolCalls).

Keep the returned top-level fields as-is, or update these consumers before removing the duplication.

Likely an incorrect or invalid review comment.


263-265: Interleaving verified — no change needed

I inspected llm_agents/tools_agent/src/tools_agent.ts. The nested graph maps llmToolCalls (":llmCallWithTools.tool_calls"), uses loop: while ":llmToolCalls", and the node toolsResponseLLM invokes agent ":llmAgent" with messages ":toolCallMessagesResult.messages". That confirms the agent iterates the pre-announced llmToolCalls and calls the LLM between tool executions.

  • File: llm_agents/tools_agent/src/tools_agent.ts
    • llmToolAgentCallMap / graph.loop: while ":llmToolCalls" (approx. lines 46–61)
    • toolCallMessagesResult (approx. lines 82–88)
    • toolsResponseLLM → agent ":llmAgent" (approx. lines 107–113)

No changes required.

},
};
}
if (func === "textSpeach") {

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.

💡 Verification agent

🧩 Analysis chain

Typo: rename textSpeach → textSpeech for clarity

Minor naming nit. Standard spelling is “Speech.” If you adopt this, ensure consistency across the codebase and tools schema.

-  if (func === "textSpeach") {
+  if (func === "textSpeech") {
     return {
       content: "speech",
       data: {
         talk: "snow",
       },
     };
   }
-          name: "toolsTestAgent--textSpeach",
+          name: "toolsTestAgent--textSpeech",
-          name: "toolsTestAgent--textSpeach",
+          name: "toolsTestAgent--textSpeech",
-            func: "textSpeach",
+            func: "textSpeech",

To find other occurrences you may need to rename:

Also applies to: 53-55, 239-239, 269-269, 277-277


🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n -C2 '\btextSpeach\b'

Length of output: 1898


Typo: rename textSpeach → textSpeech

Standard spelling is "speech" — please rename occurrences in the test to keep names and tool schema consistent.

Files / locations to change:

  • llm_agents/tools_agent/tests/test_tools.ts:19 — if-check
  • llm_agents/tools_agent/tests/test_tools.ts:53 — name
  • llm_agents/tools_agent/tests/test_tools.ts:239 — name
  • llm_agents/tools_agent/tests/test_tools.ts:269 — name
  • llm_agents/tools_agent/tests/test_tools.ts:276 — func

Suggested edits:

-  if (func === "textSpeach") {
+  if (func === "textSpeech") {
     return {
       content: "speech",
       data: {
         talk: "snow",
       },
     };
   }
-          name: "toolsTestAgent--textSpeach",
+          name: "toolsTestAgent--textSpeech",

(Apply the name change at all three name locations above.)

-            func: "textSpeach",
+            func: "textSpeech",

Quick check you can run to find any remaining occurrences:

rg -n -C2 '\btextSpeach\b'
🤖 Prompt for AI Agents
In llm_agents/tools_agent/tests/test_tools.ts around lines 19–276, there's a
typo using "textSpeach" instead of "textSpeech"; update all occurrences listed
(line 19 if-check, line 53 name, line 239 name, line 269 name, and line 276
func) to "textSpeech" so tests and tool schema match, then run a quick search
(e.g., rg -n '\btextSpeach\b') to ensure no remaining references and update any
additional occurrences found.

@isamu
isamu merged commit 327b7b2 into receptron:main Aug 15, 2025
This was referenced Aug 15, 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