Create a chat agent with tools
from polos import Agent, max_steps, MaxStepsConfig
chat_assistant = Agent(
id="chat_assistant",
provider="openai",
model="gpt-4o-mini",
system_prompt="""You are a friendly assistant. You can:
- Tell the current time using get_current_time
- Get weather using get_weather
- Perform calculations using calculator""",
tools=[get_current_time, get_weather, calculator],
stop_conditions=[max_steps(MaxStepsConfig(limit=10))],
)
import { defineAgent, maxSteps } from '@polos/sdk';
import { openai } from '@ai-sdk/openai';
import { getCurrentTime, getWeather, calculator } from './tools.js';
const chatAssistant = defineAgent({
id: 'chat_assistant',
model: openai('gpt-4o-mini'),
systemPrompt:
'You are a friendly assistant. You can:\n' +
'- Tell the current time using get_current_time\n' +
'- Get weather using get_weather\n' +
'- Perform calculations using calculator',
tools: [getCurrentTime, getWeather, calculator],
stopConditions: [maxSteps({ count: 10 })],
});
Maintain conversation context
# Use conversation_id to maintain history across messages
conversation_id = "user-123-session"
# First message
result1 = await chat_assistant.stream(
polos,
"What's the weather in Tokyo?",
conversation_id=conversation_id,
)
# Follow-up uses same context
result2 = await chat_assistant.stream(
polos,
"How about London?", # Agent remembers we're asking about weather
conversation_id=conversation_id,
)
import { randomUUID } from 'node:crypto';
// Use conversationId to maintain history across messages
const conversationId = randomUUID();
// First message
const result1 = await chatAssistant.stream(polos, {
input: "What's the weather in Tokyo?",
conversationId,
});
// Follow-up uses same context
const result2 = await chatAssistant.stream(polos, {
input: 'How about London?', // Agent remembers we're asking about weather
conversationId,
});
Run it
git clone https://github.com/polos-dev/polos.git
cd polos/python-examples/04-conversational-chat
cp .env.example .env # Add your POLOS_PROJECT_ID and API key
uv sync
python main.py
git clone https://github.com/polos-dev/polos.git
cd polos/typescript-examples/04-conversational-chat
cp .env.example .env # Add your POLOS_PROJECT_ID and API key
npm install
npx tsx main.ts