Skip to main content
Agents in Polos use LLMs to autonomously reason about tasks and decide which actions to take. This guide covers the fundamentals of creating and running agents.

Defining an agent

Create an agent by specifying a model provider, system prompt, and optional tools:

Agent configuration

Required parameters:
  • id - Unique identifier for the agent
  • provider - LLM provider (see supported providers below)
  • model - Model name (e.g., “gpt-4o”, “claude-sonnet-4”)
Optional parameters:
  • system_prompt - Instructions that guide the agent’s behavior
  • tools - List of tools the agent can call
  • output_schema - Pydantic model for structured outputs
  • stop_conditions - Conditions that terminate agent execution

Supported providers

  • openai - OpenAI (GPT-5, GPT-5-mini, GPT-4o, etc.)
  • anthropic - Anthropic (Claude Sonnet, Claude Opus, etc.)
  • gemini - Google Gemini
  • groq - Groq
  • fireworks - Fireworks AI
  • together - Together AI
  • azure - Azure OpenAI

Running agents

Synchronous execution with agent.run()

Use agent.run() for complete execution:
How it works:
  1. Agent receives your message
  2. LLM analyzes the request and decides if tools are needed
  3. If tools are needed, agent executes them. If multiple tool calls are needed, they are executed in parallel.
  4. Agent feeds tool results back to the LLM
  5. Process repeats until the agent has a final answer or hits a stop condition
  6. Returns the complete response

Provider-specific parameters

You can pass any keyword argument supported by your provider:
These parameters are passed directly to the underlying provider API.

Streaming with agent.stream()

Stream responses for real-time feedback:
Stream features:
  • Real-time token streaming
  • Access to intermediate tool calls
  • Progress tracking
You can also pass provider-specific parameters to agent.stream():
See Streaming for advanced streaming patterns.

Agent responses

Both agent.run() and agent.stream() return response objects with useful information:

Triggering agents from Slack

You can trigger agents directly from Slack by @mentioning your bot. The agent’s output streams back to the originating Slack thread.
@sales-agent is the ID of the agent you want to trigger. The bot routes the message to the right agent and streams the response back to the same thread. To set this up, create a Slack app, configure event subscriptions, and register the app with your orchestrator. See Slack Integration for the full setup guide.

Sandbox tools

Give agents the ability to write code, run shell commands, and explore a codebase inside a controlled environment. A single call to sandboxTools() creates six tools (exec, read, write, edit, glob, grep) that share an execution environment.
Polos supports three execution environments: The exec tool supports security modes to control which commands run without approval: allow-always (default for Docker), allowlist (pattern-based), and approval-always (default for local). See Sandbox for the full configuration reference.

Agent durability

Agents in Polos are durable - they survive failures and resume from the last completed step. What gets persisted:
  • Tool call inputs and outputs
  • LLM reasoning steps
  • Conversation history
  • Agent state
Example recovery scenario:
Benefits:
  • No duplicate tool calls
  • No wasted API tokens
  • No lost progress
See Durable Execution for how this works under the hood.

Using agents in workflows

Agents are workflows, so you can compose them with other workflow steps:
This combines agent autonomy with workflow orchestration for complex multi-step processes.

Next steps

Core features: Advanced patterns: