mbxai 2.1.3__tar.gz → 2.2.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.
- mbxai-2.2.0/PKG-INFO +492 -0
- mbxai-2.2.0/README.md +457 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/pyproject.toml +1 -1
- {mbxai-2.1.3 → mbxai-2.2.0}/setup.py +1 -1
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/__init__.py +1 -1
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/mcp/server.py +1 -1
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/openrouter/client.py +1 -83
- mbxai-2.1.3/PKG-INFO +0 -346
- mbxai-2.1.3/README.md +0 -311
- {mbxai-2.1.3 → mbxai-2.2.0}/.gitignore +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/LICENSE +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/agent/__init__.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/agent/client.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/agent/models.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/core.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/agent_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/agent_iterations_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/agent_logging_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/agent_tool_registration_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/agent_validation_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/auto_schema_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/conversation_history_test.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/dialog_agent_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/mcp/mcp_client_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/mcp/mcp_server_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/openrouter_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/optional_prompt_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/parse_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/parse_tool_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/request.json +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/response.json +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/send_request.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/simple_agent_test.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/tool_client_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/examples/unified_interface_example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/mcp/__init__.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/mcp/client.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/mcp/example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/openrouter/__init__.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/openrouter/config.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/openrouter/models.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/openrouter/schema.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/tools/__init__.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/tools/client.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/tools/example.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/src/mbxai/tools/types.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/tests/test_mcp_tool_registration.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/tests/test_real_mcp_schema.py +0 -0
- {mbxai-2.1.3 → mbxai-2.2.0}/tests/test_schema_conversion.py +0 -0
mbxai-2.2.0/PKG-INFO
ADDED
@@ -0,0 +1,492 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: mbxai
|
3
|
+
Version: 2.2.0
|
4
|
+
Summary: MBX AI SDK
|
5
|
+
Project-URL: Homepage, https://www.mibexx.de
|
6
|
+
Project-URL: Documentation, https://www.mibexx.de
|
7
|
+
Project-URL: Repository, https://github.com/yourusername/mbxai.git
|
8
|
+
Author: MBX AI
|
9
|
+
License: MIT
|
10
|
+
License-File: LICENSE
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
12
|
+
Classifier: Operating System :: OS Independent
|
13
|
+
Classifier: Programming Language :: Python
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
15
|
+
Requires-Python: >=3.12
|
16
|
+
Requires-Dist: fastapi>=0.115.12
|
17
|
+
Requires-Dist: httpx>=0.27.0
|
18
|
+
Requires-Dist: mcp>=1.7.1
|
19
|
+
Requires-Dist: openai>=1.77.0
|
20
|
+
Requires-Dist: pydantic-settings>=2.9.1
|
21
|
+
Requires-Dist: pydantic>=2.9.1
|
22
|
+
Requires-Dist: python-multipart>=0.0.20
|
23
|
+
Requires-Dist: sse-starlette>=2.3.4
|
24
|
+
Requires-Dist: starlette>=0.46.2
|
25
|
+
Requires-Dist: typing-inspection<=0.4.0
|
26
|
+
Requires-Dist: uvicorn>=0.34.2
|
27
|
+
Provides-Extra: dev
|
28
|
+
Requires-Dist: black>=24.3.0; extra == 'dev'
|
29
|
+
Requires-Dist: isort>=5.13.2; extra == 'dev'
|
30
|
+
Requires-Dist: mypy>=1.8.0; extra == 'dev'
|
31
|
+
Requires-Dist: pytest-asyncio>=0.26.0; extra == 'dev'
|
32
|
+
Requires-Dist: pytest-cov>=6.1.1; extra == 'dev'
|
33
|
+
Requires-Dist: pytest>=8.3.5; extra == 'dev'
|
34
|
+
Description-Content-Type: text/markdown
|
35
|
+
|
36
|
+
# MBX AI
|
37
|
+
|
38
|
+
A comprehensive Python library for building intelligent AI applications with Large Language Models (LLMs), structured responses, tool integration, and agent-based thinking.
|
39
|
+
|
40
|
+
## 🚀 Features
|
41
|
+
|
42
|
+
- **🔗 Multiple AI Client Types**: OpenRouter integration with tool-enabled and MCP-enabled variants
|
43
|
+
- **🤖 Intelligent Agent System**: Dialog-based thinking with question generation, quality iteration, and conversation memory
|
44
|
+
- **🛠️ Tool Integration**: Easy function registration with automatic schema generation
|
45
|
+
- **🔌 MCP Support**: Full Model Context Protocol (MCP) client and server implementation
|
46
|
+
- **📋 Structured Responses**: Type-safe responses using Pydantic models
|
47
|
+
- **🔄 Quality Iteration**: Built-in response improvement through AI-powered quality checks
|
48
|
+
- **💬 Conversation Memory**: Persistent dialog sessions with history management
|
49
|
+
- **⚡ Automatic Retry**: Built-in retry logic with exponential backoff for robust connections
|
50
|
+
|
51
|
+
## 📦 Installation
|
52
|
+
|
53
|
+
```bash
|
54
|
+
pip install mbxai
|
55
|
+
```
|
56
|
+
|
57
|
+
## 🏗️ Architecture Overview
|
58
|
+
|
59
|
+
MBX AI provides four main client types, each building upon the previous:
|
60
|
+
|
61
|
+
1. **OpenRouterClient** - Basic LLM interactions with structured responses
|
62
|
+
2. **ToolClient** - Adds function calling capabilities
|
63
|
+
3. **MCPClient** - Adds Model Context Protocol server integration
|
64
|
+
4. **AgentClient** - Adds intelligent dialog-based thinking (wraps any of the above)
|
65
|
+
|
66
|
+
| Client | Structured Responses | Function Calling | MCP Integration | Agent Thinking |
|
67
|
+
|--------|---------------------|------------------|-----------------|----------------|
|
68
|
+
| OpenRouterClient | ✅ | ❌ | ❌ | ❌ |
|
69
|
+
| ToolClient | ✅ | ✅ | ❌ | ❌ |
|
70
|
+
| MCPClient | ✅ | ✅ | ✅ | ❌ |
|
71
|
+
| AgentClient | ✅ | ✅* | ✅* | ✅ |
|
72
|
+
|
73
|
+
*AgentClient capabilities depend on the wrapped client
|
74
|
+
|
75
|
+
## 🚀 Quick Start
|
76
|
+
|
77
|
+
### Basic OpenRouter Client
|
78
|
+
|
79
|
+
```python
|
80
|
+
import os
|
81
|
+
from mbxai import OpenRouterClient
|
82
|
+
from pydantic import BaseModel, Field
|
83
|
+
|
84
|
+
# Initialize client
|
85
|
+
client = OpenRouterClient(token=os.getenv("OPENROUTER_API_KEY"))
|
86
|
+
|
87
|
+
# Simple chat
|
88
|
+
response = client.create([
|
89
|
+
{"role": "user", "content": "What is the capital of France?"}
|
90
|
+
])
|
91
|
+
print(response.choices[0].message.content)
|
92
|
+
|
93
|
+
# Structured response
|
94
|
+
class CityInfo(BaseModel):
|
95
|
+
name: str = Field(description="City name")
|
96
|
+
population: int = Field(description="Population count")
|
97
|
+
country: str = Field(description="Country name")
|
98
|
+
|
99
|
+
response = client.parse(
|
100
|
+
messages=[{"role": "user", "content": "Tell me about Paris"}],
|
101
|
+
response_format=CityInfo
|
102
|
+
)
|
103
|
+
city = response.choices[0].message.parsed
|
104
|
+
print(f"{city.name}, {city.country} - Population: {city.population:,}")
|
105
|
+
```
|
106
|
+
|
107
|
+
### Tool Client with Automatic Schema Generation
|
108
|
+
|
109
|
+
```python
|
110
|
+
import os
|
111
|
+
from mbxai import ToolClient, OpenRouterClient
|
112
|
+
|
113
|
+
# Initialize clients
|
114
|
+
openrouter_client = OpenRouterClient(token=os.getenv("OPENROUTER_API_KEY"))
|
115
|
+
tool_client = ToolClient(openrouter_client)
|
116
|
+
|
117
|
+
# Define a function - schema is auto-generated!
|
118
|
+
def get_weather(location: str, unit: str = "celsius") -> dict:
|
119
|
+
"""Get weather information for a location.
|
120
|
+
|
121
|
+
Args:
|
122
|
+
location: The city or location name
|
123
|
+
unit: Temperature unit (celsius or fahrenheit)
|
124
|
+
"""
|
125
|
+
return {
|
126
|
+
"location": location,
|
127
|
+
"temperature": 22,
|
128
|
+
"unit": unit,
|
129
|
+
"condition": "Sunny"
|
130
|
+
}
|
131
|
+
|
132
|
+
# Register tool (schema automatically generated from function signature)
|
133
|
+
tool_client.register_tool(
|
134
|
+
name="get_weather",
|
135
|
+
description="Get current weather for a location",
|
136
|
+
function=get_weather
|
137
|
+
# No schema needed - automatically generated!
|
138
|
+
)
|
139
|
+
|
140
|
+
# Use the tool
|
141
|
+
response = tool_client.chat([
|
142
|
+
{"role": "user", "content": "What's the weather like in Tokyo?"}
|
143
|
+
])
|
144
|
+
print(response.choices[0].message.content)
|
145
|
+
```
|
146
|
+
|
147
|
+
### MCP Client for Server Integration
|
148
|
+
|
149
|
+
```python
|
150
|
+
import os
|
151
|
+
from mbxai import MCPClient, OpenRouterClient
|
152
|
+
|
153
|
+
# Initialize MCP client
|
154
|
+
openrouter_client = OpenRouterClient(token=os.getenv("OPENROUTER_API_KEY"))
|
155
|
+
mcp_client = MCPClient(openrouter_client)
|
156
|
+
|
157
|
+
# Register MCP server (automatically loads all tools)
|
158
|
+
mcp_client.register_mcp_server("data-analysis", "http://localhost:8000")
|
159
|
+
|
160
|
+
# Chat with MCP tools available
|
161
|
+
response = mcp_client.chat([
|
162
|
+
{"role": "user", "content": "Analyze the sales data from the server"}
|
163
|
+
])
|
164
|
+
print(response.choices[0].message.content)
|
165
|
+
```
|
166
|
+
|
167
|
+
### Agent Client - Intelligent Dialog System
|
168
|
+
|
169
|
+
The AgentClient provides an intelligent thinking process with question generation, quality improvement, and conversation memory.
|
170
|
+
|
171
|
+
```python
|
172
|
+
import os
|
173
|
+
from mbxai import AgentClient, OpenRouterClient
|
174
|
+
from pydantic import BaseModel, Field
|
175
|
+
|
176
|
+
class TravelPlan(BaseModel):
|
177
|
+
destination: str = Field(description="Travel destination")
|
178
|
+
duration: str = Field(description="Trip duration")
|
179
|
+
activities: list[str] = Field(description="Recommended activities")
|
180
|
+
budget: str = Field(description="Estimated budget")
|
181
|
+
|
182
|
+
# Initialize agent
|
183
|
+
openrouter_client = OpenRouterClient(token=os.getenv("OPENROUTER_API_KEY"))
|
184
|
+
agent = AgentClient(openrouter_client, max_iterations=2)
|
185
|
+
|
186
|
+
# Agent with questions (interactive mode)
|
187
|
+
response = agent.agent(
|
188
|
+
prompt="Plan a vacation for me",
|
189
|
+
final_response_structure=TravelPlan,
|
190
|
+
ask_questions=True
|
191
|
+
)
|
192
|
+
|
193
|
+
if response.has_questions():
|
194
|
+
print("Agent Questions:")
|
195
|
+
for q in response.questions:
|
196
|
+
print(f"- {q.question}")
|
197
|
+
|
198
|
+
# Answer questions
|
199
|
+
from mbxai import AnswerList, Answer
|
200
|
+
answers = AnswerList(answers=[
|
201
|
+
Answer(key="destination_preference", answer="Mountain destination"),
|
202
|
+
Answer(key="budget_range", answer="$2000-3000"),
|
203
|
+
Answer(key="duration", answer="5 days")
|
204
|
+
])
|
205
|
+
|
206
|
+
# Continue with answers
|
207
|
+
final_response = agent.agent(
|
208
|
+
prompt="Continue with the travel planning",
|
209
|
+
final_response_structure=TravelPlan,
|
210
|
+
agent_id=response.agent_id,
|
211
|
+
answers=answers
|
212
|
+
)
|
213
|
+
|
214
|
+
plan = final_response.final_response
|
215
|
+
print(f"Destination: {plan.destination}")
|
216
|
+
print(f"Duration: {plan.duration}")
|
217
|
+
else:
|
218
|
+
# Direct response
|
219
|
+
plan = response.final_response
|
220
|
+
print(f"Destination: {plan.destination}")
|
221
|
+
```
|
222
|
+
|
223
|
+
### Agent with Tool Integration
|
224
|
+
|
225
|
+
```python
|
226
|
+
from mbxai import AgentClient, ToolClient, OpenRouterClient
|
227
|
+
|
228
|
+
# Setup tool-enabled agent
|
229
|
+
openrouter_client = OpenRouterClient(token=os.getenv("OPENROUTER_API_KEY"))
|
230
|
+
tool_client = ToolClient(openrouter_client)
|
231
|
+
agent = AgentClient(tool_client)
|
232
|
+
|
233
|
+
# Register tools via agent (proxy method)
|
234
|
+
def search_flights(origin: str, destination: str, date: str) -> dict:
|
235
|
+
"""Search for flights between cities."""
|
236
|
+
return {
|
237
|
+
"flights": [
|
238
|
+
{"airline": "Example Air", "price": "$450", "duration": "3h 15m"}
|
239
|
+
]
|
240
|
+
}
|
241
|
+
|
242
|
+
agent.register_tool(
|
243
|
+
name="search_flights",
|
244
|
+
description="Search for flights between cities",
|
245
|
+
function=search_flights
|
246
|
+
)
|
247
|
+
|
248
|
+
# Agent automatically uses tools when needed
|
249
|
+
class FlightInfo(BaseModel):
|
250
|
+
flights: list[dict] = Field(description="Available flights")
|
251
|
+
recommendation: str = Field(description="Flight recommendation")
|
252
|
+
|
253
|
+
response = agent.agent(
|
254
|
+
prompt="Find flights from New York to Los Angeles for tomorrow",
|
255
|
+
final_response_structure=FlightInfo,
|
256
|
+
ask_questions=False
|
257
|
+
)
|
258
|
+
|
259
|
+
flight_info = response.final_response
|
260
|
+
print(f"Found {len(flight_info.flights)} flights")
|
261
|
+
print(f"Recommendation: {flight_info.recommendation}")
|
262
|
+
```
|
263
|
+
|
264
|
+
## 📚 Detailed Documentation
|
265
|
+
|
266
|
+
### OpenRouterClient
|
267
|
+
|
268
|
+
The base client for OpenRouter API integration with structured response support.
|
269
|
+
|
270
|
+
#### Key Features:
|
271
|
+
- **Multiple Models**: Support for GPT-4, Claude, Llama, and other models via OpenRouter
|
272
|
+
- **Structured Responses**: Type-safe responses using Pydantic models
|
273
|
+
- **Retry Logic**: Automatic retry with exponential backoff
|
274
|
+
- **Error Handling**: Comprehensive error handling with detailed logging
|
275
|
+
|
276
|
+
#### Methods:
|
277
|
+
- `create()` - Basic chat completion
|
278
|
+
- `parse()` - Chat completion with structured response
|
279
|
+
|
280
|
+
#### Configuration:
|
281
|
+
```python
|
282
|
+
client = OpenRouterClient(
|
283
|
+
token="your-api-key",
|
284
|
+
model="openai/gpt-4-turbo", # or use OpenRouterModel enum
|
285
|
+
max_retries=3,
|
286
|
+
retry_initial_delay=1.0,
|
287
|
+
retry_max_delay=10.0
|
288
|
+
)
|
289
|
+
```
|
290
|
+
|
291
|
+
### ToolClient
|
292
|
+
|
293
|
+
Extends OpenRouterClient with function calling capabilities.
|
294
|
+
|
295
|
+
#### Key Features:
|
296
|
+
- **Automatic Schema Generation**: Generate JSON schemas from Python function signatures
|
297
|
+
- **Tool Registration**: Simple function registration
|
298
|
+
- **Tool Execution**: Automatic tool calling and response handling
|
299
|
+
- **Error Recovery**: Graceful handling of tool execution errors
|
300
|
+
|
301
|
+
#### Usage:
|
302
|
+
```python
|
303
|
+
tool_client = ToolClient(openrouter_client)
|
304
|
+
|
305
|
+
# Register with automatic schema
|
306
|
+
tool_client.register_tool("function_name", "description", function)
|
307
|
+
|
308
|
+
# Register with custom schema
|
309
|
+
tool_client.register_tool("function_name", "description", function, custom_schema)
|
310
|
+
```
|
311
|
+
|
312
|
+
### MCPClient
|
313
|
+
|
314
|
+
Extends ToolClient with Model Context Protocol (MCP) server integration.
|
315
|
+
|
316
|
+
#### Key Features:
|
317
|
+
- **MCP Server Integration**: Connect to MCP servers and load their tools
|
318
|
+
- **Tool Discovery**: Automatically discover and register tools from MCP servers
|
319
|
+
- **HTTP Client Management**: Built-in HTTP client for MCP communication
|
320
|
+
- **Schema Conversion**: Convert MCP schemas to OpenAI function format
|
321
|
+
|
322
|
+
#### Usage:
|
323
|
+
```python
|
324
|
+
mcp_client = MCPClient(openrouter_client)
|
325
|
+
mcp_client.register_mcp_server("server-name", "http://localhost:8000")
|
326
|
+
```
|
327
|
+
|
328
|
+
### AgentClient
|
329
|
+
|
330
|
+
Wraps any client with intelligent dialog-based thinking capabilities.
|
331
|
+
|
332
|
+
#### Key Features:
|
333
|
+
- **Question Generation**: Automatically generates clarifying questions
|
334
|
+
- **Quality Iteration**: Improves responses through multiple AI review cycles
|
335
|
+
- **Conversation Memory**: Maintains conversation history across interactions
|
336
|
+
- **Flexible Configuration**: Configurable quality vs speed tradeoffs
|
337
|
+
- **Tool Proxy Methods**: Access underlying client's tool capabilities
|
338
|
+
|
339
|
+
#### Configuration Options:
|
340
|
+
```python
|
341
|
+
agent = AgentClient(
|
342
|
+
ai_client=any_supported_client,
|
343
|
+
max_iterations=2 # 0=fastest, 3+=highest quality
|
344
|
+
)
|
345
|
+
```
|
346
|
+
|
347
|
+
#### Dialog Flow:
|
348
|
+
1. **Question Generation** (if `ask_questions=True`)
|
349
|
+
2. **Answer Processing** (if questions were asked)
|
350
|
+
3. **Thinking Process** (analyze prompt and context)
|
351
|
+
4. **Quality Iteration** (improve response through AI review)
|
352
|
+
5. **Final Response** (generate structured output)
|
353
|
+
|
354
|
+
#### Session Management:
|
355
|
+
```python
|
356
|
+
# List active sessions
|
357
|
+
sessions = agent.list_sessions()
|
358
|
+
|
359
|
+
# Get session info
|
360
|
+
info = agent.get_session_info(agent_id)
|
361
|
+
|
362
|
+
# Delete session
|
363
|
+
agent.delete_session(agent_id)
|
364
|
+
```
|
365
|
+
|
366
|
+
## 🏃♂️ Advanced Examples
|
367
|
+
|
368
|
+
### Custom Model Registration
|
369
|
+
|
370
|
+
```python
|
371
|
+
from mbxai import OpenRouterClient, OpenRouterModel
|
372
|
+
|
373
|
+
# Register custom model
|
374
|
+
OpenRouterClient.register_model("CUSTOM_MODEL", "provider/model-name")
|
375
|
+
|
376
|
+
# Use custom model
|
377
|
+
client = OpenRouterClient(token="your-key", model="CUSTOM_MODEL")
|
378
|
+
```
|
379
|
+
|
380
|
+
### Conversation History and Context
|
381
|
+
|
382
|
+
```python
|
383
|
+
# Start a conversation
|
384
|
+
response1 = agent.agent("Tell me about quantum computing", ScienceExplanation)
|
385
|
+
agent_id = response1.agent_id
|
386
|
+
|
387
|
+
# Continue conversation with context
|
388
|
+
response2 = agent.agent(
|
389
|
+
"How does it compare to classical computing?",
|
390
|
+
ComparisonExplanation,
|
391
|
+
agent_id=agent_id,
|
392
|
+
ask_questions=False
|
393
|
+
)
|
394
|
+
|
395
|
+
# The agent remembers the previous conversation context
|
396
|
+
```
|
397
|
+
|
398
|
+
### Error Handling and Logging
|
399
|
+
|
400
|
+
```python
|
401
|
+
import logging
|
402
|
+
|
403
|
+
# Configure logging
|
404
|
+
logging.basicConfig(level=logging.DEBUG)
|
405
|
+
|
406
|
+
try:
|
407
|
+
response = client.create(messages)
|
408
|
+
except OpenRouterAPIError as e:
|
409
|
+
print(f"API Error: {e}")
|
410
|
+
except OpenRouterConnectionError as e:
|
411
|
+
print(f"Connection Error: {e}")
|
412
|
+
except Exception as e:
|
413
|
+
print(f"Unexpected Error: {e}")
|
414
|
+
```
|
415
|
+
|
416
|
+
### Streaming Responses
|
417
|
+
|
418
|
+
```python
|
419
|
+
# Streaming with OpenRouterClient
|
420
|
+
response = client.create(messages, stream=True)
|
421
|
+
for chunk in response:
|
422
|
+
if chunk.choices[0].delta.content:
|
423
|
+
print(chunk.choices[0].delta.content, end="")
|
424
|
+
|
425
|
+
# Streaming with ToolClient (tools execute before streaming)
|
426
|
+
response = tool_client.chat(messages, stream=True)
|
427
|
+
for chunk in response:
|
428
|
+
if chunk.choices[0].delta.content:
|
429
|
+
print(chunk.choices[0].delta.content, end="")
|
430
|
+
```
|
431
|
+
|
432
|
+
## 🧪 Testing
|
433
|
+
|
434
|
+
Run the test suite:
|
435
|
+
|
436
|
+
```bash
|
437
|
+
# Install development dependencies
|
438
|
+
pip install -e ".[dev]"
|
439
|
+
|
440
|
+
# Run tests
|
441
|
+
pytest tests/
|
442
|
+
|
443
|
+
# Run with coverage
|
444
|
+
pytest tests/ --cov=mbxai --cov-report=html
|
445
|
+
```
|
446
|
+
|
447
|
+
## 🔧 Development Setup
|
448
|
+
|
449
|
+
1. Clone the repository:
|
450
|
+
```bash
|
451
|
+
git clone https://github.com/yourusername/mbxai.git
|
452
|
+
cd mbxai/packages
|
453
|
+
```
|
454
|
+
|
455
|
+
2. Create a virtual environment:
|
456
|
+
```bash
|
457
|
+
python -m venv .venv
|
458
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
459
|
+
```
|
460
|
+
|
461
|
+
3. Install in development mode:
|
462
|
+
```bash
|
463
|
+
pip install -e ".[dev]"
|
464
|
+
```
|
465
|
+
|
466
|
+
4. Set up environment variables:
|
467
|
+
```bash
|
468
|
+
export OPENROUTER_API_KEY="your-api-key"
|
469
|
+
```
|
470
|
+
|
471
|
+
## 📄 License
|
472
|
+
|
473
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
474
|
+
|
475
|
+
## 🤝 Contributing
|
476
|
+
|
477
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
478
|
+
|
479
|
+
## 🔗 Links
|
480
|
+
|
481
|
+
- **Homepage**: [https://www.mibexx.de](https://www.mibexx.de)
|
482
|
+
- **Documentation**: [https://www.mibexx.de](https://www.mibexx.de)
|
483
|
+
- **Repository**: [https://github.com/yourusername/mbxai](https://github.com/yourusername/mbxai)
|
484
|
+
|
485
|
+
## 📊 Version Information
|
486
|
+
|
487
|
+
Current version: **2.1.3**
|
488
|
+
|
489
|
+
- Python 3.12+ required
|
490
|
+
- Built with modern async/await patterns
|
491
|
+
- Type-safe with Pydantic v2
|
492
|
+
- Compatible with OpenAI SDK v1.77+
|