> ## 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.

# Conversational Chat

> Build a chat agent with conversation memory

Build an interactive chat agent that maintains conversation history.

## Create a chat agent with tools

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

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

## Maintain conversation context

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

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

## Run it

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

  ```bash TypeScript theme={null}
  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
  ```
</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/04-conversational-chat) | [TypeScript example on GitHub](https://github.com/polos-dev/polos/tree/main/typescript-examples/04-conversational-chat)
