Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions mini_agent/llm/openai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,19 @@ def _convert_messages(self, messages: list[Message]) -> tuple[str | None, list[d
if msg.tool_calls:
tool_calls_list = []
for tool_call in msg.tool_calls:
arguments_json = tool_call.function.arguments_json
if arguments_json is None:
# Fall back to deterministic dump if raw string missing
arguments_json = json.dumps(
tool_call.function.arguments, separators=(",", ":"), sort_keys=True
)
tool_calls_list.append(
{
"id": tool_call.id,
"type": "function",
"function": {
"name": tool_call.function.name,
"arguments": json.dumps(tool_call.function.arguments),
"arguments": arguments_json,
},
}
)
Expand Down Expand Up @@ -223,8 +229,9 @@ def _parse_response(self, response: Any) -> LLMResponse:
tool_calls = []
if response.tool_calls:
for tool_call in response.tool_calls:
# Parse arguments from JSON string
arguments = json.loads(tool_call.function.arguments)
# Parse arguments from JSON string while preserving the raw text
raw_arguments = tool_call.function.arguments
arguments = json.loads(raw_arguments) if raw_arguments else {}

tool_calls.append(
ToolCall(
Expand All @@ -233,6 +240,7 @@ def _parse_response(self, response: Any) -> LLMResponse:
function=FunctionCall(
name=tool_call.function.name,
arguments=arguments,
arguments_json=raw_arguments,
),
)
)
Expand Down
3 changes: 2 additions & 1 deletion mini_agent/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class FunctionCall(BaseModel):
"""Function call details."""

name: str
arguments: dict[str, Any] # Function arguments as dict
arguments: dict[str, Any] # Parsed function arguments
arguments_json: str | None = None # Raw JSON string (for deterministic replay)


class ToolCall(BaseModel):
Expand Down