|
1 | 1 | # [Agentic] Multiturn |
2 | 2 |
|
3 | | -This tutorial demonstrates how to handle multiturn conversations in AgentEx agents using the agentic ACP type. |
| 3 | +Handle multi-turn conversations in agentic agents with task-based state management. Each task maintains its own conversation history automatically. |
4 | 4 |
|
5 | | -## Official Documentation |
| 5 | +## What You'll Learn |
| 6 | +- How tasks maintain conversation state across multiple exchanges |
| 7 | +- Difference between sync and agentic multiturn patterns |
| 8 | +- Building stateful conversational agents with minimal code |
6 | 9 |
|
7 | | -[010 Multiturn Base Agentic](https://dev.agentex.scale.com/docs/tutorials/agentic/base/multiturn/) |
| 10 | +## Prerequisites |
| 11 | +- Development environment set up (see [main repo README](https://github.com/scaleapi/scale-agentex)) |
| 12 | +- Backend services running: `make dev` from repository root |
| 13 | +- Understanding of basic agentic agents (see [000_hello_acp](../000_hello_acp/)) |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +```bash |
| 18 | +cd examples/tutorials/10_agentic/00_base/010_multiturn |
| 19 | +uv run agentex agents run --manifest manifest.yaml |
| 20 | +``` |
| 21 | + |
| 22 | +## Key Pattern |
| 23 | + |
| 24 | +Unlike sync agents where you manually track conversation history, agentic agents automatically maintain state within each task: |
| 25 | + |
| 26 | +```python |
| 27 | +@app.on_task_event_send() |
| 28 | +async def on_task_event_send(event_send: TaskEventSendInput): |
| 29 | + # The task's messages list automatically includes all previous exchanges |
| 30 | + messages = event_send.task.messages |
| 31 | + |
| 32 | + # No need to manually pass history - it's already there! |
| 33 | + response = await openai_client.chat.completions.create( |
| 34 | + model="gpt-4o-mini", |
| 35 | + messages=messages |
| 36 | + ) |
| 37 | + |
| 38 | + return {"content": response.choices[0].message.content} |
| 39 | +``` |
| 40 | + |
| 41 | +## Try It |
| 42 | + |
| 43 | +1. Start the agent with the command above |
| 44 | +2. Open the web UI or use the notebook to create a task |
| 45 | +3. Send multiple messages in the same task: |
| 46 | + - "What's 25 + 17?" |
| 47 | + - "What was that number again?" |
| 48 | + - "Multiply it by 2" |
| 49 | +4. Notice the agent remembers context from previous exchanges |
| 50 | + |
| 51 | +## When to Use |
| 52 | +- Conversational agents that need memory across exchanges |
| 53 | +- Chat interfaces where users ask follow-up questions |
| 54 | +- Agents that build context over time within a session |
| 55 | + |
| 56 | +## Why This Matters |
| 57 | +Task-based state management eliminates the complexity of manually tracking conversation history. The AgentEx platform handles state persistence automatically, making it easier to build stateful agents without custom session management code. |
| 58 | + |
| 59 | +**Comparison:** In the sync version ([00_sync/010_multiturn](../../../00_sync/010_multiturn/)), you manually manage conversation history. Here, the task object does it for you. |
| 60 | + |
| 61 | +**Next:** [020_streaming](../020_streaming/) - Add real-time streaming responses |
0 commit comments