Skip to main content

Testing

17.1 Testing Agents

import pytest
from my_package.agent import MyAgent

def test_agent_creation():
    """Test agent can be created."""
    agent = MyAgent()
    assert agent is not None

def test_tool_execution():
    """Test a tool's implementation directly.

    The base Agent does not expose a public `execute_tool()` — tools are
    invoked by the planner after parsing LLM output. For unit tests, either
    call the tool function directly (it's just a decorated Python function)
    or look it up in the global registry.
    """
    from gaia.agents.base.tools import _TOOL_REGISTRY
    agent = MyAgent()
    entry = _TOOL_REGISTRY["my_tool"]
    result = entry["function"](param="value")
    assert result["status"] == "success"

def test_query_processing():
    """Test full query processing."""
    agent = MyAgent()
    result = agent.process_query("Do something")
    assert "result" in result

17.2 Silent Mode for Testing

from my_package.agent import MyAgent

def test_silent_mode():
    """Test with no console output."""
    agent = MyAgent(silent_mode=True)
    result = agent.process_query("Test query")
    # No console output, just results
    assert result is not None

17.3 Mocking LLM Responses

from unittest.mock import patch
from gaia.chat.sdk import AgentResponse

def test_with_mocked_llm():
    """Test agent with a mocked AgentSDK.

    The AgentSDK exposes `send()` (and `send_stream()`), not `.complete()`.
    Return an AgentResponse whose `text` contains the JSON the planner
    expects — the agent will parse it and invoke the referenced tool.
    """
    with patch("gaia.chat.sdk.AgentSDK") as mock_chat:
        mock_chat.return_value.send.return_value = AgentResponse(
            text='{"tool": "my_tool", "tool_args": {"param": "value"}}',
        )

        agent = MyAgent()
        agent.process_query("Test")

        assert mock_chat.return_value.send.called
Consider using the built-in MockLLMProvider / MockVLMClient helpers in gaia.testing (src/gaia/testing/mocks.py) for richer fixtures. The require_lemonade pytest fixture in tests/conftest.py skips integration tests automatically if no Lemonade server is running.