Composing Subagents

Nested agents, each an ordinary BxAgents project of its own, wired as callable tools.

On this page

Composing Subagents

subagents/ holds nested agents - each an ordinary BxAgents project of its own, with its own Agent.yml + instructions.md, and optionally its own tools/, skills/, etc.

my-agent/
β”œβ”€β”€ Agent.yml            # subAgents: [ researcher ]
β”œβ”€β”€ instructions.md
└── subagents/
    └── researcher/
        β”œβ”€β”€ Agent.yml
        └── instructions.md

A subagent is wired to its parent by name, declared in the parent's Agent.yml

  • this is the subagents/ folder name:
subAgents: [ researcher ]

At build time, bx-ai's addSubAgent() wraps each built subagent instance as a callable tool on the parent automatically - there's no separate tool-wrapping step to write yourself.

Flat on disk, a graph in config

Every subagent - no matter how deeply another subagent's own config references it - lives directly under the root project's subagents/ folder. A subagent's own declared subAgents names reference sibling entries in that same root-level folder, never a folder nested under itself.

flowchart LR
    subgraph disk["ON DISK - always flat"]
        direction TB
        R1["subagents/A/"]
        R2["subagents/B/"]
        R3["subagents/C/"]
    end
    subgraph declared["DECLARED - each agent definition's own subAgents list"]
        direction TB
        GA["A"] --> GB["B"] --> GC["C"]
    end
    subgraph built["BUILT - leaf-first"]
        direction TB
        O1["1. build C"] --> O2["2. build B<br/>with the built C"] --> O3["3. build A<br/>with the built B"]
    end
    disk -.-> declared
    declared -.-> built

A cycle in the declared graph (A -> B -> A) is rejected at validation, before anything is generated. A diamond (two parents sharing one descendant) is fine.

Two different names, two different jobs

  • The folder name under subagents/ is what subAgents: [ "..." ] references - purely a build-time wiring concern.
  • The subagent's own declared name (its definition's name field) is what you retrieve it by at runtime - every agent in the tree is registered in config/WireBox.bx under this name, so a schedules/ scheduler (or anything else WireBox-aware) reaches it with getInstance( "TheAgentName" ).

These two names can differ, and often will. Because name is now also a WireBox binding key, it must be unique across the whole project - build fails validation if two agents share one.

Try it

Acme support gets two helpers: a researcher that looks things up and a writer that words the final reply. Each is a folder with its own Agent.yml and instructions.md, and each picks one of the profiles from Models and Profiles. (bxAgents add subagent researcher --profile=fast writes the same frame and wires it in for you.)

name: researcher
description: Looks things up and writes a short summary with sources.
profile: fast
You research a question and answer with a short summary and the sources you used.
name: writer
description: Turns facts into a friendly reply for a customer.
profile: planner
You write the final reply to a customer from the facts you are given. Be brief and friendly.

Wire them to the root agent, with the folder names, at the end of Agent.yml:


subAgents: [ researcher, writer ]

Rebuild and look at what the root agent can use. Each subagent arrived as a tool called delegate_to_<name>:

cd ~/bxagents-course/acme-support
bxAgents build
bxAgents invoke --message=capabilities
Build succeeded: <anything>/acme-support/.build/app
I can use these tools: <anything>delegate_to_researcher, delegate_to_writer<anything>

The scripted model has a rule for research and one for write: each delegates a task to that subagent. The subagent answers with the model of its profile, which the default answer names, so you can see who did the work:

bxAgents invoke --message=research
bxAgents invoke --message=write
The researcher answered: I can help with orders, returns and shipping. (Answered by fast-model.)
The writer answered: I can help with orders, returns and shipping. (Answered by planner-model.)

In the web app and in the terminal chat you can also talk to a subagent directly. The Talk to menu in the bar above the conversation lists the main agent and each subagent; pick one and the next message goes to it, a banner says who you are talking to, and every agent keeps its own memory. In the terminal the same thing is /agent.

Talk to with the researcher sub-agent picked and the banner that says so

Checkpoint

acme-support/subagents/ has researcher/ and writer/, and Agent.yml ends with subAgents: [ researcher, writer ]. kit/resume.sh 11-composing-subagents restores them; rebuild after.

Full reference: subagents/.

Next: Routines and Reports

Edit this page Download Markdown Last updated Nov 26, 2026, 8:45:51 AM Report an issue
Lesson 16 of 29 - Introduction to BxAgents