Skip to main content
You can use an agent as a tool that another agent can call. This enables hierarchical agent architectures where specialized agents handle specific tasks, and a parent agent orchestrates them by calling these agent tools as needed.

Creating an Agent Tool

To create an agent tool, you need to:
  1. Create a specialized agent that will act as the tool
  2. Wrap it using tools.NewAgentTool with a tool definition

Parameters

  • name: The tool name exposed to the calling LLM.
  • description: A human-readable description of what the tool does.
  • agent: The agent instance that will be executed when the tool is called.
  • contextMode: Context mode for the agent tool.
    • SubAgentContextModeNone - The thread id is derived from the LLM-provided thread_id argument. When it is empty, each invocation starts a fresh conversation; the LLM can pass back a returned thread id to continue an earlier one.
    • SubAgentContextModeIsolated - A single sub-agent thread is stored and reused across calls, so invocations share and persist accumulated context within the session.
When the tool is called, the agent receives the tool’s arguments as input and returns its output as the tool’s result.

Using Agent Tools

Once created, you can use the agent tool in another agent’s tools list:

Complete Example

Here’s a complete example demonstrating an agent using another agent as a tool: