ExAthena.ToolCalls.RawJson (ExAthena v0.4.7)

Copy Markdown View Source

Best-effort parser for bare JSON tool calls embedded in assistant text.

Handles weak open-weight models (e.g. qwen2.5-coder:14b via Ollama) that emit tool calls as raw JSON objects in the text rather than structured tool_calls arrays or ~~~tool_call fences.

A valid payload looks like:

{"name": "read_file", "arguments": {"path": "/tmp/foo"}}

or wrapped in a markdown code fence:

```json
{"name": "read_file", "arguments": {"path": "/tmp/foo"}}
```

The parser walks the text scanning for { characters, then uses a balanced-brace scanner that respects JSON string boundaries (backslash escapes, in-string state). Never raises — malformed input returns {:ok, []}.

Summary

Functions

Extract tool calls from assistant text. Always returns {:ok, list}.

Functions

parse(text)

@spec parse(String.t()) :: {:ok, [ExAthena.Messages.ToolCall.t()]}

Extract tool calls from assistant text. Always returns {:ok, list}.