Replicate

ReplicateTools enables an Agent to generate media using the Replicate platform.

Prerequisites

1export REPLICATE_API_TOKEN=***

The following example requires the replicate library. To install the Replicate client, run the following command:

1uv pip install -U replicate

Example

The following agent will use Replicate to generate images or videos requested by the user.

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3from kern.tools.replicate import ReplicateTools
4
5"""Create an agent specialized for Replicate AI content generation"""
6
7image_agent = Agent(
8 name="Image Generator Agent",
9 model=OpenAIResponses(id="gpt-5.2"),
10 tools=[ReplicateTools(model="luma/photon-flash")],
11 description="You are an AI agent that can generate images using the Replicate API.",
12 instructions=[
13 "When the user asks you to create an image, use the `generate_media` tool to create the image.",
14 "Return the URL as raw to the user.",
15 "Don't convert image URL to markdown or anything else.",
16 ],
17 markdown=True,
18 debug_mode=True,
19 )
20
21image_agent.print_response("Generate an image of a horse in the dessert.")

Toolkit Params

ParameterTypeDefaultDescription
api_keystrNoneIf you want to manually supply the Replicate API key.
modelstrminimax/video-01The replicate model to use. Find out more on the Replicate platform.
enable_generate_mediaboolTrueEnable the generate_media functionality.
allboolFalseEnable all functionality.

Toolkit Functions

FunctionDescription
generate_mediaGenerate either an image or a video from a prompt. The output depends on the model.

Developer Resources