Skip to main content

examples.tools.ag_ui

AG-UI example tool implementations.

These callables replicate the exact feature set of the former /api/v1/examples/* AG-UI demo agents, exposed as reusable runtime tools that can be attached to agents through agentspecs.

Each function is referenced from a ToolSpec runtime block via package + method and registered on a pydantic_ai.Agent through register_agent_tools (which wires them with tool_plain).

current_time

async def current_time(timezone: str = "UTC") -> str

Get the current time in ISO format.

Arguments:

  • timezone - The timezone to use (e.g., 'UTC', 'America/New_York', 'Europe/London').

Returns:

The current time in ISO format string.

get_weather

async def get_weather(location: str) -> dict[str, str | float]

Get current weather for a location.

This tool fetches real weather data from Open-Meteo API. The frontend can render this data as a weather card.

Arguments:

  • location - City name (e.g., "New York", "London", "Tokyo").

Returns:

Dictionary with weather information:

  • temperature: Current temperature in Celsius
  • feelsLike: Apparent temperature
  • humidity: Relative humidity percentage
  • windSpeed: Wind speed in km/h
  • windGust: Wind gust speed in km/h
  • conditions: Human-readable weather description
  • location: Resolved location name

generate_haiku

async def generate_haiku(japanese: list[str], english: list[str],
gradient: str) -> str

Generate a haiku and display it in the UI.

This tool creates a haiku with Japanese text, English translation, and a beautiful gradient background. The frontend will render this as a card in both the chat and the main display area.

Arguments:

  • japanese - Array of three lines of the haiku in Japanese (5-7-5 syllables).
  • english - Array of three lines of the haiku translated to English.
  • gradient - CSS gradient string for the card background.
  • Example - linear-gradient(135deg, color1 0%, color2 100%)

Returns:

Confirmation message.

Step Objects

class Step(BaseModel)

A step in a plan.

Plan Objects

class Plan(BaseModel)

A plan with multiple steps.

create_plan

async def create_plan(steps: list[str]) -> StateSnapshotEvent

Create a plan with multiple steps.

This initializes the shared state with a new plan.

Arguments:

  • steps - List of step descriptions to create the plan.

Returns:

StateSnapshotEvent containing the initial plan state.

update_plan_step

async def update_plan_step(
index: int,
description: Optional[str] = None,
status: Optional[StepStatus] = None) -> StateDeltaEvent

Update a specific step in the plan.

Uses JSON Patch (RFC 6902) for efficient incremental updates.

Arguments:

  • index - The index of the step to update (0-based).
  • description - New description for the step (optional).
  • status - New status for the step (optional).

Returns:

StateDeltaEvent containing the JSON Patch operations.

TaskStep Objects

class TaskStep(BaseModel)

A step in a task plan.

TaskPlan Objects

class TaskPlan(BaseModel)

A task plan with multiple steps for human review.

generate_task_steps

async def generate_task_steps(steps: list[str]) -> StateSnapshotEvent

Generate a list of task steps for the user to review and approve.

This creates a task plan that will be displayed to the user. The user can enable/disable steps before confirming execution.

Arguments:

  • steps - List of step descriptions (brief imperative commands).

Returns:

StateSnapshotEvent containing the task plan for user review.

SkillLevel Objects

class SkillLevel(StrEnum)

The skill level required for the recipe.

SpecialPreferences Objects

class SpecialPreferences(StrEnum)

Special preferences for the recipe.

CookingTime Objects

class CookingTime(StrEnum)

The cooking time of the recipe.

Ingredient Objects

class Ingredient(BaseModel)

An ingredient in a recipe.

Recipe Objects

class Recipe(BaseModel)

A recipe with all its details.

display_recipe

async def display_recipe(recipe: Recipe) -> StateSnapshotEvent

Display the recipe to the user.

This tool updates the shared state with the new recipe, which is then reflected in the UI.

Arguments:

  • recipe - The complete recipe to display.

Returns:

StateSnapshotEvent containing the recipe snapshot.