A refund waits for the manager
A refund is the one thing the desk will not do on its own. The flow stops, saves itself, and waits for a person's answer.
The same desk, with a ticket that asks for money back.
from crewai.flow.persistence import SQLiteFlowPersistence
from desk import SupportDesk
db = SQLiteFlowPersistence("desk.db")
desk = SupportDesk(persistence=db, suppress_flow_events=True)
pending = desk.kickoff(inputs={"message": "Please refund order A17, it arrived broken."})
flow_id = pending.context.flow_idThe proposal reached the manager and the flow stopped there. Its state is in desk.db, so the process can end and nothing is lost. No refund has been made.
Approved
later = SupportDesk.from_pending(flow_id, db, suppress_flow_events=True)
later.resume("Yes, refund it")
print(later.state.reply)from_pending rebuilds the flow from the saved state, and resume carries the manager's answer into the second router, which takes the approved path.
Refused
later = SupportDesk.from_pending(flow_id, db, suppress_flow_events=True)
later.resume("No, it was delivered intact")
print(later.state.reply)Pick one to watch it run, step by step.
The whole desk again, now that every path in it has run: the status path through the crew, the missing order, and both ends of the refund.
The same saved ticket, resumed a second time with a different answer, takes the refused path and tells the customer. The flow never reaches pay, which is what the pause is for.
What this course did not cover
CrewAI is large. These are the parts a first course leaves out, and what each is for.
| Topic | What it is for |
|---|---|
| The CLI and project layout | crewai create builds a project of YAML files and classes, with run, train, test, replay and chat around it. |
| YAML crews with @CrewBase | The same agents and tasks written in YAML files with a class of decorators, which is what the CLI generates. |
| Knowledge sources | Files an agent searches before answering, held in a vector store. |
| Planning and reasoning | A model that writes a plan into every task, or an agent that plans before it starts. |
| Training and testing a crew | crew.train() feeds human corrections back in; crew.test() scores runs with an evaluator model. |
| Streaming, checkpointing and replay | Watching a run as it happens, saving a crew between tasks, and rerunning from a chosen task. |
| More hooks and human input | Kickoff and step hooks, and human_input=True for a person reviewing at the terminal. |
| The tool catalogue | About eighty ready-made tools in crewai-tools for search, scraping, files and databases. |
| CrewAI AMP | The hosted platform: deployment, tracing and dashboards for crews you have built. |
- Resume the same flow twice with the same answer and see what the second run does.
- Add a rule that refunds under 20 need no approval.
- Store each finished reply in the crew's memory, under the customer's scope.
Little by little, you're building something great.