Skip to content

Commit

Permalink
Merge pull request #177 from PrefectHQ/tasks-and-agents
Browse files Browse the repository at this point in the history
Add tasks and agents guide
  • Loading branch information
jlowin authored Jun 25, 2024
2 parents eaded70 + 96da21c commit af5c484
Show file tree
Hide file tree
Showing 8 changed files with 470 additions and 26 deletions.
73 changes: 73 additions & 0 deletions docs/examples/call-routing.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
title: Customer Call Routing
---

In this example, two agents interact in a call routing scenario. One agent plays the role of a customer calling into a call center, while the other agent is a trainee customer service representative. The trainee must listen to the customer's story and route them to the correct department based on the information provided.


```python
import random
from enum import Enum
import controlflow as cf


class Department(Enum):
SALES = "sales"
SUPPORT = "support"
BILLING = "billing"
TECHNICAL = "technical"
RETURNS = "returns"



@cf.flow
def routing_flow():
department = random.choice(list(Department))

# create an agent to be our "customer"
customer = cf.Agent(
"Customer",
instructions=f"""
You are training customer reps by pretending to be a customer
calling into a call center. You need to be routed to the
{department} department. Come up with a good backstory.""",
)

trainee = cf.Agent(
"Trainee",
instructions="""
You are a trainee customer service representative. You need to
listen to the customer's story and route them to the correct
department. Note that the customer is another agent training you.""",
)

task = cf.Task(
"""
In this task, the customer agent and the trainee agent will speak to
each other. The customer is trying to be routed to the correct
department. The trainee will listen and ask questions to determine the
correct department.
""",
instructions="""
Only the trainee can mark the task successful by routing the customer to
the correct department. The trainee must begin the conversation by
greeting the customer. Agents speak to each other by posting messages
directly to the thread. Do not use the `end_turn` tool or try to talk
to a user.
""",
agents=[trainee, customer],
result_type=Department,
)

routed_dapartment = task.run()
if routed_dapartment == department:
print("Success! The customer was routed to the correct department.")
else:
print(
"Failed. The customer was routed to the wrong department. "
f"The correct department was {department}."
)

if __name__ == "__main__":
routing_flow()
````
5 changes: 4 additions & 1 deletion docs/examples/library.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ title: Library
---

<CardGroup cols={2}>
<Card title="Rock, Paper, Scissors" icon="hand-scissors" href="/examples/rock_paper_scissors">
<Card title="Rock, Paper, Scissors" icon="hand-scissors" href="/examples/rock-paper-scissors">
Play a game of rock, paper, scissors against an AI - without letting it cheat.
</Card>
<Card title="Customer Call Routing" icon="phone" href="/examples/call-routing">
Two agents cooperate to route customer calls to the correct department.
</Card>
<Card title="Don't Panic." icon="paper-plane">
More examples are coming soon.
</Card>
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions docs/guides/agentic-loop.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: Working with the Agentic Loop
sidebarTitle: "Agentic Loops"
title: Managing the Agentic Loop
---

The **agentic loop** is a fundamental concept in agentic workflows, representing the iterative process of invoking AI agents to make progress towards a goal. It is at the heart of every agentic workflow because agents almost always require multiple invocations to complete complex tasks.
Expand Down
Loading

0 comments on commit af5c484

Please sign in to comment.