Skip to main content

Module tool_markup

Module tool_markup 

Source
Expand description

Fallback parser for tool calls emitted as inline markup instead of the provider’s native function-calling JSON.

Some models — notably DeepSeek served through certain OpenAI-compatible proxies (e.g. opencode-go) — emit tool calls as XML-ish markup inside the assistant content stream rather than as OpenAI tool_calls:

<||DSML||tool_calls>
<||DSML||invoke name="read">
<||DSML||parameter name="file_path" string="true">config.py</||DSML||parameter>
</||DSML||invoke>
</||DSML||tool_calls>

Anthropic-style <invoke name="..."> blocks use the same shape without the ||DSML|| token. When the OpenAI-compatible layer sees this in content (with finish_reason: "stop"), the tool would otherwise leak to the user as raw text and never execute. We detect and normalize both forms into real tool calls.

Structs§

ParsedToolCall

Functions§

extract_tool_calls
Extract every <invoke name="X"> … <parameter name="Y">Z</parameter> … </invoke> block (tolerating the ||DSML|| token prefix) into structured tool calls.
looks_like_tool_markup
Cheap pre-check: does this text contain inline tool-call markup we can parse? Used to (a) decide whether to suppress the raw text from the user and (b) whether to run the (more expensive) full extraction at stream end.