Documentation Index
Fetch the complete documentation index at: https://docs.agno.com/llms.txt
Use this file to discover all available pages before exploring further.
Code
cookbook/90_models/cloudflare/structured_output.py
from typing import List
from agno.agent import Agent, RunOutput # noqa
from agno.models.cloudflare import Cloudflare
from pydantic import BaseModel, Field
from rich.pretty import pprint # noqa
class MovieScript(BaseModel):
setting: str = Field(
..., description="Provide a nice setting for a blockbuster movie."
)
ending: str = Field(
...,
description="Ending of the movie. If not available, provide a happy ending.",
)
genre: str = Field(
...,
description="Genre of the movie. If not available, select action, thriller or romantic comedy.",
)
name: str = Field(..., description="Give a name to this movie")
characters: List[str] = Field(..., description="Name of characters for this movie.")
storyline: str = Field(
..., description="3 sentence storyline for the movie. Make it exciting!"
)
# Agent that uses JSON mode
json_mode_agent = Agent(
model=Cloudflare(id="@cf/google/gemma-4-26b-a4b-it"),
description="You write movie scripts.",
output_schema=MovieScript,
use_json_mode=True,
)
# Agent that uses structured outputs
structured_output_agent = Agent(
model=Cloudflare(id="@cf/google/gemma-4-26b-a4b-it"),
description="You write movie scripts.",
output_schema=MovieScript,
)
json_mode_agent.print_response("New York")
structured_output_agent.print_response("New York")
Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
Set your environment variables
export CLOUDFLARE_API_TOKEN=xxx
export CLOUDFLARE_ACCOUNT_ID=xxx
export CLOUDFLARE_AI_GATEWAY_ID=xxx # optional, defaults to "default"
Install dependencies
uv pip install -U openai agno
Run Agent
python cookbook/90_models/cloudflare/structured_output.py