-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_usage.py
More file actions
219 lines (166 loc) · 6.63 KB
/
example_usage.py
File metadata and controls
219 lines (166 loc) · 6.63 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
"""
Example usage of the Python AgentForce framework.
This demonstrates how to use the agents similar to the Ruby implementation.
"""
from conversation_manager import (
IntentAgent,
NewAppointmentAgent,
EscalationHandoffAgent,
GenerateSummaryAgent,
OpportunityScoringAgent
)
from call_agents import SummarizerAgent
def example_intent_agent():
"""Example of using the IntentAgent."""
print("=== Intent Agent Example ===")
# Create agent instance
agent = IntentAgent()
# Format instructions with account data
instructions = agent.format_instructions(
account_friendly_name="ABC Home Services",
account_services="plumbing, HVAC, electrical"
)
print("Instructions formatted with account data:")
print(instructions[:200] + "...")
# Example conversation data
class MockConversation:
def __init__(self):
self.messages = [
MockMessage("Hi, my water heater is leaking!")
]
class MockMessage:
def __init__(self, content):
self.content = content
conversation = MockConversation()
# Process input
processed_input = agent.process_input(conversation)
print(f"\nProcessed input: {processed_input}")
# Get agent schema
schema = agent.schema()
print(f"\nAgent schema: {schema}")
# Get tool schemas
tool_schemas = agent.tool_schema()
print(f"\nTool schemas count: {len(tool_schemas)}")
def example_new_appointment_agent():
"""Example of using the NewAppointmentAgent."""
print("\n=== New Appointment Agent Example ===")
# Create agent instance
agent = NewAppointmentAgent()
# Format instructions with account data
instructions = agent.format_instructions(
account_friendly_name="ABC Home Services",
account_services="plumbing, HVAC, electrical",
account_full_address="123 Main St, City, State 12345",
account_phone="(555) 123-4567",
account_time_zone="America/New_York",
customer_information='{"full_name": "John Doe", "phone_number": "555-123-4567"}',
current_time="2024-01-15T10:30:00Z"
)
print("Instructions formatted with account data:")
print(instructions[:200] + "...")
# Get tool schemas
tool_schemas = agent.tool_schema()
print(f"\nTool schemas count: {len(tool_schemas)}")
# Example customer data
class MockConversation:
def __init__(self):
self.customer_used_contacts = []
self.initiator_channel = {'account': {}}
self.customer = {'full_name': 'John Doe', 'primary_phone_number': '555-123-4567', 'primary_email_address': 'john@example.com', 'locations': []}
customer_data = agent.build_initial_data(MockConversation())
print(f"\nCustomer data: {customer_data}")
def example_escalation_handoff_agent():
"""Example of using the EscalationHandoffAgent."""
print("\n=== Escalation Handoff Agent Example ===")
# Create agent instance
agent = EscalationHandoffAgent()
# Format instructions with account data
instructions = agent.format_instructions(
account_friendly_name="ABC Home Services",
account_full_address="123 Main St, City, State 12345",
account_phone="(555) 123-4567",
account_services="plumbing, HVAC, electrical",
account_time_zone="America/New_York",
current_time="2024-01-15T10:30:00Z",
customer_information='{"full_name": "John Doe", "phone_number": "555-123-4567"}'
)
print("Instructions formatted with account data:")
print(instructions[:200] + "...")
# Get tool schemas
tool_schemas = agent.tool_schema()
print(f"\nTool schemas count: {len(tool_schemas)}")
def example_summary_agent():
"""Example of using the GenerateSummaryAgent."""
print("\n=== Generate Summary Agent Example ===")
# Create agent instance
agent = GenerateSummaryAgent()
# Example conversation data
class MockConversation:
def __init__(self):
self.messages = [
MockMessage("Hi, I need help with my AC", True),
MockMessage("I'd be happy to help! What's the issue?", False),
MockMessage("It's not cooling properly", True)
]
self.calls = []
class MockMessage:
def __init__(self, content, role_lead=False):
self.content = content
self.role_lead = role_lead
self.created_at = 0
conversation = MockConversation()
# Process input
processed_input = agent.process_input(conversation)
print(f"Processed input: {processed_input}")
def example_opportunity_scoring_agent():
"""Example of using the OpportunityScoringAgent."""
print("\n=== Opportunity Scoring Agent Example ===")
# Create agent instance
agent = OpportunityScoringAgent()
# Example opportunity data
class MockOpportunity:
def __init__(self):
self.qualification_questions = [
"What type of service do you need?",
"What's the urgency level?",
"Are you an existing customer?"
]
opportunity = MockOpportunity()
# Process input
processed_input = agent.process_input(opportunity)
print(f"Processed input: {processed_input}")
# Get agent schema
schema = agent.schema()
print(f"\nAgent schema: {schema}")
def example_call_summarizer_agent():
"""Example of using the SummarizerAgent."""
print("\n=== Call Summarizer Agent Example ===")
# Create agent instance
agent = SummarizerAgent()
# Example call data
class MockCall:
def __init__(self):
self.transcription = "Customer: Hi, my water heater is leaking. Agent: I understand, let me help you with that. Customer: It's been going on for a few days now."
call = MockCall()
# Process input
processed_input = agent.process_input(call)
print(f"Processed input: {processed_input}")
def main():
"""Run all examples."""
print("Python AgentForce Framework - Example Usage")
print("=" * 50)
try:
example_intent_agent()
example_new_appointment_agent()
example_escalation_handoff_agent()
example_summary_agent()
example_opportunity_scoring_agent()
example_call_summarizer_agent()
print("\n" + "=" * 50)
print("All examples completed successfully!")
except Exception as e:
print(f"\nError running examples: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
main()