Skip to content

fix: unable use agent as a tool in agent component - #17228

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
Haruko386:major
Jul 22, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
Haruko386:major

Conversation

@Haruko386

@Haruko386 Haruko386 commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Summary

As title

image

@Haruko386 Haruko386 added the 🐞 bug Something isn't working, pull request that fix bug. label Jul 22, 2026
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 40403b73-ea22-4c0d-8b60-9d22fe1fd892

📥 Commits

Reviewing files that changed from the base of the PR and between 5b0e0be and eca4366.

📒 Files selected for processing (2)
  • internal/agent/component/agent.go
  • internal/agent/component/agent_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/agent/component/agent.go

📝 Walkthrough

Walkthrough

Agent parameters now support descriptions and nested sub-agents. Canvas configuration parses child Agents into dynamic tools, which invoke child components with structured prompts and return their output. Tests cover parsing, tool metadata, invocation, depth handling, and prompt forwarding.

Changes

Agent sub-agent tooling

Layer / File(s) Summary
Agent contracts and configuration parsing
internal/agent/component/agent.go
Agent parameters include descriptions and sub-agents; initialization and runtime parsing handle nested Agent tool specifications and history window settings.
Dynamic sub-agent tool invocation
internal/agent/component/agent.go
Static tools are combined with dynamic sub-agent tools that decode JSON arguments, enforce nesting depth, invoke child Agents, and return child content or serialized output.
Sub-agent tooling tests
internal/agent/component/agent_test.go
Tests validate schema-default prompt resolution, canvas parsing, generated tool metadata, unique normalized names, child invocation, returned output, and forwarded prompt sections.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CanvasConfig
  participant ParentAgent
  participant subAgentTool
  participant ChildAgent
  CanvasConfig->>ParentAgent: provide Agent tool specification
  ParentAgent->>subAgentTool: build dynamic tool
  ParentAgent->>subAgentTool: invoke with JSON arguments
  subAgentTool->>ChildAgent: invoke with forwarded prompt sections
  ChildAgent-->>subAgentTool: return agent output
  subAgentTool-->>ParentAgent: return content or JSON output
Loading

Suggested reviewers: hz-186, yuzhichang

Poem

A rabbit hops through tools anew,
And nests a smaller agent too.
JSON knocks; the child replies,
Prompted thoughts in neat disguise.
More carrots for this clever crew!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is too generic, offering only "As title" and an image without any real summary or background context. Add a brief summary of the problem, the approach taken, and any key implementation details or tradeoffs.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: enabling an agent to be used as a tool inside the agent component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@Haruko386
Haruko386 marked this pull request as draft July 22, 2026 05:42
@Haruko386
Haruko386 marked this pull request as ready for review July 22, 2026 05:42
@Haruko386 Haruko386 added the ci Continue Integration label Jul 22, 2026
@Haruko386
Haruko386 marked this pull request as draft July 22, 2026 05:45
@Haruko386
Haruko386 marked this pull request as ready for review July 22, 2026 05:49

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

🧹 Nitpick comments (1)
internal/agent/component/agent_test.go (1)

626-658: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Solid happy-path coverage; consider adding an error-path case.

Covers argument decoding → child invocation → prompt-forwarding well. Consider adding a case for malformed argsJSON to lock in the json.Unmarshal error-wrapping behavior in subAgentTool.InvokableRun.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/agent/component/agent_test.go` around lines 626 - 658, Extend
TestAgent_SubAgentToolInvokableRunCallsChildAgent with a malformed argsJSON case
that calls subAgentTool.InvokableRun, asserts an error is returned, and verifies
the error preserves the json.Unmarshal failure context through the expected
wrapping. Ensure the child agent is not invoked for invalid arguments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/agent/component/agent.go`:
- Around line 543-552: Thread a nested-agent depth counter through the context
used by sub-agent invocation: update subAgentTool.InvokableRun and the
NewAgentComponent/Invoke path to increment and validate depth before creating
another child agent, returning a clear error when the configured maximum is
reached. Ensure the guard applies transitively across buildAgentTools and
recursive canvas parsing, while preserving normal invocation behavior within the
allowed depth.
- Around line 1432-1499: Update agentParamFromMap to reuse mergeAgentParam for
user_prompt parsing instead of assigning the schema default as a literal prompt.
Ensure both New("Agent", ...) and embedded sub-agents interpret the placeholder
consistently, while preserving the existing fallback behavior when no parsed
user prompt is available.
- Around line 605-647: Update normalizeAgentToolName and the buildAgentTools
flow to guarantee unique sub-agent tool names, including names that normalize to
"agent" or otherwise collide. Track already-used names and either reject
duplicates clearly or assign a deterministic collision-resistant suffix before
appending each tool, ensuring every registered sub-agent remains callable.

---

Nitpick comments:
In `@internal/agent/component/agent_test.go`:
- Around line 626-658: Extend TestAgent_SubAgentToolInvokableRunCallsChildAgent
with a malformed argsJSON case that calls subAgentTool.InvokableRun, asserts an
error is returned, and verifies the error preserves the json.Unmarshal failure
context through the expected wrapping. Ensure the child agent is not invoked for
invalid arguments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3bf7af43-dd94-4976-bb9f-2d408abea803

📥 Commits

Reviewing files that changed from the base of the PR and between c6d9f84 and 5b0e0be.

📒 Files selected for processing (2)
  • internal/agent/component/agent.go
  • internal/agent/component/agent_test.go

Comment thread internal/agent/component/agent.go Resolved
Comment thread internal/agent/component/agent.go Resolved
Comment thread internal/agent/component/agent.go Resolved
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit db18766 into infiniflow:main Jul 22, 2026
4 of 6 checks passed
@Haruko386
Haruko386 deleted the major branch July 23, 2026 01:32
@coderabbitai coderabbitai Bot mentioned this pull request Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants