> ## Documentation Index
> Fetch the complete documentation index at: https://polos.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent with Tools

> Create an agent with tools

A simple agent that uses a tool to look up weather information.

## Define a tool

<CodeGroup>
  ```python Python theme={null}
  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")
  ```

  ```typescript TypeScript theme={null}
  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' };
    },
  );
  ```
</CodeGroup>

## Create the agent

<CodeGroup>
  ```python Python theme={null}
  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))],
  )
  ```

  ```typescript TypeScript theme={null}
  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 })],
  });
  ```
</CodeGroup>

## Run it

<CodeGroup>
  ```bash Python theme={null}
  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
  ```

  ```bash TypeScript theme={null}
  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
  ```
</CodeGroup>

Open [http://localhost:5173](http://localhost:5173) to view your agents and workflows, run them from the UI, and see execution traces.

[Python example on GitHub](https://github.com/polos-dev/polos/tree/main/python-examples/01-agent-with-tools) | [TypeScript example on GitHub](https://github.com/polos-dev/polos/tree/main/typescript-examples/01-agent-with-tools)
