-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_dynamic_agent.php
More file actions
82 lines (70 loc) · 2.57 KB
/
Copy pathsimple_dynamic_agent.php
File metadata and controls
82 lines (70 loc) · 2.57 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
<?php
/**
* Simple Dynamic Agent Example
*
* This agent is configured dynamically per-request using a callback.
* The configuration happens fresh for each incoming request, allowing
* parameter-based customization (VIP routing, tenant isolation, etc.).
*/
require 'vendor/autoload.php';
use SignalWire\Agent\AgentBase;
$agent = new AgentBase(
name: 'Simple Customer Service Agent (Dynamic)',
autoAnswer: true,
recordCall: true,
);
// Set up a dynamic configuration callback instead of static config
$agent->setDynamicConfigCallback(function ($queryParams, $bodyParams, $headers, $agentClone) {
// Voice and language
$agentClone->addLanguage(name: 'English', code: 'en-US', voice: 'inworld.Mark');
// AI parameters
$agentClone->setParams([
'ai_model' => 'gpt-4.1-nano',
'end_of_speech_timeout' => 500,
'attention_timeout' => 15000,
'background_file_volume' => -20,
]);
// Hints for speech recognition
$agentClone->addHints(['SignalWire', 'SWML', 'API', 'webhook', 'SIP']);
// Global data
$agentClone->setGlobalData([
'agent_type' => 'customer_service',
'service_level' => 'standard',
'features_enabled' => ['basic_conversation', 'help_desk'],
'session_info' => [
'environment' => 'production',
'version' => '1.0',
],
]);
// Prompt sections
$agentClone->promptAddSection(
'Role and Purpose',
'You are a professional customer service representative. Your goal is to help '
. 'customers with their questions and provide excellent service.',
);
$agentClone->promptAddSection(
'Guidelines',
'Follow these customer service principles:',
bullets: [
'Listen carefully to customer needs',
'Provide accurate and helpful information',
'Maintain a professional and friendly tone',
'Escalate complex issues when appropriate',
'Always confirm understanding before ending',
],
);
$agentClone->promptAddSection(
'Available Services',
'You can help customers with:',
bullets: [
'General product information',
'Account questions and support',
'Technical troubleshooting guidance',
'Billing and payment inquiries',
'Service status and updates',
],
);
});
echo "Starting Simple Dynamic Agent -- configuration changes based on requests\n";
echo "Available at: http://localhost:3000/\n";
$agent->run();