Repository navigation
add tools_agent-sequential - #1224
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Poem
✨ 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. Comment |
There was a problem hiding this comment.
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.
arrayKeyhas no effect oncopyAgenthere.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
📒 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.
| justTextMessagesResult: { | ||
| unless: ":llmCallWithTools.tool.id", | ||
| agent: "copyAgent", | ||
| params: { | ||
| arrayKey: "messages", | ||
| }, | ||
| inputs: { | ||
| messages: ":textMessagesResult.messages", | ||
| }, | ||
| }, |
There was a problem hiding this comment.
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.
| 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.
| graph: { | ||
| version: 0.5, | ||
| loop: { | ||
| while: ":llmToolCalls", | ||
| }, | ||
| nodes: { | ||
| toolsResponseMessages: { | ||
| // value: ":messages", | ||
| update: ":toolsResponseResultMessages.messages", | ||
| }, | ||
| llmToolCalls: { | ||
| value: [], | ||
| update: ":llmToolCall.array", | ||
| }, |
There was a problem hiding this comment.
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.
| 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.
| toolCallAgent: { | ||
| agent: ":llmToolCall.item.name.split(--).$0", | ||
| inputs: { | ||
| arg: ":llmToolCall.item.arguments", | ||
| func: ":llmToolCall.item.name.split(--).$1", | ||
| tool_call: ":llmToolCall.item", | ||
| }, | ||
| }, |
There was a problem hiding this comment.
🛠️ 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.
| 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.
| 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, | ||
| }; |
There was a problem hiding this comment.
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.
| 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.
Summary by CodeRabbit
New Features
Chores