Customer Call Routing
Train an agent to route customer calls to the correct department.
In this example, you’ll witness a roleplay between two AI agents:
- A “customer” agent, who has been assigned a random department they need to reach but is instructed not to directly state it.
- A “trainee” customer service representative, who must figure out the correct department based on the customer’s story.
The conversation will continue back and forth until the trainee feels confident enough to route the call. This example showcases how ControlFlow can be used to create dynamic, multi-turn interactions between agents, with one agent (the trainee) ultimately making a decision that determines the outcome of the task.
As you run this example, you’ll see the conversation unfold in real-time, culminating in the trainee’s decision to route the call. The success of the interaction depends on whether the trainee correctly identifies the department the customer needs.
Code
Key points
-
Multi-agent interaction: This example showcases how to orchestrate a conversation between two AI agents, each with distinct roles and objectives.
-
Parent task as control flow: The
main_task
serves dual purposes - it represents the overall objective and acts as a control mechanism for the conversation loop. Thewhile main_task.is_incomplete()
construct creates a flexible, AI-driven loop that continues until the trainee decides to route the call. -
Explicit turn-taking: Instead of using ControlFlow’s built-in turn strategies, this example manually alternates between the customer and trainee agents. This provides fine-grained control over the conversation flow and allows for specific instructions to be given to each agent on each turn.
-
Task-specific tools: The trainee is given access to the
main_task
’s success tool, allowing them to mark the overall task as complete when they’re ready to route the call, even though that task isn’t currently active. This demonstrates how tools can be used to give agents control over task state.
Further reading
- For more details on creating and managing tasks, see the Tasks documentation.
- To learn more about agents and their capabilities, check out the Agents guide.
- For information on how ControlFlow manages conversations and context, refer to the Message History guide.
This example effectively demonstrates how to create a complex, interactive scenario in ControlFlow, with fine-grained control over agent interactions and task flow. It showcases the flexibility of the framework in handling multi-turn conversations and decision-making processes, making it an excellent template for building sophisticated AI-powered applications.