Subagent
A Tool that delegates to another agent as a subagent/handoff.
When the LLM invokes this tool, it runs the specified agent as a subprocess, sharing the parent process's blackboard context. This enables composition of agents and "handoff" patterns where one agent delegates specialized tasks to another.
Usage
Create a Subagent using one of the factory methods:
// From an @Agent annotated class
Subagent.ofClass(MyAgent::class.java)
Subagent.ofClass<MyAgent>() // Kotlin reified version
// From an agent name (resolved at runtime)
Subagent.byName("MyAgent")
// From an Agent instance
Subagent.ofInstance(resolvedAgent)
// From an instance of an @Agent annotated class
Subagent.ofAnnotatedInstance(myAgentBean)Use with withTool() on a PromptRunner:
context.ai()
.withTool(Subagent.ofClass(MyAgent::class.java))
.creating(Result::class.java)
.fromPrompt("...")For asset tracking, wrap with AssetAddingTool:
context.ai()
.withTool(assetTracker.addReturnedAssets(Subagent.ofClass(MyAgent::class.java)))
.creating(Result::class.java)
.fromPrompt("...")Input Type Resolution
The input type for the subagent is automatically determined by introspecting the agent's actions. It finds the first non-injected input binding from the agent's first action.
Types
Properties
Functions
Execute the tool with JSON input.
Extension function to convert an Embabel Tool to a Spring AI ToolCallback.
Wrap this tool to conditionally await before execution.
Wrap this tool to always require confirmation before execution.
Create a new tool with a different description. Useful for providing context-specific descriptions while keeping the same functionality.
Extension function to wrap a Tool with event publication.