🔧 You are viewing: API Specification - Complete technical reference for the Agent classSee also: Conceptual Guide · Quickstart Tutorial
- Component: Agent Base Class
- Module:
gaia.agents.base.agent - Import:
from gaia.agents.base.agent import Agent - Source:
src/gaia/agents/base/agent.py
Overview
TheAgent class is the foundational base class for all GAIA agents. It provides a complete reasoning loop that connects LLMs with executable tools, manages conversation state, handles error recovery, and orchestrates multi-step planning and execution.
What it does:
- Manages LLM conversation and reasoning loop
- Registers and executes tools
- Parses and validates JSON responses from LLMs
- Handles multi-step plan execution
- Provides error recovery and retry logic
- Manages conversation history and state
- Supports streaming and non-streaming responses
- Integrates with ChatSDK for LLM communication
- Foundation for building any AI agent
- Handles complex reasoning patterns (planning, execution, error recovery)
- Provides tool registration and execution framework
- Supports multiple LLM backends (local, Claude, ChatGPT)
- Built-in debugging and tracing capabilities
Purpose and Use Cases
When to Use
-
Building Custom Agents
- Domain-specific assistants (customer service, data analysis, etc.)
- Task automation agents
- Multi-step workflow orchestrators
-
Tool-Based Applications
- Agents that need to interact with APIs, databases, or file systems
- Applications requiring LLM decision-making with concrete actions
-
Research and Experimentation
- Testing different prompting strategies
- Evaluating LLM performance on multi-step tasks
- Building agent benchmarks
When NOT to Use
- Simple single-turn LLM queries (use
ChatSDKdirectly) - Applications without tools (use
LLMClientdirectly) - Stateless request/response patterns (use
quick_chat())
API Specification
Class Definition
Constructor
Abstract Methods (Must Implement)
Core Methods
Helper Methods
State Management Properties
Implementation Details
Reasoning Loop
The agent implements a sophisticated reasoning loop:- Planning State - LLM creates a multi-step plan
- Execution State - Execute plan steps sequentially
- Error Recovery State - Handle failures and retry
- Completion State - Generate final answer
Tool Execution
Tools are registered using the@tool decorator in _register_tools():
JSON Response Format
The LLM must respond with JSON in one of these formats: Thought + Tool:Error Handling
The agent automatically handles:- Invalid JSON responses (with repair attempts)
- Tool execution failures (with retry logic)
- Missing required fields (prompts LLM for correction)
- Max steps exceeded (graceful termination)
Code Examples
Example 1: Minimal Agent
Example 2: Database Agent with Multiple Tools
Example 3: Silent Mode for API
Testing Requirements
Unit Tests
File:tests/agents/base/test_agent.py
Integration Tests
Dependencies
Required Packages
External Dependencies
Acceptance Criteria
- Agent class implemented with all abstract methods
- State management working (all 5 states)
- Tool registration and execution working
- JSON validation and repair working
- Conversation history tracking working
- Error recovery and retry logic working
- Max steps enforcement working
- Silent mode working (no console output)
- Streaming mode working
- All configuration parameters working
- Unit tests pass (100% coverage of public methods)
- Integration tests pass
- Documentation complete in SDK.md
- Example agents work
Performance Considerations
Memory Management
- Conversation history limited by
max_history_lengthin ChatConfig - Error history stored but not automatically pruned
- Consider clearing history for long-running agents
Token Usage
- Default context window: 4096 tokens
- Tool descriptions consume ~100-500 tokens
- Monitor token usage with
show_stats=True - Use smaller models for simple tasks (Qwen2.5-0.5B)
- Use larger models for complex reasoning (Qwen3-Coder-30B)
Latency
- Streaming mode reduces perceived latency
- Tool execution time depends on tool implementation
- Local LLM faster than cloud APIs but lower quality
- Plan-execute cycles add latency vs direct execution
Migration Notes
From Direct LLM Calls
Before:Adding Tools to Existing Agent
Future Enhancements
- Parallel tool execution for independent operations
- Tool dependency graph for optimal ordering
- Automatic tool discovery from modules
- Tool result caching
- Multi-agent collaboration patterns
- Enhanced planning with A* or beam search
- Learning from error history
- Dynamic system prompt adjustment
Status: ✅ Implemented and tested Last Updated: December 10, 2025 Specification Version: 1.0.0