mbxai 0.5.17__py3-none-any.whl → 0.5.18__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.17"
5
+ __version__ = "0.5.18"
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.17",
34
+ version="0.5.18",
35
35
  )
36
36
 
37
37
  # Initialize MCP server
mbxai/tools/client.py CHANGED
@@ -72,8 +72,13 @@ class ToolClient:
72
72
  truncated[k] = str(v)[:max_length] + "..." if len(str(v)) > max_length else v
73
73
  return str(truncated)
74
74
 
75
- def _validate_message_sequence(self, messages: list[dict[str, Any]]) -> None:
76
- """Validate the message sequence for tool calls and responses."""
75
+ def _validate_message_sequence(self, messages: list[dict[str, Any]], validate_responses: bool = True) -> None:
76
+ """Validate the message sequence for tool calls and responses.
77
+
78
+ Args:
79
+ messages: The message sequence to validate
80
+ validate_responses: Whether to validate that all tool calls have responses
81
+ """
77
82
  tool_call_ids = set()
78
83
  tool_response_ids = set()
79
84
 
@@ -89,23 +94,30 @@ class ToolClient:
89
94
  tool_response_ids.add(msg["tool_call_id"])
90
95
  logger.info(f"Found tool response for call ID {msg['tool_call_id']} in message {i}")
91
96
 
92
- # Check for missing responses
93
- missing_responses = tool_call_ids - tool_response_ids
94
- if missing_responses:
95
- logger.error(f"Missing tool responses for call IDs: {missing_responses}")
96
- logger.error("Message sequence:")
97
- for i, msg in enumerate(messages):
98
- role = msg.get("role", "unknown")
99
- if role == "assistant" and "tool_calls" in msg:
100
- logger.error(f" Message {i} - Assistant with tool calls: {[tc['id'] for tc in msg['tool_calls']]}")
101
- elif role == "tool":
102
- logger.error(f" Message {i} - Tool response for call ID: {msg['tool_call_id']}")
103
- else:
104
- logger.error(f" Message {i} - {role}: {self._truncate_content(msg.get('content'))}")
105
- raise ValueError(f"Invalid message sequence: missing responses for tool calls {missing_responses}")
106
-
107
- def _log_messages(self, messages: list[dict[str, Any]]) -> None:
108
- """Log the messages being sent to OpenRouter."""
97
+ # Only validate responses if requested
98
+ if validate_responses:
99
+ # Check for missing responses
100
+ missing_responses = tool_call_ids - tool_response_ids
101
+ if missing_responses:
102
+ logger.error(f"Missing tool responses for call IDs: {missing_responses}")
103
+ logger.error("Message sequence:")
104
+ for i, msg in enumerate(messages):
105
+ role = msg.get("role", "unknown")
106
+ if role == "assistant" and "tool_calls" in msg:
107
+ logger.error(f" Message {i} - Assistant with tool calls: {[tc['id'] for tc in msg['tool_calls']]}")
108
+ elif role == "tool":
109
+ logger.error(f" Message {i} - Tool response for call ID: {msg['tool_call_id']}")
110
+ else:
111
+ logger.error(f" Message {i} - {role}: {self._truncate_content(msg.get('content'))}")
112
+ raise ValueError(f"Invalid message sequence: missing responses for tool calls {missing_responses}")
113
+
114
+ def _log_messages(self, messages: list[dict[str, Any]], validate_responses: bool = True) -> None:
115
+ """Log the messages being sent to OpenRouter.
116
+
117
+ Args:
118
+ messages: The messages to log
119
+ validate_responses: Whether to validate that all tool calls have responses
120
+ """
109
121
  logger.info("Sending messages to OpenRouter:")
110
122
  for i, msg in enumerate(messages):
111
123
  role = msg.get("role", "unknown")
@@ -125,7 +137,7 @@ class ToolClient:
125
137
  logger.info(f" Message {i} - {role}: content='{content}'")
