|
| 1 | +# Weather agent Example |
| 2 | + |
| 3 | +A simple example demonstrating the basics of Polos: |
| 4 | +- Creating agent with tool |
| 5 | +- Running a worker to execute the agent |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +1. **Polos Server** - The orchestrator that manages workflow execution |
| 10 | +2. **Python 3.10+** |
| 11 | +3. **Polos project ID** - Get this from the UI page http://localhost:5173/settings |
| 12 | +3. **OpenAI API Key** - For the weather agent |
| 13 | + |
| 14 | +## Setup |
| 15 | + |
| 16 | +### 1. Start the Polos Server |
| 17 | + |
| 18 | +Install and start the Polos server (orchestrator): |
| 19 | + |
| 20 | +```bash |
| 21 | +# Install polos-server |
| 22 | +curl -fsSL https://install.polos.dev/install.sh | bash |
| 23 | + |
| 24 | +# Start the server |
| 25 | +polos-server start |
| 26 | +``` |
| 27 | + |
| 28 | +Example output: |
| 29 | +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 30 | +🎉 Polos server is running! |
| 31 | +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 32 | +📡 Orchestrator API: http://127.0.0.1:8080 |
| 33 | +🌐 UI: http://127.0.0.1:5173 |
| 34 | +🔑 Project ID: 8348be0b-bee2-4b28-bd7a-3d5a873c01ab |
| 35 | +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 36 | + |
| 37 | + |
| 38 | +The server runs at `http://localhost:8080` by default. |
| 39 | + |
| 40 | +### 2. Install Dependencies |
| 41 | + |
| 42 | +```bash |
| 43 | +# Using uv (recommended) |
| 44 | +uv sync |
| 45 | + |
| 46 | +# Or using pip |
| 47 | +pip install -e . |
| 48 | +``` |
| 49 | + |
| 50 | +### 3. Configure Environment |
| 51 | + |
| 52 | +Create a `.env` file: |
| 53 | + |
| 54 | +```bash |
| 55 | +# Required: Your project ID. |
| 56 | +# You can get this from the output printed by `polos-server start` or from the UI page at |
| 57 | +# http://localhost:5173/projects/settings (the ID will be below the project name 'default') |
| 58 | +POLOS_PROJECT_ID=my-project |
| 59 | + |
| 60 | +# Required: OpenAI API key for the agent |
| 61 | +OPENAI_API_KEY=sk-... |
| 62 | + |
| 63 | +# Optional: Orchestrator URL (defaults to http://localhost:8080) |
| 64 | +# POLOS_API_URL=http://localhost:8080 |
| 65 | +``` |
| 66 | + |
| 67 | +## Running the Example |
| 68 | + |
| 69 | +### Terminal 1: Start the Worker |
| 70 | + |
| 71 | +The worker executes workflows and agents: |
| 72 | + |
| 73 | +```bash |
| 74 | +python worker.py |
| 75 | +``` |
| 76 | + |
| 77 | +You should see: |
| 78 | +``` |
| 79 | +Starting worker... |
| 80 | + Project ID: <my-project> |
| 81 | + Agents: ['weather_agent'] |
| 82 | + Press Ctrl+C to stop |
| 83 | +``` |
| 84 | + |
| 85 | +### Terminal 2: Run the Example |
| 86 | + |
| 87 | +In a separate terminal, run: |
| 88 | + |
| 89 | +```bash |
| 90 | +python main.py |
| 91 | +``` |
| 92 | + |
| 93 | +You should see: |
| 94 | +``` |
| 95 | +Invoking weather_agent... |
| 96 | +Result: 'The weather in New York is...' |
| 97 | +``` |
| 98 | + |
| 99 | +## What's Happening? |
| 100 | + |
| 101 | +1. **main.py** invokes `weather_agent` with input "What's the weather like in New York?" |
| 102 | +2. **Polos Server** receives the workflow (agent) and queues it for execution |
| 103 | +3. **worker.py** picks up the agent request and executes it: |
| 104 | + - Starts the weather agent to get weather information |
| 105 | + - The agent uses the `get_weather` tool |
| 106 | +4. The result is returned through Polos Server to the caller |
| 107 | + |
| 108 | +## Files |
| 109 | + |
| 110 | +- `agents.py` - Defines the `weather_agent` agent |
| 111 | +- `tools.py` - Defines the `get_weather` tool with mock weather data |
| 112 | +- `worker.py` - Runs the worker that executes workflows |
| 113 | +- `main.py` - Invokes the workflow and displays results |
0 commit comments