What you’ll build
- A CrewAI tool that emits a
handoffpayload (reason + target + context). - Agent instructions that decide when to escalate.
- NDJSON streaming so CometChat can display escalation status in real time.
Prerequisites
- CrewAI project +
/kickoffstreaming endpoint (crew-ai.mdx) - A human support flow in your product (ticketing, live agent queue, etc.)
Steps
1
Define handoff targets
Decide where to route:
support, sales, billing, or a specific user ID.2
Create a handoff tool
Return a JSON payload with
target, reason, and optional priority. Raise exceptions if required fields are missing.3
Write agent rules
In the backstory, describe clear thresholds for escalation (e.g., compliance, billing disputes, missing permissions).
4
Handle on the client
When CometChat receives a
tool_result for handoff, trigger your own UI/notification flow.Sample handoff tool
src/crew_demo/tools/handoff.py
crew.py.
Agent configuration
src/crew_demo/config/agents.yaml
src/crew_demo/config/tasks.yaml
CometChat integration
- Provider: CrewAI
- Agent ID:
handoff - Deployment URL: your
/kickoff - Client: map the
handofftool payload to your routing layer (open a ticket, page on-call, or DM a user).