126
138
 
127
139
  # Validate message sequence
128
- self._validate_message_sequence(messages)
140
+ self._validate_message_sequence(messages, validate_responses)
129
141
 
130
142
  async def chat(
131
143
  self,
@@ -154,8 +166,8 @@ class ToolClient:
154
166
  kwargs["tool_choice"] = "auto"
155
167
 
156
168
  while True:
157
- # Log messages before sending to OpenRouter
158
- self._log_messages(messages)
169
+ # Log messages before sending to OpenRouter, but don't validate responses yet
170
+ self._log_messages(messages, validate_responses=False)
159
171
 
160
172
  # Get the model's response
161
173
  response = self._client.chat_completion(
@@ -228,8 +240,8 @@ class ToolClient:
228
240
  messages.append(tool_response)
229
241
  logger.info(f"Added tool response for call ID {tool_call.id}")
230
242
 
231
- # Validate message sequence before getting next response
232
- self._validate_message_sequence(messages)
243
+ # Now validate the message sequence after all tool calls have been processed
244
+ self._validate_message_sequence(messages, validate_responses=True)
233
245
 
234
246
  # Get a new response from the model with all tool results
235
247
  response = self._client.chat_completion(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mbxai
3
- Version: 0.5.17
3
+ Version: 0.5.18
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=ZLQIr0rOpwAUUWES-qp9QdbVKYWSAdUb9L08NrI7SB4,48
1
+ mbxai/__init__.py,sha256=tFcXsftXhe6lGhf_x4i-2A4VqY6oG4jt3o9rTgcfXuw,48
2
2
  mbxai/core.py,sha256=WMvmU9TTa7M_m-qWsUew4xH8Ul6xseCZ2iBCXJTW-Bs,196
3
3
  mbxai/mcp/__init__.py,sha256=_ek9iYdYqW5saKetj4qDci11jxesQDiHPJRpHMKkxgU,175
4
4
  mbxai/mcp/client.py,sha256=hEAVWIrIq758C1zm9aWGf-FiITB3LxtuxZEZ0CcjJ4s,5343
5
5
  mbxai/mcp/example.py,sha256=oaol7AvvZnX86JWNz64KvPjab5gg1VjVN3G8eFSzuaE,2350
6
- mbxai/mcp/server.py,sha256=apl2xuRSpFpqsgYNE42WCD-YfNVFguyUSYaYzngGj1Q,3463
6
+ mbxai/mcp/server.py,sha256=TL2Kr8SWMLRwtIsyiFcf9JPRLmja2PU_B-FE44fpDl8,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=SunEXOpJva6faGGxzKtMhgscHPq7PS4YFwV_Ll6VX-Q,16298
12
+ mbxai/tools/client.py,sha256=Y7cY_Z5sxDbSyMr1xzqME9lxLzjtwrBfyYX4jESHYDw,16958
13
13
  mbxai/tools/example.py,sha256=1HgKK39zzUuwFbnp3f0ThyWVfA_8P28PZcTwaUw5K78,2232
14
14
  mbxai/tools/types.py,sha256=fo5t9UbsHGynhA88vD_ecgDqL8iLvt2E1h1ym43Rrgk,745
15
- mbxai-0.5.17.dist-info/METADATA,sha256=s2QPZsInPdzDQBc18Jg5qisz-srRA9qo4cZ82ew2TLc,4108
16
- mbxai-0.5.17.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
- mbxai-0.5.17.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
18
- mbxai-0.5.17.dist-info/RECORD,,
15
+ mbxai-0.5.18.dist-info/METADATA,sha256=rV2rkKpOnSc5MzngBqQ281QowFO2XeQ6GUTDOP-QFwk,4108
16
+ mbxai-0.5.18.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
+ mbxai-0.5.18.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
18
+ mbxai-0.5.18.dist-info/RECORD,,
File without changes