Skip to main content
🔧 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

The Agent 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 AgentSDK for LLM communication
Why use it:
  • 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

  1. Building Custom Agents
    • Domain-specific assistants (customer service, data analysis, etc.)
    • Task automation agents
    • Multi-step workflow orchestrators
  2. Tool-Based Applications
    • Agents that need to interact with APIs, databases, or file systems
    • Applications requiring LLM decision-making with concrete actions
  3. 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 AgentSDK directly)
  • Applications without tools (use LLMClient directly)
  • 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:
  1. Planning State - LLM creates a multi-step plan
  2. Execution State - Execute plan steps sequentially
  3. Error Recovery State - Handle failures and retry
  4. Completion State - Generate final answer
State Transitions:

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:
Answer:
Plan:

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


Performance Considerations

Memory Management

  • Conversation history limited by max_history_length in AgentConfig
  • 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 (Qwen3-0.6B)
  • Use larger models for complex reasoning (Qwen3.5-35B)

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:
After:

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: April 2026 Specification Version: 1.0.0