Quickstart
Install and run your first agent
By the end of this page you will have a registered Replicate agent answering a real prompt through the framework's routing and resilience layer — verified by the built-in diagnostics command.
llama_chat agent invoked through AgentExecutor, plus a clean replicate-agent doctor report.Steps
-
Install the package
The core install is dependency-light; extras like OpenTelemetry are opt-in.
-
Set your token and run the doctor
doctorchecks the token, Python version, dependencies, and API connectivity before you write any code. -
Register and run an agent
One decorator registers the agent;
AgentExecutorstreams the result.
1. Install the package
pip install replicate-mcp-agents
If you want the full bundle — OpenTelemetry export, HTTP transports, and Latitude
integration — install pip install "replicate-mcp-agents[all]" instead. The optional
extras matter later, not for this page.
2. Set your token and run the doctor
export REPLICATE_API_TOKEN=r8_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
replicate-agent doctor
You now have a verified environment. Everything that follows assumes doctor is green —
if a later step fails, re-run it first; a missing token is the single most common failure mode
(it is Failure #1 in the runbook).
3. Register and run an agent
An agent is just a function that builds the payload for a Replicate model, plus
metadata the framework uses for routing and MCP tool definitions. Save this as first_agent.py:
import asyncio
from replicate_mcp import agent
from replicate_mcp.agents.execution import AgentExecutor
@agent(
model="meta/meta-llama-3-8b-instruct",
description="Fast chat model for general queries",
tags=["chat", "fast"],
estimated_cost=0.002,
)
def llama_chat(prompt: str) -> dict:
return {"prompt": prompt}
async def main():
executor = AgentExecutor(max_concurrency=5)
async for chunk in executor.run("llama_chat", {"prompt": "Say hello in 5 words"}):
print(chunk)
asyncio.run(main())
python first_agent.py
That call already went through the production layer: a per-model circuit breaker (trips after 5 consecutive failures), retry with decorrelated jitter (2 retries, 0.5 s base delay), and concurrency capping at 5 — all defaults you can tune later.
Verification
You're done when
replicate-agent doctorreports all checks passed.python first_agent.pyprints at least one chunk containing anoutputkey.- No traceback mentioning
AuthenticationErrororCircuitOpenError.
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
{"error": "REPLICATE_API_TOKEN is not set"} |
Token exported in a different shell, or not at all | export REPLICATE_API_TOKEN=... in the same shell, confirm with env | grep REPLICATE |
AgentNotFoundError: llama_chat |
The module defining the @agent was never imported before executor.run() |
Keep registration and execution in the same module, or import the agents module first |
429 Too Many Requests in logs |
Concurrency too high for your Replicate rate limit | Lower max_concurrency or attach a TokenBucket — see Resilience & caching |
Next steps
- Serve over MCP — make this agent callable from Claude Desktop and Cursor.
- Architecture — understand the layer your call just passed through.
- Agents & workflows — compose multi-step DAG pipelines.