Skip to content

add tools_agent-sequential - #1224

Merged
isamu merged 2 commits into
receptron:mainfrom
isamu:tools_agent-sequential
Sep 11, 2025
Merged

isamu merged 2 commits into
receptron:mainfrom
isamu:tools_agent-sequential

Conversation

@isamu

@isamu isamu commented Sep 11, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Introduced a sequential tools agent that orchestrates multi-step tool calls, enabling smoother, iterative interactions with tools.
    • Improved handling of tool call loops and responses, ensuring messages and results are consistently aggregated and returned.
    • Provides a ready-to-use sample demonstrating tool invocation with parameters for quicker onboarding.
  • Chores

    • Version bumped the tools agent package to 1.0.5.

@coderabbitai

coderabbitai Bot commented Sep 11, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new sequential tools agent implementation and exposes it as toolsSequentialAgent from both src and lib index files. Introduces a new TypeScript module defining the sequential graph-based flow. Updates package version to 1.0.5. No changes to existing toolsAgent behavior.

Changes

Cohort / File(s) Summary
Public API: add toolsSequentialAgent export
llm_agents/tools_agent/src/index.ts, llm_agents/tools_agent/lib/index.js, llm_agents/tools_agent/lib/index.d.ts
Import and re-export default from ./tools_agent-sequential as named export toolsSequentialAgent, alongside existing toolsAgent. Adjust CommonJS export initializers in lib.
New sequential tools agent implementation
llm_agents/tools_agent/src/tools_agent-sequential.ts
Adds graph-based sequential tools agent: defines workflow nodes (passthrough, llmCallWithTools, message aggregation, per-tool loop via llmToolAgentCallMap, toolsResponseLLM), selects result between plain LLM messages and tool-augmented messages. Exports AgentFunctionInfo as default.
Package metadata
llm_agents/tools_agent/package.json
Bumps version from 1.0.4 to 1.0.5.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as Caller
  participant A as toolsSequentialAgent
  participant L as LLM
  participant R as Tool Router
  participant T as Tool Impl(s)

  U->>A: input, system prompt, tools[]
  A->>L: llmCallWithTools(messages, tools)
  L-->>A: assistant message (+ optional tool_calls)

  alt No tool_calls
    A-->>U: justTextMessagesResult (messages)
  else tool_calls present
    loop For each tool_call
      A->>R: derive tool agent from name (split by --)
      R->>T: invoke tool with arguments
      T-->>R: tool result
      R-->>A: toolCallMessagesResult
      A->>L: toolsResponseLLM (messages + tool results)
      L-->>A: follow-up assistant message (+ optional tool_calls)
    end
    A-->>U: toolsResponseResultMessages
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Tools iterator #1207 — Introduces a similar multi-step/looping tool-call flow and updates the tools agent surface, paralleling this PR’s sequential implementation.
  • llmModel #1214 — Modifies parameters for llmCallWithTools and toolsResponseLLM nodes that this PR’s sequential agent defines.
  • update test #1189 — Updates tests around multi-step tool_calls, aligning with the new sequential tools agent behavior.

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "add tools_agent-sequential" is concise and directly describes the primary change in the PR—adding the new tools_agent-sequential module and exposing it—so it accurately summarizes the main intent of the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

I hop through graphs with orderly cheer,
Step by step, the tools draw near.
A flick of a paw, a loop well-spun,
Calls and replies, all neatly done.
Version bumped, horizons wide—
Sequential trails, a tidy ride. 🐇✨

✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

@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: 4

🧹 Nitpick comments (5)
llm_agents/tools_agent/src/tools_agent-sequential.ts (3)

107-114: Optionally pass tools on follow-up LLM calls.

Keeps the second LLM invocation capable of proposing further tool calls if you later extend the loop to consume them.

Apply:

           toolsResponseLLM: {
             agent: ":llmAgent",
             params: {
               forWeb: true,
               dataStream: true,
             },
-            inputs: { messages: ":toolCallMessagesResult.messages" },
+            inputs: { messages: ":toolCallMessagesResult.messages", tools: ":tools" },
           },

35-44: Remove unused params on copyAgent.

arrayKey has no effect on copyAgent here.

Apply:

-      agent: "copyAgent",
-      params: {
-        arrayKey: "messages",
-      },
+      agent: "copyAgent",

