AutoGen¶
Test AutoGen multi-agent conversations with Tenro.
Experimental
This framework integration is experimental. Examples may break when the framework updates. See Compatibility for support definitions.
Tested with: autogen-agentchat==0.5.0, autogen-ext==0.5.0
What you'll use¶
| Decorator | Purpose |
|---|---|
@link_tool |
Your custom tools (search, database, APIs) |
@link_agent |
Entry point for tracing |
No @link_llm needed. Tenro intercepts LLM calls at the HTTP level automatically.
Customer support example¶
A customer support conversation with multiple agents.
"""Customer Support: Testing knowledge base retrieval with AutoGen."""
from __future__ import annotations
from examples.experimental.autogen.myapp.agents import CustomerSupportAgent, search_kb
from tenro import Provider, ToolCall
from tenro.simulate import agent, llm, tool
from tenro.testing import tenro
@tenro
def test_customer_support_answers_question() -> None:
"""Test customer support agent uses knowledge base and LLM.
Flow: LLM decides to call search_kb → tool returns result → LLM answers.
"""
# Simulate the tool that LLM will call
tool.simulate(search_kb, result="Full refunds within 30 days.")
# Simulate LLM: first requests tool, then gives final answer
llm.simulate(
Provider.OPENAI,
responses=[
[ToolCall("search_kb", query="refund")],
"You can get a full refund within 30 days of purchase. TERMINATE",
],
)
result = CustomerSupportAgent().run("How do I get a refund?")
assert result == "You can get a full refund within 30 days of purchase. TERMINATE"
agent.verify(CustomerSupportAgent)
llm.verify_many(Provider.OPENAI, count=2)
tool.verify_many(search_kb, count=1)
RAG pipeline example¶
A retrieval-augmented generation conversation with document search.
"""RAG Pipeline: Testing document retrieval with AutoGen."""
from __future__ import annotations
from examples.experimental.autogen.myapp.agents import RAGPipeline, fetch_docs
from tenro import Provider, ToolCall
from tenro.simulate import agent, llm, tool
from tenro.testing import tenro
@tenro
def test_rag_pipeline_synthesizes_answer() -> None:
"""Test RAG pipeline fetches documents and generates answer.
Flow: LLM decides to call fetch_docs → tool returns docs → LLM synthesizes.
"""
# Simulate the tool that LLM will call
tool.simulate(
fetch_docs,
result="Machine learning uses algorithms to learn.\nDeep learning is a subset of ML.",
)
# Simulate LLM: first requests tool, then synthesizes answer
llm.simulate(
Provider.OPENAI,
responses=[
[ToolCall("fetch_docs", topic="AI")],
"ML uses algorithms to learn from data. TERMINATE",
],
)
result = RAGPipeline().run("What is machine learning?", "AI")
assert result == "ML uses algorithms to learn from data. TERMINATE"
agent.verify(RAGPipeline)
llm.verify_many(Provider.OPENAI, count=2)
tool.verify_many(fetch_docs, count=1)
Multi-turn conversation example¶
A multi-agent conversation handling complex queries.
"""Multi-Turn Conversation: Testing sequential LLM calls with AutoGen."""
from __future__ import annotations
from examples.experimental.autogen.myapp.agents import ConversationAgent
from tenro import Provider
from tenro.simulate import agent, llm
from tenro.testing import tenro
@tenro
def test_multi_turn_conversation() -> None:
"""Test agent handles multi-turn conversation with context."""
llm.simulate(
Provider.OPENAI,
responses=[
"A list in Python is created with square brackets: my_list = [1, 2, 3] TERMINATE",
"To add items, use append(): my_list.append(4) TERMINATE",
],
)
responses = ConversationAgent().run(
["How do I create a list in Python?", "How do I add items to it?"]
)
assert responses == [
"A list in Python is created with square brackets: my_list = [1, 2, 3] TERMINATE",
"To add items, use append(): my_list.append(4) TERMINATE",
]
agent.verify(ConversationAgent)
llm.verify_many(Provider.OPENAI, count=2)
Key patterns¶
Agentic loop (LLM calls tool)¶
When the LLM decides to call a tool, then responds with the result:
from tenro import Provider, ToolCall
from tenro.simulate import llm, tool
# Assuming search_knowledge_base is defined with @link_tool("search_kb")
# 1. Set up tool result (use function reference)
tool.simulate(search_knowledge_base, result={"content": "Full refunds within 30 days."})
# 2. Set up LLM responses: first triggers tool, second is final response
llm.simulate(Provider.OPENAI, responses=[
ToolCall(search_knowledge_base, query="refund"),
"You can get a full refund within 30 days.",
])
Multi-agent conversations¶
from tenro import Provider, ToolCall
from tenro.simulate import llm
# Sequential responses for different agents with tool calls
llm.simulate(Provider.OPENAI, responses=[
ToolCall(lookup, query="info"),
"Agent 1: I found the information.",
"Agent 2: Based on the findings..."
])
Verifying¶
from tenro import Provider
from tenro.simulate import llm, tool
tool.verify_many(search_knowledge_base, count=1)
llm.verify_many(Provider.OPENAI, count=2) # Tool request + final answer
See also¶
- Testing patterns - Common testing recipes
- How Tenro works - HTTP interception explained
- API reference: construct - Full API documentation