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§

could_be_tool_markup_prefix
True while the first streamed content bytes could still become one of the supported tool-call markup forms. Used by streaming adapters to avoid leaking partial DSML/DeepSeek tags before looks_like_tool_markup() can see a complete closed block.
extract_tool_calls
Extract supported inline tool-call formats 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.