1-2: Re-export nestedAgentGenerator from @graphai/vanilla and stop importing /lib/generator directly.

Found direct imports of "@graphai/vanilla/lib/generator" in:

  • llm_agents/tools_agent/src/tools_agent-sequential.ts
  • llm_agents/tools_agent/src/tools_agent.ts
  • llm_agents/anthropic_agent/tests/tools_agent.ts
  • llm_agents/tools_agent/lib/tools_agent.js (built)

agents/vanilla_agents includes lib/generator.js and package.json lists "files":["./lib"], so the internal path currently resolves — but it's a brittle, non‑public import. Add a top-level export (e.g. in agents/vanilla_agents/src/index.ts: export { nestedAgentGenerator } from "./generator";) and update the above imports to:
import { nestedAgentGenerator } from "@graphai/vanilla";

llm_agents/tools_agent/lib/index.d.ts (2)

4-4: Remove redundant named export once using direct re-export.

If you apply the inline re-export, this becomes unnecessary.

-export { toolsSequentialAgent };

2-2: Prefer direct re-export to avoid extra import.

Replace the import + separate named export with a single direct re-export for toolsSequentialAgent in:

  • llm_agents/tools_agent/src/index.ts
  • llm_agents/tools_agent/lib/index.d.ts

Verified: llm_agents/tools_agent/src/tools_agent-sequential.ts exists and package.json.types points to ./lib/index.d.ts.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7785448 and e4bc525.

📒 Files selected for processing (5)
  • llm_agents/tools_agent/lib/index.d.ts (1 hunks)
  • llm_agents/tools_agent/lib/index.js (1 hunks)
  • llm_agents/tools_agent/package.json (1 hunks)
  • llm_agents/tools_agent/src/index.ts (1 hunks)
  • llm_agents/tools_agent/src/tools_agent-sequential.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
llm_agents/tools_agent/src/tools_agent-sequential.ts (1)
llm_agents/tools_agent/lib/tools_agent.js (2)
  • toolWorkFlowStep (4-156)
  • toolsAgentInfo (158-210)
⏰ 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 (4)
llm_agents/tools_agent/package.json (1)

3-3: Version bump looks fine.

No concerns with 1.0.5.

llm_agents/tools_agent/src/index.ts (1)

2-5: Approve — build exposes toolsSequentialAgent
Generated index.js and index.d.ts both contain imports/exports for toolsSequentialAgent alongside toolsAgent.

llm_agents/tools_agent/lib/index.js (2)

6-6: LGTM: Proper export hoisting.

Predeclaring both exports is standard for CJS transpiled output.


9-10: LGTM: New symbol exported without affecting existing API.

Default import wired to a named export as expected; ordering matches d.ts.

Comment on lines +35 to +44
justTextMessagesResult: {
unless: ":llmCallWithTools.tool.id",
agent: "copyAgent",
params: {
arrayKey: "messages",
},
inputs: {
messages: ":textMessagesResult.messages",
},
},

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.

⚠️ Potential issue

Condition mismatch will bypass tool flow.

justTextMessagesResult checks tool.id while the tool branch uses tool_calls. If tool_calls exist but tool.id is undefined, the non-tool path wins and tools are skipped.

Apply:

