# Tutor Agent

Tutor agent built on the handoff pattern: a triage agent reads each student question and hands it to a history or math specialist to answer.

- Category: Customer Support / Chatbots
- Capabilities: agents, memory, workflows
- Source code: [python](https://github.com/agnt5dev/templates/tree/main/python/tutor_agent), [typescript](https://github.com/agnt5dev/templates/tree/main/typescript/tutor_agent), [go](https://github.com/agnt5dev/templates/tree/main/go/tutor_agent)
- [All templates](https://agnt5.com/templates.md)

The tutor-agent template demonstrates the agent handoff pattern: a triage agent reads the student's question, decides which subject it belongs to, and hands the conversation off to a specialist agent that answers it end to end.

## What you'll build

- A `triage_agent` that classifies an incoming question by subject
- A `history_tutor_agent` and a `math_tutor_agent`, each with domain-specific instructions
- Handoffs wired with `handoff()` so the triage agent can transfer control without the caller managing routing logic
- A single chat workflow that drives the whole exchange

## Requirements

- Python 3.12+ or Node.js 22+
- `OPENAI_API_KEY`
- The AGNT5 CLI

## Install

```bash
curl -LsSf https://agnt5.com/cli.sh | bash
```

## Setup



### Scaffold the project



**Python**

```bash
agnt5 create --template python/tutor_agent my-tutor
cd my-tutor
```


**TypeScript**

```bash
agnt5 create --template typescript/tutor_agent my-tutor
cd my-tutor
```




### Set environment variables

```bash
cp .env.example .env
```


### Install dependencies



**uv (Python)**

```bash
uv sync
```


**pip (Python)**

```bash
pip install -e .
```


**npm (TypeScript)**

```bash
npm install
```




### Start the AGNT5 dev server

```bash
agnt5 dev
```


## How it works

The chat workflow runs the triage agent with the incoming message. The triage agent's instructions tell it to classify the question - history, math, or general - and hand off to the matching specialist when appropriate. Each specialist is registered as a handoff target on the triage agent. Once a handoff fires, the specialist agent answers the question directly using its own domain-specific instructions; the workflow doesn't need to know which specialist ultimately responded.

Passing the workflow's context into the triage agent's run call means the whole handoff chain - the triage turn and whichever specialist responds - checkpoints through the workflow's durable context.


> The handoff contract is just a description string plus a target agent. Adding a third subject means writing one more specialist agent and one more handoff entry on the triage agent - no branching logic to maintain.


## Key files



**Python**

```text
app.py                       - Worker entry point
src/tutor_agent/workflows.py - tutor_chat_workflow: a thin wrapper that runs the triage agent with context=ctx
src/tutor_agent/agents.py    - triage_agent, history_tutor_agent, math_tutor_agent, and their handoff wiring
```


**TypeScript**

```text
app.ts            - Worker entry point
src/workflows.ts  - tutorChatWorkflow: a thin wrapper that runs the triage agent with ctx
src/agents.ts     - getHistoryTutorAgent(), getMathTutorAgent(), getTutorAgent(), and their handoff wiring
```



## Customize

**Add a subject.** Write a new specialized `Agent` with its own instructions, then add a `handoff(...)` entry for it on `triage_agent` and mention the trigger criteria in the triage instructions.

**Change the triage criteria.** The decision logic lives entirely in the triage agent's instructions in `agents.py`/`agents.ts` - no code branches to update.

**Give a specialist tools.** Pass a `tools=[...]` list to `history_tutor_agent` or `math_tutor_agent` (e.g. a `check_equation` tool for math) - handoffs preserve whatever tools the target agent defines.

## Next steps

- Read [/docs/build/agents](https://agnt5.com/docs/build/agents.md) for agent handoffs
- Compare with [travel_booking_customer_service](https://agnt5.com/templates/travel_booking_customer_service.md) for a single-agent, tool-based alternative to routing
- See [/docs/build/workflows](https://agnt5.com/docs/build/workflows.md#state) for durable run- and session-scoped state

> For the complete documentation index, see [llms.txt](/llms.txt).
> A full single-fetch corpus is available at [llms-full.txt](/llms-full.txt).
