conversimple-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,377 @@
1
+ Metadata-Version: 2.4
2
+ Name: conversimple-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for Conversimple Conversational AI Platform
5
+ Home-page: https://github.com/conversimple/conversimple-sdk
6
+ Author: Conversimple
7
+ Author-email: support@conversimple.com
8
+ Project-URL: Bug Tracker, https://github.com/conversimple/conversimple-sdk/issues
9
+ Project-URL: Documentation, https://docs.conversimple.com/sdk
10
+ Project-URL: Platform, https://platform.conversimple.com
11
+ Keywords: conversational ai,voice ai,chatbot,websocket,sdk,speech to text,text to speech
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
15
+ Classifier: Topic :: Communications :: Chat
16
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ Requires-Dist: websockets>=12.0
27
+ Requires-Dist: aiofiles>=23.0
28
+ Requires-Dist: aiohttp>=3.8.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0; extra == "dev"
31
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
32
+ Requires-Dist: black>=23.0; extra == "dev"
33
+ Requires-Dist: flake8>=6.0; extra == "dev"
34
+ Requires-Dist: mypy>=1.0; extra == "dev"
35
+ Provides-Extra: examples
36
+ Requires-Dist: aiofiles>=23.0; extra == "examples"
37
+ Requires-Dist: aiohttp>=3.8.0; extra == "examples"
38
+ Dynamic: author
39
+ Dynamic: author-email
40
+ Dynamic: classifier
41
+ Dynamic: description
42
+ Dynamic: description-content-type
43
+ Dynamic: home-page
44
+ Dynamic: keywords
45
+ Dynamic: project-url
46
+ Dynamic: provides-extra
47
+ Dynamic: requires-dist
48
+ Dynamic: requires-python
49
+ Dynamic: summary
50
+
51
+ # Conversimple SDK
52
+
53
+ Python client library for the Conversimple Conversational AI Platform.
54
+
55
+ This SDK enables customers to build and deploy AI agents that integrate with the Conversimple platform's WebRTC infrastructure and conversation management, providing real-time voice conversation capabilities with function calling support.
56
+
57
+ ## Features
58
+
59
+ - **Real-time Voice Conversations**: Integrate with WebRTC-based voice conversations
60
+ - **Function Calling**: Define tools that can be executed during conversations
61
+ - **Event-Driven Architecture**: React to conversation lifecycle events
62
+ - **Auto-Reconnection**: Fault-tolerant WebSocket connection with exponential backoff
63
+ - **Type Hints**: Full typing support for better development experience
64
+ - **Async/Await Support**: Both sync and async tool definitions
65
+
66
+ ## Quick Start
67
+
68
+ ### Installation
69
+
70
+ ```bash
71
+ pip install conversimple-sdk
72
+ ```
73
+
74
+ ### Basic Usage
75
+
76
+ ```python
77
+ import asyncio
78
+ from conversimple import ConversimpleAgent, tool
79
+
80
+ class MyAgent(ConversimpleAgent):
81
+ @tool("Get current weather for a location")
82
+ def get_weather(self, location: str) -> dict:
83
+ return {"location": location, "temperature": 72, "condition": "sunny"}
84
+
85
+ def on_conversation_started(self, conversation_id: str):
86
+ print(f"Conversation started: {conversation_id}")
87
+
88
+ async def main():
89
+ agent = MyAgent(
90
+ api_key="your-api-key",
91
+ customer_id="your-customer-id"
92
+ )
93
+
94
+ await agent.start()
95
+
96
+ # Keep running
97
+ while True:
98
+ await asyncio.sleep(1)
99
+
100
+ if __name__ == "__main__":
101
+ asyncio.run(main())
102
+ ```
103
+
104
+ ## Core Concepts
105
+
106
+ ### Agent Session Model
107
+
108
+ Each `ConversimpleAgent` instance handles a single conversation session. For multiple concurrent conversations, create multiple agent instances:
109
+
110
+ ```python
111
+ # Per-conversation agent instances
112
+ async def handle_conversation(conversation_id):
113
+ agent = MyAgent(api_key=api_key, customer_id=customer_id)
114
+ await agent.start(conversation_id=conversation_id)
115
+ ```
116
+
117
+ ### Tool Registration
118
+
119
+ Define tools using the `@tool` and `@tool_async` decorators:
120
+
121
+ ```python
122
+ from conversimple import tool, tool_async
123
+
124
+ class BusinessAgent(ConversimpleAgent):
125
+ @tool("Look up customer information")
126
+ def lookup_customer(self, customer_id: str) -> dict:
127
+ # Synchronous tool execution
128
+ return customer_database.get(customer_id)
129
+
130
+ @tool_async("Send email notification")
131
+ async def send_email(self, email: str, subject: str, body: str) -> dict:
132
+ # Asynchronous tool execution
133
+ result = await email_service.send(email, subject, body)
134
+ return {"sent": True, "message_id": result.id}
135
+ ```
136
+
137
+ ### Event Callbacks
138
+
139
+ Handle conversation lifecycle events:
140
+
141
+ ```python
142
+ class MyAgent(ConversimpleAgent):
143
+ def on_conversation_started(self, conversation_id: str):
144
+ print(f"🎤 Conversation started: {conversation_id}")
145
+
146
+ def on_conversation_ended(self, conversation_id: str):
147
+ print(f"📞 Conversation ended: {conversation_id}")
148
+
149
+ def on_tool_called(self, tool_call):
150
+ print(f"🔧 Executing tool: {tool_call.tool_name}")
151
+
152
+ def on_error(self, error_type: str, message: str, details: dict):
153
+ print(f"❌ Error ({error_type}): {message}")
154
+ ```
155
+
156
+ ## Configuration
157
+
158
+ ### Environment Variables
159
+
160
+ ```bash
161
+ export CONVERSIMPLE_API_KEY="your-api-key"
162
+ export CONVERSIMPLE_CUSTOMER_ID="your-customer-id"
163
+ export CONVERSIMPLE_PLATFORM_URL="ws://localhost:4000/sdk/websocket"
164
+ export CONVERSIMPLE_LOG_LEVEL="INFO"
165
+ ```
166
+
167
+ ### Programmatic Configuration
168
+
169
+ ```python
170
+ agent = ConversimpleAgent(
171
+ api_key="your-api-key",
172
+ customer_id="your-customer-id",
173
+ platform_url="wss://platform.conversimple.com/sdk/websocket"
174
+ )
175
+ ```
176
+
177
+ ## Examples
178
+
179
+ The SDK includes several example implementations:
180
+
181
+ ### Simple Weather Agent
182
+ ```bash
183
+ python examples/simple_agent.py
184
+ ```
185
+
186
+ A basic agent that provides weather information, demonstrating:
187
+ - Tool registration with `@tool` decorator
188
+ - Conversation lifecycle callbacks
189
+ - Basic agent structure
190
+
191
+ ### Customer Service Agent
192
+ ```bash
193
+ python examples/customer_service.py
194
+ ```
195
+
196
+ Advanced customer service agent with multiple tools:
197
+ - Customer lookup and account management
198
+ - Support ticket creation
199
+ - Email notifications
200
+ - Refund processing
201
+ - Async tool execution
202
+
203
+ ### Multi-Step Booking Agent
204
+ ```bash
205
+ python examples/booking_agent.py
206
+ ```
207
+
208
+ Complex booking workflow demonstrating:
209
+ - Multi-turn conversation state management
210
+ - Booking creation, confirmation, and cancellation
211
+ - Business rule validation
212
+ - Transaction-like processes
213
+
214
+ ## API Reference
215
+
216
+ ### ConversimpleAgent
217
+
218
+ Main agent class for platform integration.
219
+
220
+ #### Methods
221
+
222
+ - `__init__(api_key, customer_id=None, platform_url="ws://localhost:4000/sdk/websocket")`
223
+ - `async start(conversation_id=None)` - Start agent and connect to platform
224
+ - `async stop()` - Stop agent and disconnect
225
+ - `on_conversation_started(conversation_id)` - Conversation started callback
226
+ - `on_conversation_ended(conversation_id)` - Conversation ended callback
227
+ - `on_tool_called(tool_call)` - Tool execution callback
228
+ - `on_tool_completed(call_id, result)` - Tool completion callback
229
+ - `on_error(error_type, message, details)` - Error handling callback
230
+
231
+ ### Tool Decorators
232
+
233
+ #### @tool(description)
234
+ Register synchronous tool function.
235
+
236
+ ```python
237
+ @tool("Description of what this tool does")
238
+ def my_tool(self, param1: str, param2: int = 10) -> dict:
239
+ return {"result": "success"}
240
+ ```
241
+
242
+ #### @tool_async(description)
243
+ Register asynchronous tool function.
244
+
245
+ ```python
246
+ @tool_async("Description of async tool")
247
+ async def my_async_tool(self, param: str) -> dict:
248
+ await asyncio.sleep(0.1) # Async operation
249
+ return {"result": "success"}
250
+ ```
251
+
252
+ ### Type Hints
253
+
254
+ The SDK automatically generates JSON schemas from Python type hints:
255
+
256
+ - `str` → `"type": "string"`
257
+ - `int` → `"type": "integer"`
258
+ - `float` → `"type": "number"`
259
+ - `bool` → `"type": "boolean"`
260
+ - `list` → `"type": "array"`
261
+ - `dict` → `"type": "object"`
262
+ - `Optional[T]` → Same as T (nullable)
263
+
264
+ ## Protocol Details
265
+
266
+ ### WebSocket Messages
267
+
268
+ The SDK communicates with the platform using these message types:
269
+
270
+ #### Outgoing (SDK → Platform)
271
+ - `register_conversation_tools` - Register available tools
272
+ - `tool_call_response` - Tool execution results
273
+ - `tool_call_error` - Tool execution failures
274
+ - `heartbeat` - Connection keepalive
275
+
276
+ #### Incoming (Platform → SDK)
277
+ - `tool_call_request` - Tool execution requests
278
+ - `conversation_lifecycle` - Conversation started/ended
279
+ - `config_update` - Configuration updates
280
+ - `analytics_update` - Usage analytics
281
+
282
+ ### Message Format
283
+
284
+ Tool registration:
285
+ ```json
286
+ {
287
+ "conversation_id": "conv_123",
288
+ "tools": [
289
+ {
290
+ "name": "get_weather",
291
+ "description": "Get weather for location",
292
+ "parameters": {
293
+ "type": "object",
294
+ "properties": {
295
+ "location": {"type": "string"}
296
+ },
297
+ "required": ["location"]
298
+ }
299
+ }
300
+ ]
301
+ }
302
+ ```
303
+
304
+ Tool execution:
305
+ ```json
306
+ {
307
+ "call_id": "call_abc123",
308
+ "result": {"temperature": 22, "condition": "sunny"}
309
+ }
310
+ ```
311
+
312
+ ## Error Handling
313
+
314
+ The SDK provides comprehensive error handling:
315
+
316
+ ### Connection Errors
317
+ - Automatic reconnection with exponential backoff
318
+ - Configurable retry attempts and timeouts
319
+ - Connection state monitoring
320
+
321
+ ### Tool Execution Errors
322
+ - Automatic error reporting to platform
323
+ - Exception wrapping and formatting
324
+ - Timeout handling
325
+
326
+ ### Logging
327
+ ```python
328
+ import logging
329
+
330
+ # Configure SDK logging
331
+ logging.basicConfig(level=logging.INFO)
332
+ logger = logging.getLogger("conversimple")
333
+ ```
334
+
335
+ ## Development
336
+
337
+ ### Setup Development Environment
338
+
339
+ ```bash
340
+ git clone https://github.com/conversimple/conversimple-sdk
341
+ cd conversimple-sdk
342
+
343
+ # Create virtual environment
344
+ python -m venv venv
345
+ source venv/bin/activate # On Windows: venv\Scripts\activate
346
+
347
+ # Install dependencies
348
+ pip install -r requirements.txt -r requirements-dev.txt
349
+
350
+ # Install in editable mode
351
+ pip install -e .
352
+ ```
353
+
354
+ ### Running Tests
355
+
356
+ ```bash
357
+ pytest tests/
358
+ ```
359
+
360
+ ### Code Formatting
361
+
362
+ ```bash
363
+ black conversimple/
364
+ flake8 conversimple/
365
+ mypy conversimple/
366
+ ```
367
+
368
+ ## License
369
+
370
+ This project is licensed under the MIT License - see the LICENSE file for details.
371
+
372
+ ## Support
373
+
374
+ - **Documentation**: https://docs.conversimple.com/sdk
375
+ - **GitHub Issues**: https://github.com/conversimple/conversimple-sdk/issues
376
+ - **Email Support**: support@conversimple.com
377
+ - **Community**: https://community.conversimple.com
@@ -0,0 +1,327 @@
1
+ # Conversimple SDK
2
+
3
+ Python client library for the Conversimple Conversational AI Platform.
4
+
5
+ This SDK enables customers to build and deploy AI agents that integrate with the Conversimple platform's WebRTC infrastructure and conversation management, providing real-time voice conversation capabilities with function calling support.
6
+
7
+ ## Features
8
+
9
+ - **Real-time Voice Conversations**: Integrate with WebRTC-based voice conversations
10
+ - **Function Calling**: Define tools that can be executed during conversations
11
+ - **Event-Driven Architecture**: React to conversation lifecycle events
12
+ - **Auto-Reconnection**: Fault-tolerant WebSocket connection with exponential backoff
13
+ - **Type Hints**: Full typing support for better development experience
14
+ - **Async/Await Support**: Both sync and async tool definitions
15
+
16
+ ## Quick Start
17
+
18
+ ### Installation
19
+
20
+ ```bash
21
+ pip install conversimple-sdk
22
+ ```
23
+
24
+ ### Basic Usage
25
+
26
+ ```python
27
+ import asyncio
28
+ from conversimple import ConversimpleAgent, tool
29
+
30
+ class MyAgent(ConversimpleAgent):
31
+ @tool("Get current weather for a location")
32
+ def get_weather(self, location: str) -> dict:
33
+ return {"location": location, "temperature": 72, "condition": "sunny"}
34
+
35
+ def on_conversation_started(self, conversation_id: str):
36
+ print(f"Conversation started: {conversation_id}")
37
+
38
+ async def main():
39
+ agent = MyAgent(
40
+ api_key="your-api-key",
41
+ customer_id="your-customer-id"
42
+ )
43
+
44
+ await agent.start()
45
+
46
+ # Keep running
47
+ while True:
48
+ await asyncio.sleep(1)
49
+
50
+ if __name__ == "__main__":
51
+ asyncio.run(main())
52
+ ```
53
+
54
+ ## Core Concepts
55
+
56
+ ### Agent Session Model
57
+
58
+ Each `ConversimpleAgent` instance handles a single conversation session. For multiple concurrent conversations, create multiple agent instances:
59
+
60
+ ```python
61
+ # Per-conversation agent instances
62
+ async def handle_conversation(conversation_id):
63
+ agent = MyAgent(api_key=api_key, customer_id=customer_id)
64
+ await agent.start(conversation_id=conversation_id)
65
+ ```
66
+
67
+ ### Tool Registration
68
+
69
+ Define tools using the `@tool` and `@tool_async` decorators:
70
+
71
+ ```python
72
+ from conversimple import tool, tool_async
73
+
74
+ class BusinessAgent(ConversimpleAgent):
75
+ @tool("Look up customer information")
76
+ def lookup_customer(self, customer_id: str) -> dict:
77
+ # Synchronous tool execution
78
+ return customer_database.get(customer_id)
79
+
80
+ @tool_async("Send email notification")
81
+ async def send_email(self, email: str, subject: str, body: str) -> dict:
82
+ # Asynchronous tool execution
83
+ result = await email_service.send(email, subject, body)
84
+ return {"sent": True, "message_id": result.id}
85
+ ```
86
+
87
+ ### Event Callbacks
88
+
89
+ Handle conversation lifecycle events:
90
+
91
+ ```python
92
+ class MyAgent(ConversimpleAgent):
93
+ def on_conversation_started(self, conversation_id: str):
94
+ print(f"🎤 Conversation started: {conversation_id}")
95
+
96
+ def on_conversation_ended(self, conversation_id: str):
97
+ print(f"📞 Conversation ended: {conversation_id}")
98
+
99
+ def on_tool_called(self, tool_call):
100
+ print(f"🔧 Executing tool: {tool_call.tool_name}")
101
+
102
+ def on_error(self, error_type: str, message: str, details: dict):
103
+ print(f"❌ Error ({error_type}): {message}")
104
+ ```
105
+
106
+ ## Configuration
107
+
108
+ ### Environment Variables
109
+
110
+ ```bash
111
+ export CONVERSIMPLE_API_KEY="your-api-key"
112
+ export CONVERSIMPLE_CUSTOMER_ID="your-customer-id"
113
+ export CONVERSIMPLE_PLATFORM_URL="ws://localhost:4000/sdk/websocket"
114
+ export CONVERSIMPLE_LOG_LEVEL="INFO"
115
+ ```
116
+
117
+ ### Programmatic Configuration
118
+
119
+ ```python
120
+ agent = ConversimpleAgent(
121
+ api_key="your-api-key",
122
+ customer_id="your-customer-id",
123
+ platform_url="wss://platform.conversimple.com/sdk/websocket"
124
+ )
125
+ ```
126
+
127
+ ## Examples
128
+
129
+ The SDK includes several example implementations:
130
+
131
+ ### Simple Weather Agent
132
+ ```bash
133
+ python examples/simple_agent.py
134
+ ```
135
+
136
+ A basic agent that provides weather information, demonstrating:
137
+ - Tool registration with `@tool` decorator
138
+ - Conversation lifecycle callbacks
139
+ - Basic agent structure
140
+
141
+ ### Customer Service Agent
142
+ ```bash
143
+ python examples/customer_service.py
144
+ ```
145
+
146
+ Advanced customer service agent with multiple tools:
147
+ - Customer lookup and account management
148
+ - Support ticket creation
149
+ - Email notifications
150
+ - Refund processing
151
+ - Async tool execution
152
+
153
+ ### Multi-Step Booking Agent
154
+ ```bash
155
+ python examples/booking_agent.py
156
+ ```
157
+
158
+ Complex booking workflow demonstrating:
159
+ - Multi-turn conversation state management
160
+ - Booking creation, confirmation, and cancellation
161
+ - Business rule validation
162
+ - Transaction-like processes
163
+
164
+ ## API Reference
165
+
166
+ ### ConversimpleAgent
167
+
168
+ Main agent class for platform integration.
169
+
170
+ #### Methods
171
+
172
+ - `__init__(api_key, customer_id=None, platform_url="ws://localhost:4000/sdk/websocket")`
173
+ - `async start(conversation_id=None)` - Start agent and connect to platform
174
+ - `async stop()` - Stop agent and disconnect
175
+ - `on_conversation_started(conversation_id)` - Conversation started callback
176
+ - `on_conversation_ended(conversation_id)` - Conversation ended callback
177
+ - `on_tool_called(tool_call)` - Tool execution callback
178
+ - `on_tool_completed(call_id, result)` - Tool completion callback
179
+ - `on_error(error_type, message, details)` - Error handling callback
180
+
181
+ ### Tool Decorators
182
+
183
+ #### @tool(description)
184
+ Register synchronous tool function.
185
+
186
+ ```python
187
+ @tool("Description of what this tool does")
188
+ def my_tool(self, param1: str, param2: int = 10) -> dict:
189
+ return {"result": "success"}
190
+ ```
191
+
192
+ #### @tool_async(description)
193
+ Register asynchronous tool function.
194
+
195
+ ```python
196
+ @tool_async("Description of async tool")
197
+ async def my_async_tool(self, param: str) -> dict:
198
+ await asyncio.sleep(0.1) # Async operation
199
+ return {"result": "success"}
200
+ ```
201
+
202
+ ### Type Hints
203
+
204
+ The SDK automatically generates JSON schemas from Python type hints:
205
+
206
+ - `str` → `"type": "string"`
207
+ - `int` → `"type": "integer"`
208
+ - `float` → `"type": "number"`
209
+ - `bool` → `"type": "boolean"`
210
+ - `list` → `"type": "array"`
211
+ - `dict` → `"type": "object"`
212
+ - `Optional[T]` → Same as T (nullable)
213
+
214
+ ## Protocol Details
215
+
216
+ ### WebSocket Messages
217
+
218
+ The SDK communicates with the platform using these message types:
219
+
220
+ #### Outgoing (SDK → Platform)
221
+ - `register_conversation_tools` - Register available tools
222
+ - `tool_call_response` - Tool execution results
223
+ - `tool_call_error` - Tool execution failures
224
+ - `heartbeat` - Connection keepalive
225
+
226
+ #### Incoming (Platform → SDK)
227
+ - `tool_call_request` - Tool execution requests
228
+ - `conversation_lifecycle` - Conversation started/ended
229
+ - `config_update` - Configuration updates
230
+ - `analytics_update` - Usage analytics
231
+
232
+ ### Message Format
233
+
234
+ Tool registration:
235
+ ```json
236
+ {
237
+ "conversation_id": "conv_123",
238
+ "tools": [
239
+ {
240
+ "name": "get_weather",
241
+ "description": "Get weather for location",
242
+ "parameters": {
243
+ "type": "object",
244
+ "properties": {
245
+ "location": {"type": "string"}
246
+ },
247
+ "required": ["location"]
248
+ }
249
+ }
250
+ ]
251
+ }
252
+ ```
253
+
254
+ Tool execution:
255
+ ```json
256
+ {
257
+ "call_id": "call_abc123",
258
+ "result": {"temperature": 22, "condition": "sunny"}
259
+ }
260
+ ```
261
+
262
+ ## Error Handling
263
+
264
+ The SDK provides comprehensive error handling:
265
+
266
+ ### Connection Errors
267
+ - Automatic reconnection with exponential backoff
268
+ - Configurable retry attempts and timeouts
269
+ - Connection state monitoring
270
+
271
+ ### Tool Execution Errors
272
+ - Automatic error reporting to platform
273
+ - Exception wrapping and formatting
274
+ - Timeout handling
275
+
276
+ ### Logging
277
+ ```python
278
+ import logging
279
+
280
+ # Configure SDK logging
281
+ logging.basicConfig(level=logging.INFO)
282
+ logger = logging.getLogger("conversimple")
283
+ ```
284
+
285
+ ## Development
286
+
287
+ ### Setup Development Environment
288
+
289
+ ```bash
290
+ git clone https://github.com/conversimple/conversimple-sdk
291
+ cd conversimple-sdk
292
+
293
+ # Create virtual environment
294
+ python -m venv venv
295
+ source venv/bin/activate # On Windows: venv\Scripts\activate
296
+
297
+ # Install dependencies
298
+ pip install -r requirements.txt -r requirements-dev.txt
299
+
300
+ # Install in editable mode
301
+ pip install -e .
302
+ ```
303
+
304
+ ### Running Tests
305
+
306
+ ```bash
307
+ pytest tests/
308
+ ```
309
+
310
+ ### Code Formatting
311
+
312
+ ```bash
313
+ black conversimple/
314
+ flake8 conversimple/
315
+ mypy conversimple/
316
+ ```
317
+
318
+ ## License
319
+
320
+ This project is licensed under the MIT License - see the LICENSE file for details.
321
+
322
+ ## Support
323
+
324
+ - **Documentation**: https://docs.conversimple.com/sdk
325
+ - **GitHub Issues**: https://github.com/conversimple/conversimple-sdk/issues
326
+ - **Email Support**: support@conversimple.com
327
+ - **Community**: https://community.conversimple.com