Adapters¶
The adapter protocol and framework-specific implementations.
AgentAdapter Protocol¶
AgentAdapter
¶
Bases: Protocol
Minimal interface any agent must implement for testing.
All agent-facing APIs are async-first. Sync agents are supported via the GenericAdapter which wraps sync callables in a thread executor.
Streaming is optional — adapters may also implement: async def run_stream(self, input: AgentInput) -> AsyncIterator[StreamEvent]
If run_stream is not present, CheckAgent falls back to run() and synthesizes streaming events from the completed trace.
run(input)
async
¶
Execute the agent and return a structured trace.
GenericAdapter¶
GenericAdapter(fn)
¶
Wraps any Python callable to conform to the AgentAdapter protocol.
The callable should accept a string (the query) and return a string or any value that becomes the final_output. Additional kwargs from AgentInput.context are forwarded if the callable accepts **kwargs.
wrap¶
wrap(fn=None)
¶
Wrap a callable as a GenericAdapter. Usable as decorator or function.
@wrap async def my_agent(query: str) -> str: ...
or¶
adapter = wrap(my_sync_function)
Framework Adapters¶
Framework adapters require their respective packages to be installed. Install with optional extras:
pip install checkagent[langchain] # LangChain
pip install checkagent[openai-agents] # OpenAI Agents SDK
pip install checkagent[pydantic-ai] # PydanticAI
pip install checkagent[crewai] # CrewAI
pip install checkagent[anthropic] # Anthropic
LangChainAdapter¶
LangChainAdapter(runnable, *, input_key='input', extra_inputs=None)
¶
Wraps a LangChain Runnable (chain, agent, or graph) as an AgentAdapter.
Parameters¶
runnable : Any
A LangChain Runnable — could be a chain, agent executor,
RunnableSequence, or LangGraph StateGraph / compiled graph.
input_key : str
Key used to pass the query into the runnable's invoke dict.
Defaults to "input".
extra_inputs : dict[str, Any] | None
Additional variables to include in every invocation dict. Useful for
multi-variable prompt templates (e.g. RAG chains needing context).
Per-run values from AgentInput.context override these defaults.