Tools
Understanding tools and how they enable human-in-the-loop AI workflows
Tools
Tools are a fundamental concept in the AG-UI protocol that enable AI agents to interact with external systems and incorporate human judgment into their workflows. By defining tools in the frontend and passing them to agents, developers can create sophisticated human-in-the-loop experiences that combine AI capabilities with human expertise.
What Are Tools?
In AG-UI, tools are functions that agents can call to:
- Request specific information
- Perform actions in external systems
- Ask for human input or confirmation
- Access specialized capabilities
Tools bridge the gap between AI reasoning and real-world actions, allowing agents to accomplish tasks that would be impossible through conversation alone.
Tool Structure
Tools follow a consistent structure that defines their name, purpose, and expected parameters:
The parameters
field uses JSON Schema to define
the structure of arguments that the tool accepts. This schema is used by both
the agent (to generate valid tool calls) and the frontend (to validate and parse
tool arguments).
Frontend-Defined Tools
A key aspect of AG-UI’s tool system is that tools are defined in the frontend and passed to the agent during execution:
This approach has several advantages:
- Frontend control: The frontend determines what capabilities are available to the agent
- Dynamic capabilities: Tools can be added or removed based on user permissions, context, or application state
- Separation of concerns: Agents focus on reasoning while frontends handle tool implementation
- Security: Sensitive operations are controlled by the application, not the agent
Tool Call Lifecycle
When an agent needs to use a tool, it follows a standardized sequence of events:
-
ToolCallStart: Indicates the beginning of a tool call with a unique ID and tool name
-
ToolCallArgs: Streams the tool arguments as they’re generated
-
ToolCallEnd: Marks the completion of the tool call
The frontend accumulates these deltas to construct the complete tool call arguments. Once the tool call is complete, the frontend can execute the tool and provide results back to the agent.
Tool Results
After a tool has been executed, the result is sent back to the agent as a “tool message”:
This message becomes part of the conversation history, allowing the agent to reference and incorporate the tool’s result in subsequent responses.
Human-in-the-Loop Workflows
The AG-UI tool system is especially powerful for implementing human-in-the-loop workflows. By defining tools that request human input or confirmation, developers can create AI experiences that seamlessly blend autonomous operation with human judgment.
For example:
- Agent needs to make an important decision
- Agent calls the
confirmAction
tool with details about the decision - Frontend displays a confirmation dialog to the user
- User provides their input
- Frontend sends the user’s decision back to the agent
- Agent continues processing with awareness of the user’s choice
This pattern enables use cases like:
- Approval workflows: AI suggests actions that require human approval
- Data verification: Humans verify or correct AI-generated data
- Collaborative decision-making: AI and humans jointly solve complex problems
- Supervised learning: Human feedback improves future AI decisions
CopilotKit Integration
CopilotKit provides a simplified way to work with
AG-UI tools in React applications through its
useCopilotAction
hook:
This approach makes it easy to define tools that integrate with your React components and handle the tool execution logic in a clean, declarative way.
Tool Examples
Here are some common types of tools used in AG-UI applications:
User Confirmation
Data Retrieval
User Interface Control
Content Generation
Best Practices
When designing tools for AG-UI:
- Clear naming: Use descriptive, action-oriented names
- Detailed descriptions: Include thorough descriptions to help the agent understand when and how to use the tool
- Structured parameters: Define precise parameter schemas with descriptive field names and constraints
- Required fields: Only mark parameters as required if they’re truly necessary
- Error handling: Implement robust error handling in tool execution code
- User experience: Design tool UIs that provide appropriate context for human decision-making
Conclusion
Tools in AG-UI bridge the gap between AI reasoning and real-world actions, enabling sophisticated workflows that combine the strengths of AI and human intelligence. By defining tools in the frontend and passing them to agents, developers can create interactive experiences where AI and humans collaborate efficiently.
The tool system is particularly powerful for implementing human-in-the-loop workflows, where AI can suggest actions but defer critical decisions to humans. This balances automation with human judgment, creating AI experiences that are both powerful and trustworthy.