mbxai 0.5.20__py3-none-any.whl → 0.5.21__py3-none-any.whl

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/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  MBX AI package.
3
3
  """
4
4
 
5
- __version__ = "0.5.20"
5
+ __version__ = "0.5.21"
mbxai/mcp/client.py CHANGED
@@ -90,7 +90,8 @@ class MCPClient(ToolClient):
90
90
  # Make the HTTP request to the tool's URL
91
91
  response = await self._http_client.post(
92
92
  url,
93
- json={"input": kwargs} if tool.strict else kwargs
93
+ json={"input": kwargs} if tool.strict else kwargs,
94
+ timeout=300.0 # 5 minutes timeout
94
95
  )
95
96
  return response.json()
96
97
 
mbxai/mcp/server.py CHANGED
@@ -31,7 +31,7 @@ class MCPServer:
31
31
  self.app = FastAPI(
32
32
  title=self.name,
33
33
  description=self.description,
34
- version="0.5.20",
34
+ version="0.5.21",
35
35
  )
36
36
 
37
37
  # Initialize MCP server
mbxai/tools/client.py CHANGED
@@ -9,6 +9,7 @@ import json
9
9
  from pydantic import BaseModel
10
10
  from ..openrouter import OpenRouterClient
11
11
  from .types import Tool, ToolCall
12
+ import asyncio
12
13
 
13
14
  logger = logging.getLogger(__name__)
14
15
 
@@ -266,10 +267,18 @@ class ToolClient:
266
267
 
267
268
  # Call the tool
268
269
  logger.info(f"Calling tool: {tool.name} with args: {self._truncate_dict(arguments)}")
269
- if inspect.iscoroutinefunction(tool.function):
270
- result = await tool.function(**arguments)
271
- else:
272
- result = tool.function(**arguments)
270
+ try:
271
+ if inspect.iscoroutinefunction(tool.function):
272
+ result = await asyncio.wait_for(tool.function(**arguments), timeout=300.0) # 5 minutes timeout
273
+ else:
274
+ result = tool.function(**arguments)
275
+ logger.info(f"Tool {tool.name} completed successfully")
276
+ except asyncio.TimeoutError:
277
+ logger.error(f"Tool {tool.name} timed out after 5 minutes")
278
+ result = {"error": "Tool execution timed out after 5 minutes"}
279
+ except Exception as e:
280
+ logger.error(f"Error calling tool {tool.name}: {str(e)}")
281
+ result = {"error": f"Tool execution failed: {str(e)}"}
273
282
 
274
283
  # Convert result to JSON string if it's not already
275
284
  if not isinstance(result, str):
@@ -360,13 +369,14 @@ class ToolClient:
360
369
  for tool_call in message.tool_calls
361
370
  ]
362
371
  messages.append(assistant_message)
363
- logger.info(f"Assistant message: content='{self._truncate_content(message.content)}', tool_calls={[tc.function.name for tc in message.tool_calls] if message.tool_calls else None}")
372
+ logger.info(f"Message count: {len(messages)}, Added assistant message with tool calls: {[tc.function.name for tc in message.tool_calls] if message.tool_calls else None}")
364
373
 
365
374
  # If there are no tool calls, we're done
366
375
  if not message.tool_calls:
367
376
  return response
368
377
 
369
- # Handle all tool calls before getting the next model response
378
+ # Process all tool calls
379
+ tool_responses = []
370
380
  for tool_call in message.tool_calls:
371
381
  tool = self._tools.get(tool_call.function.name)
372
382
  if not tool:
@@ -392,48 +402,24 @@ class ToolClient:
392
402
  if not isinstance(result, str):
393
403
  result = json.dumps(result)
394
404
 
395
- # Create and add the tool response immediately
405
+ # Create the tool response
396
406
  tool_response = {
397
407
  "role": "tool",
398
408
  "tool_call_id": tool_call.id,
399
409
  "content": result,
400
410
  }
401
- messages.append(tool_response)
402
- logger.info(f"Tool response for call ID {tool_call.id}: {self._truncate_content(result)}")
411
+ tool_responses.append(tool_response)
412
+ logger.info(f"Created tool response for call ID {tool_call.id}")
403
413
 
404
- # Get a new response from the model with all tool results
405
- response = self._client.chat_completion_parse(
406
- messages=messages,
407
- response_format=response_format,
408
- model=model,
409
- stream=stream,
410
- **kwargs,
411
- )
414
+ # Add all tool responses to the messages
415
+ messages.extend(tool_responses)
416
+ logger.info(f"Message count: {len(messages)}, Added {len(tool_responses)} tool responses to messages")
412
417
 
413
- if stream:
414
- return response
418
+ # Validate the message sequence
419
+ self._validate_message_sequence(messages, validate_responses=True)
415
420
 
416
- message = response.choices[0].message
417
- # Add the assistant's message with tool calls
418
- assistant_message = {
419
- "role": "assistant",
420
- "content": message.content or None, # Ensure content is None if empty
421
- }
422
- if message.tool_calls:
423
- assistant_message["tool_calls"] = [
424
- {
425
- "id": tool_call.id,
426
- "type": "function",
427
- "function": {
428
- "name": tool_call.function.name,
429
- "arguments": tool_call.function.arguments,
430
- },
431
- }
432
- for tool_call in message.tool_calls
433
- ]
434
- messages.append(assistant_message)
435
- logger.info(f"Assistant message: content='{self._truncate_content(message.content)}', tool_calls={[tc.function.name for tc in message.tool_calls] if message.tool_calls else None}")
421
+ # Log the messages we're about to send
422
+ self._log_messages(messages, validate_responses=False)
436
423
 
437
- # If there are no more tool calls, we're done
438
- if not message.tool_calls:
439
- return response
424
+ # Continue the loop to get the next response
425
+ continue
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mbxai
3
- Version: 0.5.20
3
+ Version: 0.5.21
4
4
  Summary: MBX AI SDK
5
5
  Project-URL: Homepage, https://www.mibexx.de
6
6
  Project-URL: Documentation, https://www.mibexx.de
@@ -1,18 +1,18 @@
1
- mbxai/__init__.py,sha256=PUJe90d--hNgAyBIE5Y18DZDiuCdN7znT-cSzdXGpWM,48
1
+ mbxai/__init__.py,sha256=_iYdYXR15WHhK5UJKTKwj9MTpmhkiwKKaIJAdJAPsM4,48
2
2
  mbxai/core.py,sha256=WMvmU9TTa7M_m-qWsUew4xH8Ul6xseCZ2iBCXJTW-Bs,196
3
3
  mbxai/mcp/__init__.py,sha256=_ek9iYdYqW5saKetj4qDci11jxesQDiHPJRpHMKkxgU,175
4
- mbxai/mcp/client.py,sha256=hEAVWIrIq758C1zm9aWGf-FiITB3LxtuxZEZ0CcjJ4s,5343
4
+ mbxai/mcp/client.py,sha256=sUdup2ts_Anr5o27y-BZW2hE_xw-2T7Sstds7cZexCw,5395
5
5
  mbxai/mcp/example.py,sha256=oaol7AvvZnX86JWNz64KvPjab5gg1VjVN3G8eFSzuaE,2350
6
- mbxai/mcp/server.py,sha256=8dfQSFdA0LN0kwSws-9our6vqq5L0F6U-s3gkB9-zME,3463
6
+ mbxai/mcp/server.py,sha256=hGlo5m_HdX0pTqxp-DmecCSo_830zVUFZcjvGhe9pVM,3463
7
7
  mbxai/openrouter/__init__.py,sha256=Ito9Qp_B6q-RLGAQcYyTJVWwR2YAZvNqE-HIYXxhtD8,298
8
8
  mbxai/openrouter/client.py,sha256=XLRMRNRJH96Jl6_af0KkzRDdLJnixh8I3RvEEcFuXyg,10840
9
9
  mbxai/openrouter/config.py,sha256=MTX_YHsFrM7JYqovJSkEF6JzVyIdajeI5Dja2CALH58,2874
10
10
  mbxai/openrouter/models.py,sha256=b3IjjtZAjeGOf2rLsdnCD1HacjTnS8jmv_ZXorc-KJQ,2604
11
11
  mbxai/tools/__init__.py,sha256=QUFaXhDm-UKcuAtT1rbKzhBkvyRBVokcQIOf9cxIuwc,160
12
- mbxai/tools/client.py,sha256=chTzGN6Tyi8Z428e5sR3BklieH8vBSKlx95SZ56GKg8,17729
12
+ mbxai/tools/client.py,sha256=t7rdITqgCbDXQPFOZhGj6VDDPAwqdilJMKPfCOcJaFo,17279
13
13
  mbxai/tools/example.py,sha256=1HgKK39zzUuwFbnp3f0ThyWVfA_8P28PZcTwaUw5K78,2232
14
14
  mbxai/tools/types.py,sha256=fo5t9UbsHGynhA88vD_ecgDqL8iLvt2E1h1ym43Rrgk,745
15
- mbxai-0.5.20.dist-info/METADATA,sha256=cm360CdwmXEwZnwFNj8pS2ssbonWyl_zFCiKyCTMrrM,4108
16
- mbxai-0.5.20.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
- mbxai-0.5.20.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
18
- mbxai-0.5.20.dist-info/RECORD,,
15
+ mbxai-0.5.21.dist-info/METADATA,sha256=vXEAsDBTc5drMfXx2mo9PXvG-BikBYz293NAclpyl54,4108
16
+ mbxai-0.5.21.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
+ mbxai-0.5.21.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
18
+ mbxai-0.5.21.dist-info/RECORD,,
File without changes