A chat model answers with tool calls: a tool name plus a JSON string of arguments. Before running anything you must check the arguments against the tool's schema, then append one tool message per call to the conversation so the model can read the results on its next turn.
Implement execute_tool_calls(messages, assistant_message, registry).
messages: the conversation so far (list of dicts). Do not mutate it.assistant_message: {"role": "assistant", "content": ..., "tool_calls": [{"id": str, "function": {"name": str, "arguments": str}}, ...]}. The tool_calls key may be missing or empty.registry: dict name -> {"function": callable, "parameters": schema}, where schema = {"type": "object", "properties": {arg: {"type": T, optional "enum": [...]}}, "required": [...]} and T is one of "string", "integer", "number", "boolean", "array", "object".Return messages + [assistant_message] + tool_messages, with one tool message per call, in call order:
{"role": "tool", "tool_call_id": id, "name": name, "content": content}.
content comes from the first check that fails, in this order:
error: unknown tool '<name>'error: arguments are not a JSON objectrequired, in order: error: missing required argument '<arg>'properties: error: unexpected argument '<arg>'error: argument '<arg>' must be <T>; a value outside enum gives error: argument '<arg>' must be one of <json.dumps(enum)>error: <ExceptionType>: <message>If every check passes, call function(**args). A str result is the content as is; any other result is json.dumps(result).
"integer" accepts int but not bool; "number" accepts int or float but not bool; "boolean" accepts only bool; "array" is a list, "object" a dict.