Skip to content
AgentField

Testing

Patterns for unit testing, integration testing, and mocking AgentField agents.

Testing pyramid — unit, integration, end-to-end

Write deterministic, fast tests for your agents -- from unit tests to full integration suites.

AgentField agents are regular Python functions decorated with @app.reasoner() and @app.skill(). Test them with standard tools like pytest, mock LLM calls for deterministic assertions, and run integration tests against a local backend.

Key Principle

Replace app.ai and app.call with AsyncMock instances so no real LLM calls happen. Tests run in milliseconds with deterministic results.

from unittest.mock import AsyncMock
from src.agents.classifier import app, classify, Classification

app.ai = AsyncMock(return_value=Classification(category="technical", confidence=0.95))
result = await classify(text="How to configure Kubernetes pods")
assert result.category == "technical"

What just happened

The example replaced live infrastructure with mocks and still exercised the agent’s logic directly. That is the key testing pattern to make explicit: most agent tests should validate control flow, schemas, and fallback behavior without invoking real models or remote agents.

{
  "llm_call": "mocked",
  "cross_agent_call": "mockable",
  "test_speed": "milliseconds",
  "assertion_target": "reasoner_behavior"
}