-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatasphere_multi_instance_demo.py
More file actions
189 lines (166 loc) · 7.28 KB
/
Copy pathdatasphere_multi_instance_demo.py
File metadata and controls
189 lines (166 loc) · 7.28 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
#!/usr/bin/env python3
"""
Copyright (c) 2025 SignalWire
This file is part of the SignalWire SDK.
Licensed under the MIT License.
See LICENSE file in the project root for full license information.
"""
"""
DataSphere Multiple Instance Demo
This example demonstrates the new DataSphere skill with multiple instance support.
You can load the same skill multiple times with different configurations and tool names.
Features demonstrated:
- Multiple instances of the same skill (datasphere)
- Custom tool names for each instance
- Different configurations per instance
- Custom no_results_message per instance
To use this demo, you'll need:
- SignalWire DataSphere setup with documents
- Valid space_name, project_id, token, and document_id values
"""
import os
from signalwire import AgentBase
def main():
# Create an agent
agent = AgentBase("Multi-DataSphere Assistant", route="/datasphere-demo")
# Configure the agent with inworld.Mark voice
agent.add_language("English", "en-US", "inworld.Mark")
print("Creating agent with multiple DataSphere skill instances...")
# Add datetime and math skills for basic functionality
try:
agent.add_skill("datetime")
print("Added datetime skill")
except Exception as e:
print(f"Failed to add datetime skill: {e}")
try:
agent.add_skill("math")
print("Added math skill")
except Exception as e:
print(f"Failed to add math skill: {e}")
# Example configuration - replace with your actual DataSphere details
example_config = {
'space_name': 'your-space',
'project_id': 'your-project-id',
'token': 'your-token'
}
# Instance 1: Drinks knowledge base
try:
agent.add_skill("datasphere", {
**example_config,
"document_id": "drinks-doc-123",
"tool_name": "search_drinks_knowledge",
"tags": ["Drinks", "Bar", "Cocktails"],
"count": 2,
"distance": 5.0,
"no_results_message": "I couldn't find any drink recipes or information about '{query}'. Try asking about a different cocktail or beverage.",
"swaig_fields": {
"fillers": {
"en-US": [
"Let me check our drink recipes...",
"Searching our cocktail database...",
"Looking up drink information..."
]
}
}
})
print("Added drinks knowledge search (tool: search_drinks_knowledge)")
except Exception as e:
print(f"Failed to add drinks DataSphere skill: {e}")
print(" Note: Replace example_config with your actual DataSphere credentials")
# Instance 2: Food knowledge base
try:
agent.add_skill("datasphere", {
**example_config,
"document_id": "food-doc-456",
"tool_name": "search_food_knowledge",
"tags": ["Food", "Recipes", "Cooking"],
"count": 3,
"distance": 4.0,
"language": "en",
"no_results_message": "I couldn't find any recipes or cooking information about '{query}'. Try asking about a different dish or ingredient.",
"swaig_fields": {
"fillers": {
"en-US": [
"Checking our recipe collection...",
"Searching cooking instructions...",
"Looking through our food database..."
]
}
}
})
print("Added food knowledge search (tool: search_food_knowledge)")
except Exception as e:
print(f"Failed to add food DataSphere skill: {e}")
print(" Note: Replace example_config with your actual DataSphere credentials")
# Instance 3: General knowledge base with default tool name
try:
agent.add_skill("datasphere", {
**example_config,
"document_id": "general-doc-789",
# No tool_name specified, so it will use default "search_knowledge"
"count": 1,
"distance": 3.0,
"no_results_message": "I couldn't find information about '{query}' in our general knowledge base. Please try rephrasing your question."
})
print("Added general knowledge search (tool: search_knowledge - default)")
except Exception as e:
print(f"Failed to add general DataSphere skill: {e}")
print(" Note: Replace example_config with your actual DataSphere credentials")
# Show what skills/instances are loaded
loaded_skills = agent.list_skills()
print(f"\nLoaded skill instances: {', '.join(loaded_skills)}")
# Show available skills from registry
try:
from signalwire.skills.registry import skill_registry
available_skills = skill_registry.list_skills()
print(f"\nAvailable skills in registry:")
for skill in available_skills:
print(f" - {skill['name']}: {skill['description']}")
if skill['name'] == 'datasphere':
print(f" Supports multiple instances: Yes")
else:
print(f" Supports multiple instances: No")
except Exception as e:
print(f"Failed to list available skills: {e}")
print(f"\nAgent available at: {agent.get_full_url()}")
print("The agent now has enhanced capabilities:")
print(" - Can tell current date/time")
print(" - Can perform mathematical calculations")
# Count how many DataSphere instances we have
datasphere_instances = [skill for skill in loaded_skills if skill.startswith('datasphere_')]
if datasphere_instances:
print(f" - Has {len(datasphere_instances)} knowledge search capabilities:")
for instance in datasphere_instances:
tool_name = instance.split('_', 1)[1] if '_' in instance else 'search_knowledge'
print(f" * {tool_name}")
print("\nDataSphere Multiple Instance Examples:")
print(" # Basic usage with default tool name")
print(" agent.add_skill('datasphere', {")
print(" 'space_name': 'my-space',")
print(" 'project_id': 'my-project',")
print(" 'token': 'my-token',")
print(" 'document_id': 'my-doc-id'")
print(" })")
print(" # Creates tool: search_knowledge")
print(" ")
print(" # Custom tool name for drinks knowledge")
print(" agent.add_skill('datasphere', {")
print(" 'space_name': 'my-space',")
print(" 'project_id': 'my-project',")
print(" 'token': 'my-token',")
print(" 'document_id': 'drinks-doc',")
print(" 'tool_name': 'search_drinks',")
print(" 'tags': ['Drinks', 'Cocktails'],")
print(" 'count': 3")
print(" })")
print(" # Creates tool: search_drinks")
print(" ")
print(" # Multiple instances with different configurations")
print(" agent.add_skill('datasphere', {..., 'tool_name': 'search_products'})")
print(" agent.add_skill('datasphere', {..., 'tool_name': 'search_support'})")
print(" agent.add_skill('datasphere', {..., 'tool_name': 'search_policies'})")
print("\nStarting agent server...")
print("Note: Works in any deployment mode (server/CGI/Lambda)")
agent.run()
if __name__ == "__main__":
main()