Add agent interface and model implementations

Implements Phase 1: Agent abstraction layer with multiple model support

Features:
- Abstract AgentInterface base class with standard contract
- LoremTesterAgent: Full-featured mock agent with realistic behavior
  - Configurable reasoning effort levels (none to xhigh)
  - Random tool/function call generation
  - Error triggers for testing (rate_limit, context_overflow)
  - Temperature-based response variation
- TatlockAgent: Placeholder for future PydanticAI integration
- ModelRegistry: Centralized model management and discovery

Testing:
- 9 unit tests for lorem-tester agent behavior
- 9 unit tests for registry operations
- Coverage: Agent abstraction fully tested

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-06 19:36:53 +01:00
co-authored by Claude
parent 62edb111bd
commit 4e6ca4466b
8 changed files with 975 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
"""Tests for agent implementations."""
+196
View File
@@ -0,0 +1,196 @@
"""
Tests for Lorem Tester agent.
"""
import pytest
from src.agents.lorem_tester import LoremTesterAgent
from src.core.exceptions import (
RateLimitError,
ContextLengthError,
APIError,
)
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_basic_response():
"""Test basic lorem tester response without reasoning or tools."""
agent = LoremTesterAgent()
messages = [{"role": "user", "content": "Hello"}]
items = []
async for item in agent.generate_response(messages):
items.append(item)
# Should have at least one message item
assert len(items) >= 1
# Last item should be message
last_item = items[-1]
assert last_item.type == "message"
assert last_item.data["role"] == "assistant"
assert last_item.data["content"][0]["type"] == "output_text"
assert len(last_item.data["content"][0]["text"]) > 0
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_with_reasoning():
"""Test lorem tester with reasoning enabled."""
agent = LoremTesterAgent()
messages = [{"role": "user", "content": "Explain something"}]
reasoning = {"summary": "auto", "effort": "medium"}
items = []
async for item in agent.generate_response(messages, reasoning=reasoning):
items.append(item)
# Should have reasoning item and message item
assert len(items) >= 2
# First item should be reasoning
reasoning_item = items[0]
assert reasoning_item.type == "reasoning"
assert "summary" in reasoning_item.data
assert isinstance(reasoning_item.data["summary"], list)
assert len(reasoning_item.data["summary"]) > 0
# Last item should be message
message_item = items[-1]
assert message_item.type == "message"
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_reasoning_effort_levels():
"""Test different reasoning effort levels."""
agent = LoremTesterAgent()
messages = [{"role": "user", "content": "Test"}]
# Test different effort levels
efforts = ["minimal", "low", "medium", "high", "xhigh"]
for effort in efforts:
reasoning = {"summary": "auto", "effort": effort}
items = []
async for item in agent.generate_response(messages, reasoning=reasoning):
if item.type == "reasoning":
items.append(item)
# Should have reasoning item
assert len(items) >= 1
reasoning_item = items[0]
assert reasoning_item.type == "reasoning"
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_with_tools():
"""Test lorem tester with tools (may or may not call them)."""
agent = LoremTesterAgent()
messages = [{"role": "user", "content": "Use a tool"}]
tools = [
{"name": "search_knowledge", "description": "Search knowledge base"},
{"name": "calculate", "description": "Do math"},
]
items = []
async for item in agent.generate_response(messages, tools=tools):
items.append(item)
# Should have at least message item
# May have function_call items (randomized)
assert len(items) >= 1
# Check item types
for item in items:
assert item.type in ["reasoning", "function_call", "message"]
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_capabilities():
"""Test lorem tester capabilities."""
agent = LoremTesterAgent()
assert await agent.supports_tools() is True
assert await agent.supports_reasoning() is True
capabilities = await agent.get_capabilities()
assert capabilities["streaming"] is True
assert capabilities["reasoning"] is True
assert capabilities["tools"] is True
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_rate_limit_trigger():
"""Test rate limit error trigger."""
agent = LoremTesterAgent()
messages = [{"role": "user", "content": "trigger_rate_limit"}]
with pytest.raises(RateLimitError) as exc_info:
async for item in agent.generate_response(messages):
pass
assert "rate limit" in str(exc_info.value).lower()
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_context_overflow_trigger():
"""Test context length error trigger."""
agent = LoremTesterAgent()
messages = [{"role": "user", "content": "trigger_context_overflow"}]
with pytest.raises(ContextLengthError) as exc_info:
async for item in agent.generate_response(messages):
pass
assert "context" in str(exc_info.value).lower()
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_invalid_tool_trigger():
"""Test invalid tool error trigger."""
agent = LoremTesterAgent()
messages = [{"role": "user", "content": "trigger_invalid_tool"}]
with pytest.raises(APIError) as exc_info:
async for item in agent.generate_response(messages):
pass
assert "tool" in str(exc_info.value).lower()
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_temperature_variation():
"""Test temperature affects response variety."""
agent = LoremTesterAgent()
messages = [{"role": "user", "content": "Test"}]
# Low temperature
items_low = []
async for item in agent.generate_response(messages, temperature=0.1):
if item.type == "message":
items_low.append(item)
# High temperature
items_high = []
async for item in agent.generate_response(messages, temperature=1.5):
if item.type == "message":
items_high.append(item)
# Both should have responses
assert len(items_low) >= 1
assert len(items_high) >= 1
+124
View File
@@ -0,0 +1,124 @@
"""
Tests for model registry.
"""
import pytest
from src.agents.registry import ModelRegistry
from src.agents.lorem_tester import LoremTesterAgent
from src.agents.tatlock import TatlockAgent
from src.core.exceptions import ModelNotFoundError
@pytest.mark.unit
@pytest.mark.asyncio
async def test_list_models():
"""Test listing all available models."""
models = await ModelRegistry.list_models()
# Should have both models
assert len(models) == 2
# Check model IDs
model_ids = [m["id"] for m in models]
assert "lorem-tester" in model_ids
assert "tatlock" in model_ids
# Check structure
for model in models:
assert "id" in model
assert "object" in model
assert model["object"] == "model"
assert "created" in model
assert "owned_by" in model
assert "capabilities" in model
assert "description" in model
@pytest.mark.unit
@pytest.mark.asyncio
async def test_lorem_tester_capabilities():
"""Test lorem-tester model capabilities."""
models = await ModelRegistry.list_models()
lorem_model = next(m for m in models if m["id"] == "lorem-tester")
capabilities = lorem_model["capabilities"]
# Lorem Tester should have all features
assert capabilities["streaming"] is True
assert capabilities["reasoning"] is True
assert capabilities["tools"] is True
assert capabilities["vision"] is False
assert capabilities["audio"] is False
@pytest.mark.unit
@pytest.mark.asyncio
async def test_tatlock_capabilities():
"""Test tatlock model capabilities."""
models = await ModelRegistry.list_models()
tatlock_model = next(m for m in models if m["id"] == "tatlock")
capabilities = tatlock_model["capabilities"]
# Tatlock is placeholder - minimal capabilities
assert capabilities["streaming"] is True
assert capabilities["reasoning"] is False # Not yet
assert capabilities["tools"] is False # Not yet
assert capabilities["vision"] is False
assert capabilities["audio"] is False
@pytest.mark.unit
def test_get_agent_lorem_tester():
"""Test getting lorem-tester agent instance."""
agent = ModelRegistry.get_agent("lorem-tester")
assert isinstance(agent, LoremTesterAgent)
@pytest.mark.unit
def test_get_agent_tatlock():
"""Test getting tatlock agent instance."""
agent = ModelRegistry.get_agent("tatlock")
assert isinstance(agent, TatlockAgent)
@pytest.mark.unit
def test_get_agent_not_found():
"""Test getting non-existent agent raises error."""
with pytest.raises(ModelNotFoundError) as exc_info:
ModelRegistry.get_agent("nonexistent-model")
assert "nonexistent-model" in str(exc_info.value)
@pytest.mark.unit
def test_model_exists():
"""Test checking if model exists."""
assert ModelRegistry.model_exists("lorem-tester") is True
assert ModelRegistry.model_exists("tatlock") is True
assert ModelRegistry.model_exists("nonexistent") is False
@pytest.mark.unit
@pytest.mark.asyncio
async def test_get_model_info():
"""Test getting detailed model information."""
info = await ModelRegistry.get_model_info("lorem-tester")
assert info["id"] == "lorem-tester"
assert info["object"] == "model"
assert "created" in info
assert "owned_by" in info
assert "capabilities" in info
assert "description" in info
@pytest.mark.unit
@pytest.mark.asyncio
async def test_get_model_info_not_found():
"""Test getting info for non-existent model raises error."""
with pytest.raises(ModelNotFoundError):
await ModelRegistry.get_model_info("nonexistent-model")