FrameworksAutoGen
AutoGen
Orchestrate Microsoft AutoGen multi-agent workflows with nRouter. Connect agents via OpenAI-compatible endpoints with intelligent routing and budget controls.
Last updated
Microsoft's AutoGen framework supports any OpenAI-compatible endpoint via its OpenAIChatCompletionClient. Point it at nRouter — guardrails, caching, and rate-limits auto-apply to every agent turn.
Installation
pip install autogen-agentchat autogen-ext[openai]Setup
import os
from autogen_ext.models.openai import OpenAIChatCompletionClient
model_client = OpenAIChatCompletionClient(
model="claude-sonnet-4-5-20250929",
api_key=os.environ["NROUTER_API_KEY"],
base_url="https://api.nrouter.ai/v1",
)Single Agent
import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
from autogen_core import CancellationToken
async def main():
agent = AssistantAgent(
name="assistant",
model_client=model_client,
system_message="You are a concise, technical assistant.",
)
response = await agent.on_messages(
[TextMessage(content="What is an LLM gateway?", source="user")],
cancellation_token=CancellationToken(),
)
print(response.chat_message.content)
asyncio.run(main())Multi-Agent Conversation
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.conditions import MaxMessageTermination
researcher = AssistantAgent(
name="researcher",
model_client=model_client,
system_message="You research topics and surface the key facts.",
)
critic = AssistantAgent(
name="critic",
model_client=model_client,
system_message="You critique research for accuracy and depth.",
)
team = RoundRobinGroupChat(
[researcher, critic],
termination_condition=MaxMessageTermination(max_messages=6),
)
result = await team.run(task="Evaluate the state of LLM observability in 2026.")
for msg in result.messages:
print(f"{msg.source}: {msg.content}")Per-Request Overrides
Pass nrouter_* fields through the client's extra_create_args:
model_client = OpenAIChatCompletionClient(
model="gpt-5.5",
api_key=os.environ["NROUTER_API_KEY"],
base_url="https://api.nrouter.ai/v1",
extra_create_args={
"nrouter_prompt_template_id": "your-summarizer-id",
"nrouter_prompt_variables": {"language": "Spanish"},
"nrouter_cache": False,
},
)Guardrails are not passed here. You assign them in the dashboard at key, team, or organization scope — the narrowest scope that mentions a guardrail wins — and they run automatically on every agent turn that scope covers.
Tools
AutoGen tool wiring — guardrails check the user input before tools run:
async def get_weather(city: str) -> str:
return f"72°F and sunny in {city}"
agent = AssistantAgent(
name="weather_assistant",
model_client=model_client,
tools=[get_weather],
)Next Steps
- CrewAI — Alternative multi-agent framework
- Python SDK — Without AutoGen
Was this page helpful?