-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathcustomer-service.py
More file actions
139 lines (122 loc) · 3.88 KB
/
customer-service.py
File metadata and controls
139 lines (122 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from praisonaiagents import Agent, Task, PraisonAIAgents
import time
from typing import Dict, List
def classify_query():
"""Simulates query classification"""
query_types = [
{"type": "technical", "priority": "high", "complexity": "complex"},
{"type": "billing", "priority": "medium", "complexity": "simple"},
{"type": "general", "priority": "low", "complexity": "simple"}
]
return query_types[int(time.time()) % 3]
def handle_query(query: Dict):
"""Simulates query handling"""
responses = {
"technical": "Technical support solution provided",
"billing": "Billing inquiry resolved",
"general": "General information provided"
}
return responses.get(query["type"], "Query forwarded to specialist")
def evaluate_satisfaction():
"""Simulates satisfaction evaluation"""
scores = ["satisfied", "neutral", "unsatisfied"]
return scores[int(time.time()) % 3]
def optimize_response(satisfaction: str):
"""Simulates response optimization"""
optimizations = {
"satisfied": "maintain_approach",
"neutral": "minor_adjustments",
"unsatisfied": "major_revision"
}
return optimizations.get(satisfaction, "review_process")
# Create specialized agents
classifier = Agent(
name="Query Classifier",
role="Query Classification",
goal="Classify incoming customer queries",
instructions="Analyze and categorize customer queries",
tools=[classify_query]
)
handler = Agent(
name="Query Handler",
role="Query Resolution",
goal="Handle customer queries appropriately",
instructions="Provide appropriate responses to queries",
tools=[handle_query]
)
evaluator = Agent(
name="Satisfaction Evaluator",
role="Satisfaction Assessment",
goal="Evaluate customer satisfaction",
instructions="Assess response effectiveness",
tools=[evaluate_satisfaction]
)
optimizer = Agent(
name="Response Optimizer",
role="Service Optimization",
goal="Optimize service based on feedback",
instructions="Improve response strategies",
tools=[optimize_response]
)
# Create workflow tasks
classification_task = Task(
name="classify_query",
description="Classify customer query",
expected_output="Query classification",
agent=classifier,
is_start=True,
task_type="decision",
condition={
"high": ["handle_query", "evaluate_satisfaction"],
"medium": ["handle_query", "evaluate_satisfaction"],
"low": ["handle_query"]
}
)
handling_task = Task(
name="handle_query",
description="Handle customer query",
expected_output="Query response",
agent=handler,
next_tasks=["evaluate_satisfaction"]
)
evaluation_task = Task(
name="evaluate_satisfaction",
description="Evaluate customer satisfaction",
expected_output="Satisfaction level",
agent=evaluator,
next_tasks=["optimize_response"]
)
optimization_task = Task(
name="optimize_response",
description="Optimize response strategy",
expected_output="Optimization recommendations",
agent=optimizer,
task_type="decision",
condition={
"major_revision": ["classify_query"],
"minor_adjustments": "",
"maintain_approach": ""
}
)
# Create workflow
workflow = PraisonAIAgents(
agents=[classifier, handler, evaluator, optimizer],
tasks=[classification_task, handling_task, evaluation_task, optimization_task],
process="workflow",
verbose=True
)
def main():
print("\nStarting Customer Service Optimization Workflow...")
print("=" * 50)
# Run workflow
results = workflow.start()
# Print results
print("\nCustomer Service Results:")
print("=" * 50)
for task_id, result in results["task_results"].items():
if result:
print(f"\nTask: {task_id}")
print(f"Result: {result.raw}")
print("-" * 50)
if __name__ == "__main__":
main()