agents.examples.backend_tool_rendering
Backend Tool Rendering example.
Demonstrates an agent that uses backend tools to fetch data which is then rendered by the frontend. Unlike frontend tools, these tools execute on the backend and return data that the frontend can use to render UI components.
Features:
- Backend tool execution
- Real API calls (weather data)
- Frontend rendering of tool results
This pattern is useful for:
- Weather applications
- Data dashboards
- Any scenario where backend APIs provide data for UI
get_weather
@agent.tool_plain
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