Running Agents with Maev
Maev is designed to stay out of your way. In any Python agent, the integration is the same two lines:
import maev
maev.run(agent, gateway=True)Then your agent runs exactly as it already does. Maev patches LLM clients in-process, captures every call, and activates Autopilot automatically. No callbacks, no middleware, no config files.
The only rules
- Pass your agent (or a function that runs it) to
maev.run(), specifyinggateway=True. - Set
MAEV_API_KEYas an environment variable. - That's it.
OpenAI
import os
import maev
from openai import OpenAI
client = OpenAI()
def support_agent():
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful support agent."},
{"role": "user", "content": "How do I reset my password?"},
],
)
return response.choices[0].message.content
result = maev.run(support_agent, gateway=True)Azure OpenAI
import os
import maev
from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
api_key=os.environ["AZURE_OPENAI_API_KEY"],
api_version="2024-12-01-preview",
)
def support_agent():
response = client.chat.completions.create(
model="gpt-4o", # your Azure deployment name
messages=[
{"role": "system", "content": "You are a helpful support agent."},
{"role": "user", "content": "How do I reset my password?"},
],
)
return response.choices[0].message.content
result = maev.run(support_agent, gateway=True)Anthropic
import os
import maev
from anthropic import Anthropic
client = Anthropic()
def research_agent():
response = client.messages.create(
model="claude-3-5-sonnet-latest",
max_tokens=512,
system="You summarize product research clearly and carefully.",
messages=[
{"role": "user", "content": "Summarize the top three customer complaints."}
],
)
return response.content[0].text
result = maev.run(research_agent, gateway=True)LangChain
No callback handlers, wrappers, or custom middleware are required. Pass your chain or agent function to maev.run().
import os
import maev
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_openai import ChatOpenAI
model = ChatOpenAI(model="gpt-4o")
def langchain_agent():
result = model.invoke(
[
SystemMessage(content="You are a precise and helpful support agent."),
HumanMessage(content="Draft a password reset reply."),
]
)
return result.content
result = maev.run(langchain_agent, gateway=True)LangChain streaming and async flows still work. Maev patches the framework layer and the underlying provider clients automatically.
CrewAI
Pass the crew directly to maev.run(). Maev detects .kickoff() automatically.
import os
import maev
from crewai import Agent, Crew, Task
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o")
researcher = Agent(
role="Researcher",
goal="Find the most important competitor updates from this week.",
backstory="You are a sharp market analyst who writes concise summaries.",
llm=llm,
)
task = Task(
description="Summarize the top competitor announcements from this week.",
expected_output="A short bulleted brief with the biggest updates.",
agent=researcher,
)
crew = Crew(agents=[researcher], tasks=[task])
result = maev.run(crew, gateway=True)LangGraph
Pass the compiled graph to maev.run(). Maev detects .invoke() automatically.
import maev
# your compiled LangGraph graph
app = workflow.compile()
result = maev.run(app, {"messages": [HumanMessage(content="What is the weather?")]}, gateway=True)Async agents
Async agents work without any extra setup:
import asyncio
import maev
from openai import AsyncOpenAI
client = AsyncOpenAI()
async def async_agent():
response = await client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Summarize quarterly earnings."}],
)
return response.choices[0].message.content
result = asyncio.run(maev.run(async_agent, gateway=True))Budget and safety limits
Set limits to protect against runaway agents:
result = maev.run(
agent,
gateway=True,
cost_budget=0.50, # stop if this run costs more than $0.50
max_calls=30, # stop after 30 LLM calls
max_duration_s=120.0, # stop after 2 minutes
fallback_models=["gpt-4o-mini"], # switch if primary model fails
)If any limit is exceeded, Maev stops the run and raises maev.CircuitBrokenError.
Naming your agent
If you run multiple agents, give each a distinct name so they appear separately in the dashboard:
result = maev.run(agent, agent_name="Invoice Processing Agent (prod)", gateway=True)If not provided, Maev auto-detects the name from the function or class name.
Updating the SDK
The SDK checks PyPI in the background and prints a terminal notice when a newer maev-sdk release is available. Your agent keeps running normally while you decide when to upgrade.