Agent Tools

Purpose

Agent Tools address the need for agent composition and delegation within the broader Tooling System. While the parent topic defines modular tools like function wrappers, artifact loaders, and search tools that an agent can invoke, Agent Tools introduce a unique capability: wrapping entire sub-agents as callable tools. This allows an agent to delegate part of its processing to another specialized agent, enabling hierarchical and compositional AI workflows.

This subtopic solves problems where:

By encapsulating sub-agents as tools that can be called synchronously within agent workflows, Agent Tools enable flexible, composable agent architectures that improve modularity and reuse.

Functionality

The core functionality of Agent Tools revolves around a tool implementation that wraps a sub-agent instance and exposes it as a callable function tool. Key aspects include:

Agent Wrapping and Invocation

Integration with LLM Requests

Input and Output Schema Validation

Session and State Management

Skip Summarization Control


Code Illustration: Running a Sub-Agent as a Tool

func (t *agentTool) Run(toolCtx tool.Context, args any) (map[string]any, error) {
	// Validate input arguments against sub-agent input schema
	if err := utils.ValidateMapOnSchema(argsMap, agentInputSchema, true); err != nil {
		return nil, err
	}

	// Create a new session for the sub-agent with inherited state
	subSession, err := sessionService.Create(toolCtx, &session.CreateRequest{ ... })

	// Instantiate runner and execute sub-agent
	eventCh := runner.Run(toolCtx, subSession.UserID, subSession.ID, content, ...)

	// Collect final sub-agent response event
	// Parse and validate output against output schema
	return parsedOutput, nil
}

Integration

Agent Tools integrate tightly within the Modular Tool Framework and complement other subtopics:

By wrapping sub-agents as tools, Agent Tools enable hierarchical agent delegation and modular AI workflows that scale beyond single-agent or flat tool invocation patterns.


sequenceDiagram
participant ParentAgent as Parent Agent
participant AgentTool as Agent Tool
participant Runner as Agent Runner
participant SubAgent as Sub Agent
participant SessionSvc as Session Service
ParentAgent->>AgentTool: Call Run(args)
AgentTool->>SessionSvc: Create sub-agent session (with inherited state)
SessionSvc-->>AgentTool: New sub-agent session
AgentTool->>Runner: Run sub-agent with session and input
Runner->>SubAgent: Execute sub-agent
SubAgent-->>Runner: Emit events & final response
Runner-->>AgentTool: Stream events channel
AgentTool->>AgentTool: Collect last LLM response
AgentTool->>AgentTool: Validate and parse output schema
AgentTool-->>ParentAgent: Return output map