Replicate Tools
Generate images and video on Replicate models with the generate_media tool.
"""
Replicate Tools
=============================
Demonstrates replicate tools.
"""
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.replicate import ReplicateTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
"""Create an agent specialized for Replicate AI content generation"""
# Example 1: Enable specific Replicate functions
image_agent = Agent(
name="Image Generator Agent",
model=OpenAIChat(id="gpt-5.6-luna"),
tools=[ReplicateTools(model="luma/photon-flash", enable_generate_media=True)],
description="You are an AI agent that can generate images using the Replicate API.",
instructions=[
"When the user asks you to create an image, use the `generate_media` tool to create the image.",
"Return the URL as raw to the user.",
"Don't convert image URL to markdown or anything else.",
],
markdown=True,
)
# Example 2: Enable all Replicate functions
full_agent = Agent(
name="Full Replicate Agent",
model=OpenAIChat(id="gpt-5.6-luna"),
tools=[ReplicateTools(model="minimax/video-01", all=True)],
description="You are an AI agent that can generate various media using Replicate models.",
instructions=[
"Use the Replicate API to generate images or videos based on user requests.",
"Return the generated media URL to the user.",
],
markdown=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
image_agent.print_response("Generate an image of a horse in the dessert.")Only image_agent is called; full_agent is a separate video configuration. Both expose the single generate_media function. The wrapper sends a text prompt to the selected model and returns image or video URLs; it does not expose every input supported by a model's API.
Set both Replicate environment variables below to the same token before starting Python. Agno checks REPLICATE_API_KEY, while the Replicate SDK's shared client authenticates with REPLICATE_API_TOKEN.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openai replicateExport your API keys
export OPENAI_API_KEY="your_openai_api_key_here"
export REPLICATE_API_KEY="your_replicate_api_key_here"
export REPLICATE_API_TOKEN="$REPLICATE_API_KEY"Run the example
Save the code above as replicate_tools.py, then run:
python replicate_tools.pyFull source: cookbook/91_tools/replicate_tools.py