Examples¶
Real-world examples for testing AI agents with Tenro.
All examples are tested in CI and can be copied directly into your project.
-
Framework examples
Test agents built with LangChain, CrewAI, LangGraph, Pydantic AI, AutoGen, and LlamaIndex.
-
Pattern recipes
Common testing patterns: simulating responses, verifying calls, error handling, and more.
Quick start example¶
Here's a complete example you can copy and run:
from tenro import link_agent, link_tool, Construct, Provider
from tenro.simulate import llm, tool
from tenro.testing import tenro
# Your application code (framework user - no @link_llm needed)
@link_tool("search")
def search(query: str) -> list[str]:
return [] # In production: call your search API
@link_agent("Researcher")
def researcher(topic: str) -> str:
docs = search(topic)
# Framework handles LLM - Tenro intercepts at HTTP level
chain = prompt | ChatOpenAI()
return chain.invoke(docs)
# Your test
@tenro
def test_researcher() -> None:
# Simulate dependencies (use function reference)
tool.simulate(search, result=["doc1", "doc2"])
llm.simulate(Provider.OPENAI, response="Summary of findings")
# Run the agent
result = researcher("AI trends")
# Verify behaviour
tool.verify_many(search, count=1)
llm.verify(Provider.OPENAI)
Framework examples¶
Each framework has its own dedicated page with tailored examples:
| Framework | Description |
|---|---|
| LangChain | Chains, tools, and RAG pipelines |
| CrewAI | Multi-agent crews |
| LangGraph | Stateful graph workflows |
| Pydantic AI | Type-safe agents |
| AutoGen | Microsoft's agent framework |
| LlamaIndex | Query engines and RAG |
| Custom agents | Raw OpenAI/Anthropic SDK |
Pattern recipes¶
Common testing patterns:
| Pattern | Description |
|---|---|
| Simulating responses | Control tool and LLM outputs |
| Verifying calls | Check call counts and arguments |
| Verifying sequence | Ensure correct operation order |
| Simulating errors | Test error handling |
| Dynamic behaviour | Compute results from inputs |
Running examples locally¶
# Clone the repository
git clone https://github.com/tenro-ai/tenro-python
cd tenro-python
# Install with example dependencies
uv sync --group examples
# Run all examples
uv run pytest examples/
# Run by category
uv run pytest examples/patterns/
uv run pytest examples/langchain/
uv run pytest examples/crewai/
See also¶
- Quick start: Your first test with Tenro
- How Tenro works: HTTP interception explained
- Testing patterns: Detailed pattern explanations