Define a tool
from pydantic import BaseModel
from polos import tool, WorkflowContext
class WeatherInput(BaseModel):
city: str
class WeatherOutput(BaseModel):
city: str
temperature: int
condition: str
@tool(description="Get weather for a city")
async def get_weather(ctx: WorkflowContext, input: WeatherInput) -> WeatherOutput:
# In production, call a real weather API
return WeatherOutput(city=input.city, temperature=72, condition="Sunny")
import { defineTool, type WorkflowContext } from '@polos/sdk';
import { z } from 'zod';
const weatherInputSchema = z.object({
city: z.string(),
});
const weatherOutputSchema = z.object({
city: z.string(),
temperature: z.number(),
condition: z.string(),
});
export const getWeather = defineTool(
{
id: 'get_weather',
description: 'Get weather for a city',
inputSchema: weatherInputSchema,
outputSchema: weatherOutputSchema,
},
async (_ctx: WorkflowContext, input) => {
// In production, call a real weather API
return { city: input.city, temperature: 72, condition: 'Sunny' };
},
);
Create the agent
from polos import Agent, max_steps, MaxStepsConfig
weather_agent = Agent(
id="weather_agent",
provider="openai",
model="gpt-4o-mini",
system_prompt="You are a weather assistant. Use the get_weather tool to look up weather.",
tools=[get_weather],
stop_conditions=[max_steps(MaxStepsConfig(limit=10))],
)
import { defineAgent, maxSteps } from '@polos/sdk';
import { openai } from '@ai-sdk/openai';
import { getWeather } from './tools.js';
export const weatherAgent = defineAgent({
id: 'weather_agent',
model: openai('gpt-4o-mini'),
systemPrompt: 'You are a weather assistant. Use the get_weather tool to look up weather.',
tools: [getWeather],
stopConditions: [maxSteps({ count: 10 })],
});
Run it
git clone https://github.com/polos-dev/polos.git
cd polos/python-examples/01-weather-agent
cp .env.example .env # Add your POLOS_PROJECT_ID and OPENAI_API_KEY
uv sync
python main.py
git clone https://github.com/polos-dev/polos.git
cd polos/typescript-examples/01-agent-with-tools
cp .env.example .env # Add your POLOS_PROJECT_ID and OPENAI_API_KEY
npm install
npx tsx main.ts