Adapters API Reference¶
Wrap a pydantic-ai Agent to conform to the agent callable contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
AnyAgent
|
A pydantic-ai |
required |
Example
Source code in src/pytest_agent_eval/adapters/pydantic_ai.py
__call__(history: History) -> AgentReply
async
¶
Run the agent and normalise output to (reply, tool_calls).
Source code in src/pytest_agent_eval/adapters/pydantic_ai.py
__init__(agent: AnyAgent) -> None
¶
Store the pydantic-ai agent to delegate calls to.
Source code in src/pytest_agent_eval/adapters/pydantic_ai.py
Wrap a LangChain Runnable to conform to the agent callable contract.
Expects the runnable to accept {"messages": [...]} and return an
AIMessage or object with a content attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runnable
|
LangChainRunnable
|
A LangChain Runnable (e.g. a compiled graph or chain). |
required |
Example
Source code in src/pytest_agent_eval/adapters/langchain.py
__call__(history: History) -> AgentReply
async
¶
Run the runnable and normalise output to (reply, tool_calls).
Source code in src/pytest_agent_eval/adapters/langchain.py
__init__(runnable: LangChainRunnable) -> None
¶
Store the LangChain runnable to delegate calls to.
Source code in src/pytest_agent_eval/adapters/langchain.py
Wrap an AsyncOpenAI client to conform to the agent callable contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AsyncOpenAI
|
An |
required |
model
|
str
|
Model name to use for completions (e.g. |
required |
system_prompt
|
str | None
|
Optional system prompt prepended to every call. |
None
|
Example
Source code in src/pytest_agent_eval/adapters/openai.py
__call__(history: History) -> AgentReply
async
¶
Run a chat completion and normalise to (reply, tool_calls).
Source code in src/pytest_agent_eval/adapters/openai.py
__init__(client: AsyncOpenAI, model: str, system_prompt: str | None = None) -> None
¶
Store the OpenAI client, model name, and optional system prompt.
Source code in src/pytest_agent_eval/adapters/openai.py
Wrap a smolagents agent to conform to the agent callable contract.
Duck-typed: works with any object exposing .run(task, reset=...) and
.memory.steps. Smolagents's sync run is offloaded with
asyncio.to_thread so the event loop stays responsive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
SmolagentsAgent
|
A smolagents agent (e.g. |
required |
include_internal_tools
|
bool
|
When |
False
|
Example
from smolagents import ToolCallingAgent, InferenceClientModel
from pytest_agent_eval.adapters.smolagents import SmolagentsAdapter
model = InferenceClientModel(model_id="meta-llama/Llama-3.3-70B-Instruct")
agent = ToolCallingAgent(tools=[...], model=model)
@pytest.fixture
def llm_eval_agent():
return SmolagentsAdapter(agent)
Source code in src/pytest_agent_eval/adapters/smolagents.py
__call__(history: History) -> AgentReply
async
¶
Run the agent against the latest user message and return (reply, tool_calls).
Source code in src/pytest_agent_eval/adapters/smolagents.py
__init__(agent: SmolagentsAgent, *, include_internal_tools: bool = False) -> None
¶
Store the smolagents agent and the internal-tool filter setting.
Source code in src/pytest_agent_eval/adapters/smolagents.py
Voice adapter: streams a WAV per turn into a fresh LiveKit AgentSession.
The user supplies a session_factory callable that returns a fresh
(AgentSession, Agent) pair on every invocation — one pair per turn.
The adapter attaches a :class:WavFileAudioInput from the turn's
audio: field, captures every executed tool call via
function_tools_executed, and accumulates the assistant transcript via
conversation_item_added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_factory
|
SessionFactory
|
Returns a fresh |
required |
sample_rate
|
int
|
WAV sample rate in Hz (must match the input file). Default 24 kHz, the OpenAI Realtime native rate. |
24000
|
frame_ms
|
int
|
Frame size in milliseconds. Default 20 ms. |
20
|
grace_period_s
|
float
|
Seconds to wait after the WAV drains before closing the session — gives the model time to fire trailing tool calls. |
8.0
|
timeout_s
|
float
|
Maximum seconds to wait for WAV exhaustion before forcibly closing the session. |
30.0
|
Example
from livekit.agents.voice import Agent, AgentSession
from livekit.plugins import openai
from pytest_agent_eval.adapters.livekit import LiveKitAdapter
def make_session():
session = AgentSession(llm=openai.realtime.RealtimeModel())
agent = Agent(instructions="...", tools=[...])
return session, agent
@pytest.fixture
def llm_eval_agent():
return LiveKitAdapter(make_session)
Source code in src/pytest_agent_eval/adapters/livekit.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
__call__(history: History) -> AgentReply
async
¶
Stream the WAV on the last user turn and return (reply, tool_calls).
Source code in src/pytest_agent_eval/adapters/livekit.py
__init__(session_factory: SessionFactory, *, sample_rate: int = 24000, frame_ms: int = 20, grace_period_s: float = 8.0, timeout_s: float = 30.0) -> None
¶
Store the session factory and streaming/event-capture knobs.