Fal

FalTools enable an Agent to perform media generation tasks.

Prerequisites

The following example requires the fal_client library and an API key which can be obtained from Fal.

1uv pip install -U fal_client
1export FAL_KEY=***

Example

The following agent will use FAL to generate any video requested by the user.

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3from kern.tools.fal import FalTools
4
5fal_agent = Agent(
6 name="Fal Video Generator Agent",
7 model=OpenAIResponses(id="gpt-5.2"),
8 tools=[FalTools("fal-ai/hunyuan-video")],
9 description="You are an AI agent that can generate videos using the Fal API.",
10 instructions=[
11 "When the user asks you to create a video, use the `generate_media` tool to create the video.",
12 "Return the URL as raw to the user.",
13 "Don't convert video URL to markdown or anything else.",
14 ],
15 markdown=True,
16 debug_mode=True,
17 )
18
19fal_agent.print_response("Generate video of balloon in the ocean")

Toolkit Params

ParameterTypeDefaultDescription
api_keystrNoneAPI key for authentication purposes.
modelstrNoneThe model to use for the media generation.
enable_generate_mediaboolTrueEnable the generate_media functionality.
enable_image_to_imageboolTrueEnable the image_to_image functionality.
allboolFalseEnable all functionality.

Toolkit Functions

FunctionDescription
generate_mediaGenerate either images or videos depending on the user prompt.
image_to_imageTransform an input image based on a text prompt.

Developer Resources