Skip to main content
This example builds on Hello World by adding a tool that calls a real weather API and an output schema that returns structured data. The agent uses Open-Meteo - a free weather API that requires no API key - so you can run it immediately.

What you’ll learn

  • Defining a tool with tool() and Zod parameter schema
  • Calling an external HTTP API inside a tool
  • Using outputSchema for structured JSON output
  • Type-safe Agent<TDeps, TOutput> generics

Prerequisites

  • Vibes installed
  • ANTHROPIC_API_KEY set (Open-Meteo requires no key)

Complete example

Source: examples/weather-agent.ts

Run it

How it works

Tool definition: tool() wraps an async function. The parameters Zod schema is used to generate the tool’s JSON schema for the model - the model sees field names and descriptions. Execute function: _ctx is the RunContext (available when using dependencies - see Dependencies). The second argument is the validated, typed tool args. Output schema: outputSchema makes the agent return a typed object instead of a string. Vibes instructs the model to produce structured output matching the Zod schema. Type generics: Agent<undefined, z.infer<typeof WeatherReport>> - first param is deps type (none here), second is the output type. TypeScript infers result.output as WeatherReport.

Next steps