Weather Tool LLM Loop
Define one weather tool and let an LLM turn call it before producing a final answer.
What You Build
Section titled “What You Build”A Cloudflare agent facade with get_current_weather, one LLM route, and a
submit call that returns a tool-informed answer.
Prerequisites
Section titled “Prerequisites”-
Define the weather tool:
import { defineTool } from "@agent-os/kernel/tools";import { Schema } from "effect";const getCurrentWeather = defineTool({name: "get_current_weather",description: "Get the current weather for a city.",args: Schema.Struct({ city: Schema.String }),authority: "weather.read",admit: () => ({ ok: true }),execute: ({ city }) => ({city,temperatureC: 22,condition: "sunny",}),}); -
Register the tool in the same
defineAgentDOfacade as the LLM route:export const AgentDO = defineAgentDO<Env>({bindings: [endpoint<Env>("llm").from((env) => env.LLM_ENDPOINT),credential<Env>("llm-key").from((env) => env.LLM_KEY),],llms: {default: openAIChat({model: "gpt-4.1-mini",endpoint: "llm",credential: "llm-key",}),},tools: [getCurrentWeather],scopeRefForScope: (scope) => ({ kind: "conversation", scopeId: scope }),}); -
Submit a user turn through the facade:
const result = await agent.submit({intent: "What is the weather in Lisbon?",input: {},deliver: "weather.answer.ready",budget: { maxTurns: 3 },}); -
Keep weather facts in the tool implementation. Do not put provider material, API keys, raw provider responses, or resolved endpoint URLs into ledger events.
Checkpoint
Section titled “Checkpoint”The deterministic local proof for this tutorial used a fake LLM transport and verified this sequence:
request 1 includes get_current_weatherLLM returns get_current_weather({ city: "Lisbon" })runtime executes the toolrequest 2 includes the tool resultLLM returns "Lisbon is sunny and 22 C."weather.answer.ready is deliveredA live provider checkpoint is a separate opt-in smoke: run it only after the provider endpoint, credential, and model are declared from one source.
Tighten the tool contract with tool schema and authority.