-    justTextMessagesResult: {
-      unless: ":llmCallWithTools.tool.id",
+    justTextMessagesResult: {
+      unless: ":llmCallWithTools.tool_calls",
       agent: "copyAgent",
-      params: {
-        arrayKey: "messages",
-      },
       inputs: {
         messages: ":textMessagesResult.messages",
       },
     },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
justTextMessagesResult: {
unless: ":llmCallWithTools.tool.id",
agent: "copyAgent",
params: {
arrayKey: "messages",
},
inputs: {
messages: ":textMessagesResult.messages",
},
},
justTextMessagesResult: {
unless: ":llmCallWithTools.tool_calls",
agent: "copyAgent",
inputs: {
messages: ":textMessagesResult.messages",
},
},
🤖 Prompt for AI Agents
In llm_agents/tools_agent/src/tools_agent-sequential.ts around lines 35 to 44,
the `justTextMessagesResult` condition uses `:llmCallWithTools.tool.id` which
mismatches the tool branch that checks `tool_calls`, allowing the non-tool path
to win when `tool_calls` exists but `tool.id` is undefined; change the `unless`
expression to check the same presence used by the tool branch (e.g.,
`:llmCallWithTools.tool_calls`) so the flow chooses the tool branch whenever
`tool_calls` are present.

Comment on lines +56 to +69
graph: {
version: 0.5,
loop: {
while: ":llmToolCalls",
},
nodes: {
toolsResponseMessages: {
// value: ":messages",
update: ":toolsResponseResultMessages.messages",
},
llmToolCalls: {
value: [],
update: ":llmToolCall.array",
},

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.

⚠️ Potential issue

Loop never seeds from inputs.

llmToolCalls is initialized to [], so while: ":llmToolCalls" can short-circuit. Seed from the nested agent input.

Apply:

-          llmToolCalls: {
-            value: [],
+          llmToolCalls: {
+            value: ":llmToolCalls",
             update: ":llmToolCall.array",
           },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
graph: {
version: 0.5,
loop: {
while: ":llmToolCalls",
},
nodes: {
toolsResponseMessages: {
// value: ":messages",
update: ":toolsResponseResultMessages.messages",
},
llmToolCalls: {
value: [],
update: ":llmToolCall.array",
},
graph: {
version: 0.5,
loop: {
while: ":llmToolCalls",
},
nodes: {
toolsResponseMessages: {
// value: ":messages",
update: ":toolsResponseResultMessages.messages",
},
llmToolCalls: {
value: ":llmToolCalls",
update: ":llmToolCall.array",
},
🤖 Prompt for AI Agents
In llm_agents/tools_agent/src/tools_agent-sequential.ts around lines 56 to 69,
the graph node llmToolCalls is initialized to an empty array which lets while:
":llmToolCalls" short-circuit; seed llmToolCalls from the nested agent input
instead (set its value to the nested input array, e.g. ":llmToolCall.array" to
match the existing update), so the loop has initial items to iterate over and
ensure the seeded value shape matches the update shape.

Comment on lines +76 to +83
toolCallAgent: {
agent: ":llmToolCall.item.name.split(--).$0",
inputs: {
arg: ":llmToolCall.item.arguments",
func: ":llmToolCall.item.name.split(--).$1",
tool_call: ":llmToolCall.item",
},
},

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.

🛠️ Refactor suggestion

Pass per-agent passthrough data to tools (parity with existing toolsAgent).

Sequential variant omits data, which many tool agents expect. Add a data node and wire it into toolCallAgent.

Apply:

+          data: {
+            agent: ({ passthrough, agentName }) => {
+              if (passthrough && passthrough[agentName]) return passthrough[agentName];
+              return {};
+            },
+            inputs: {
+              passthrough: ":passthrough",
+              agentName: ":llmToolCall.item.name.split(--).$0",
+            },
+          },
           toolCallAgent: {
             agent: ":llmToolCall.item.name.split(--).$0",
             inputs: {
               arg: ":llmToolCall.item.arguments",
               func: ":llmToolCall.item.name.split(--).$1",
               tool_call: ":llmToolCall.item",
+              data: ":data",
             },
           },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
toolCallAgent: {
agent: ":llmToolCall.item.name.split(--).$0",
inputs: {
arg: ":llmToolCall.item.arguments",
func: ":llmToolCall.item.name.split(--).$1",
tool_call: ":llmToolCall.item",
},
},
data: {
agent: ({ passthrough, agentName }) => {
if (passthrough && passthrough[agentName]) return passthrough[agentName];
return {};
},
inputs: {
passthrough: ":passthrough",
agentName: ":llmToolCall.item.name.split(--).$0",
},
},
toolCallAgent: {
agent: ":llmToolCall.item.name.split(--).$0",
inputs: {
arg: ":llmToolCall.item.arguments",
func: ":llmToolCall.item.name.split(--).$1",
tool_call: ":llmToolCall.item",
data: ":data",
},
},
🤖 Prompt for AI Agents
In llm_agents/tools_agent/src/tools_agent-sequential.ts around lines 76 to 83,
the Sequential variant is missing the per-agent passthrough `data` field
expected by many tool agents; add a `data` entry to the toolCallAgent inputs
(e.g. set data to ":llmToolCall.data") so the tool receives the same per-call
data as the existing toolsAgent, and ensure any upstream node that constructs
llmToolCall includes/forwards a .data property so this reference resolves.

Comment on lines +141 to +193
const toolsAgentInfo: AgentFunctionInfo = {
name: "toolsAgent",
agent: toolsAgent,
mock: toolsAgent,
samples: [
{
inputs: {
llmAgent: "openAIAgent",
tools: [
{
type: "function",
function: {
name: "lightAgent--toggleLight",
description: "Switch of light",
parameters: {
type: "object",
properties: {
switch: {
type: "boolean",
description: "change light state",
},
},
},
},
},
],
messages: [
{
role: "system",
content: "You are a light switch. Please follow the user's instructions.",
},
],
userInput: {
text: "turn on the light.",
message: {
role: "user",
content: "turn on the light.",
},
},
},
params: {},
result: "",
},
],
description: "",
category: [],
author: "",
repository: "",
source: "https://github.com/receptron/graphai/blob/main/llm_agents/tools_agent/src/tools_agent.ts",
package: "@graphai/tools_agent",
license: "",
hasGraphData: true,
};

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.

⚠️ Potential issue

Public name collision and incorrect source link.

This sequential agent is exported as toolsSequentialAgent, but AgentFunctionInfo.name is "toolsAgent" and source points to the non-sequential file. This can break registries and docs.

Apply:

-const toolsAgentInfo: AgentFunctionInfo = {
-  name: "toolsAgent",
+const toolsAgentInfo: AgentFunctionInfo = {
+  name: "toolsSequentialAgent",
   agent: toolsAgent,
   mock: toolsAgent,
@@
-  source: "https://github.com/receptron/graphai/blob/main/llm_agents/tools_agent/src/tools_agent.ts",
+  source: "https://github.com/receptron/graphai/blob/main/llm_agents/tools_agent/src/tools_agent-sequential.ts",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const toolsAgentInfo: AgentFunctionInfo = {
name: "toolsAgent",
agent: toolsAgent,
mock: toolsAgent,
samples: [
{
inputs: {
llmAgent: "openAIAgent",
tools: [
{
type: "function",
function: {
name: "lightAgent--toggleLight",
description: "Switch of light",
parameters: {
type: "object",
properties: {
switch: {
type: "boolean",
description: "change light state",
},
},
},
},
},
],
messages: [
{
role: "system",
content: "You are a light switch. Please follow the user's instructions.",
},
],
userInput: {
text: "turn on the light.",
message: {
role: "user",
content: "turn on the light.",
},
},
},
params: {},
result: "",
},
],
description: "",
category: [],
author: "",
repository: "",
source: "https://github.com/receptron/graphai/blob/main/llm_agents/tools_agent/src/tools_agent.ts",
package: "@graphai/tools_agent",
license: "",
hasGraphData: true,
};
const toolsAgentInfo: AgentFunctionInfo = {
name: "toolsSequentialAgent",
agent: toolsAgent,
mock: toolsAgent,
samples: [
{
inputs: {
llmAgent: "openAIAgent",
tools: [
{
type: "function",
function: {
name: "lightAgent--toggleLight",
description: "Switch of light",
parameters: {
type: "object",
properties: {
switch: {
type: "boolean",
description: "change light state",
},
},
},
},
},
],
messages: [
{
role: "system",
content: "You are a light switch. Please follow the user's instructions.",
},
],
userInput: {
text: "turn on the light.",
message: {
role: "user",
content: "turn on the light.",
},
},
},
params: {},
result: "",
},
],
description: "",
category: [],
author: "",
repository: "",
source: "https://github.com/receptron/graphai/blob/main/llm_agents/tools_agent/src/tools_agent-sequential.ts",
package: "@graphai/tools_agent",
license: "",
hasGraphData: true,
};
🤖 Prompt for AI Agents
In llm_agents/tools_agent/src/tools_agent-sequential.ts around lines 141 to 193,
the AgentFunctionInfo object uses name: "toolsAgent" and a source URL pointing
to the non-sequential file which causes public name collision and incorrect
docs/registry entries; change AgentFunctionInfo.name to "toolsSequentialAgent"
(matching the exported identifier) and update the source field to the sequential
file path (e.g., .../tools_agent-sequential.ts) so the registry and docs
reference the correct module.

@isamu
isamu merged commit 66c90be into receptron:main Sep 11, 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