Run & Chat
ag2 run#
Execute an agent from a Python file or YAML config with a single message.
Options#
| Flag | Description |
|---|---|
--message, -m | The message to send to the agent |
--max-turns | Maximum conversation turns (default: 10) |
--verbose, -v | Show detailed agent output |
--json | Output structured JSON result |
Examples#
Run an agent with a message:
Pipe input from stdin:
Get structured JSON output:
YAML Config#
You can define agents in YAML instead of Python:
config.yaml
llm:
model: gpt-4o-mini
agents:
- name: assistant
system_message: "You are a helpful research assistant."
ag2 chat#
Start an interactive terminal chat session with an agent or team.
Options#
| Flag | Description |
|---|---|
--model | Create an ad-hoc agent with this model |
--system | System message for ad-hoc agent |
--verbose, -v | Show detailed output |
--max-turns | Maximum turns per exchange (default: 10) |
Examples#
Chat with an agent from a file:
Create a quick ad-hoc agent:
Session Commands#
During a chat session, you can use these commands:
| Command | Description |
|---|---|
/quit | End the session |
/cost | Show token usage and cost |
/history | Show conversation history |
Session Recording#
All chat sessions are automatically saved to ~/.ag2/sessions/ for later replay and debugging. Use ag2 replay to review past sessions.