(args-object args)Parses a tool-call arguments value into a map, tolerating BOTH wire forms:
§11 requires a port to accept arguments supplied as an object as well as the
JSON string, because some clients send it that way. A malformed string is not
fatal — it yields {}.
Parses a tool-call `arguments` value into a map, tolerating BOTH wire forms:
§11 requires a port to accept `arguments` supplied as an object as well as the
JSON string, because some clients send it that way. A malformed string is not
fatal — it yields `{}`.(args-string args)Renders a tool-call arguments value as the JSON STRING the OpenAI wire
format uses, so a caller can hand it to a conforming client byte-for-byte.
Renders a tool-call `arguments` value as the JSON STRING the OpenAI wire format uses, so a caller can hand it to a conforming client byte-for-byte.
(content-text content)Flattens an OpenAI content value to text: the string form and the
parts-array form. Parts with no string text contribute nothing.
Flattens an OpenAI `content` value to text: the string form and the parts-array form. Parts with no string `text` contribute nothing.
(finish-reason-for has-tool-calls? provider-stop)Maps a provider stop reason onto an OpenAI finish reason.
TOOL CALLS WIN: a turn that emitted any tool call is always "tool_calls"
to a conforming client, whatever the provider said (§11). Otherwise
max_tokens/length -> "length", refusal/content_filter -> "content_filter",
everything else -> "stop".
Maps a provider stop reason onto an OpenAI finish reason. TOOL CALLS WIN: a turn that emitted any tool call is always `"tool_calls"` to a conforming client, whatever the provider said (§11). Otherwise max_tokens/length -> "length", refusal/content_filter -> "content_filter", everything else -> "stop".
(has-system-message? messages)True when the message list already carries a system-ish message.
True when the message list already carries a system-ish message.
(openai-messages-to-anthropic messages)Converts an OpenAI messages array into Anthropic-native messages plus the
extracted system prompt, preserving the tool structure a text flattening
destroys (§11):
tool_calls become tool_use blocks, with
arguments re-parsed from its JSON string into an OBJECT;tool-role result becomes a tool_result block keyed by its
tool_call_id, MERGED into a single user turn when consecutive;system/developer messages are HOISTED out, since Anthropic takes
system separately (multiple ones join with a blank line).Returns {:messages [...] :system "..."}.
Converts an OpenAI `messages` array into Anthropic-native messages plus the
extracted system prompt, preserving the tool structure a text flattening
destroys (§11):
- an assistant turn's `tool_calls` become `tool_use` blocks, with
`arguments` re-parsed from its JSON string into an OBJECT;
- a `tool`-role result becomes a `tool_result` block keyed by its
`tool_call_id`, MERGED into a single user turn when consecutive;
- `system`/`developer` messages are HOISTED out, since Anthropic takes
system separately (multiple ones join with a blank line).
Returns `{:messages [...] :system "..."}`.(openai-tool-choice-to-anthropic choice)Maps OpenAI tool_choice onto Anthropic's shape. Returns nil for absent /
"auto" (the provider default) and for anything unrecognized, so nothing is
sent and the provider decides.
Maps OpenAI `tool_choice` onto Anthropic's shape. Returns nil for absent / `"auto"` (the provider default) and for anything unrecognized, so nothing is sent and the provider decides.
(openai-tools-to-anthropic tools)Converts an OpenAI tools array into Anthropic tool declarations. Entries
that are already provider-native pass through; anything unrecognized is
skipped. A missing parameters becomes an empty object schema.
Converts an OpenAI `tools` array into Anthropic tool declarations. Entries that are already provider-native pass through; anything unrecognized is skipped. A missing `parameters` becomes an empty object schema.
(tool-calls-json result)Renders a result's tool calls as an OpenAI tool_calls array, ready to put on
an assistant message. Convenience for assembling a response envelope.
Renders a result's tool calls as an OpenAI `tool_calls` array, ready to put on an assistant message. Convenience for assembling a response envelope.
(tool-calls-of m)Reads an assistant message's OpenAI tool_calls into
[{:id :name :arguments}], arguments in the JSON-string wire form. An entry
with no function is skipped.
Reads an assistant message's OpenAI `tool_calls` into
`[{:id :name :arguments}]`, arguments in the JSON-string wire form. An entry
with no `function` is skipped.(translate client request)SPEC §11 — exactly ONE provider call, returned in OpenAI shape. Drives no loop, executes no tool, touches no conversation store.
client is a toolnexus.client/create-client map. request:
:messages the OpenAI messages array, VERBATIM (assistant turns with
tool_calls, tool-role results with tool_call_id)
:tools the OpenAI tools array, VERBATIM — declaration-only
:toolkit an ordinary toolkit, DECLARED via the §5 adapters and NEVER
executed; composes with :tools, toolkit declarations first
:toolChoice the OpenAI tool_choice, VERBATIM (mapped for anthropic)
:system overrides the system prompt
:maxTokens overrides the per-provider default (anthropic default 4096)
Returns:
{:text "" :toolCalls [{:id :name :arguments}] :finishReason "stop"|"tool_calls"|"length"|"content_filter" :usage {:prompt-tokens :completion-tokens :total-tokens} :model "" :raw <the provider's decoded response>}
:arguments is a JSON STRING — the OpenAI wire form.
SPEC §11 — exactly ONE provider call, returned in OpenAI shape. Drives no
loop, executes no tool, touches no conversation store.
`client` is a `toolnexus.client/create-client` map. `request`:
:messages the OpenAI `messages` array, VERBATIM (assistant turns with
`tool_calls`, `tool`-role results with `tool_call_id`)
:tools the OpenAI `tools` array, VERBATIM — declaration-only
:toolkit an ordinary toolkit, DECLARED via the §5 adapters and NEVER
executed; composes with :tools, toolkit declarations first
:toolChoice the OpenAI `tool_choice`, VERBATIM (mapped for anthropic)
:system overrides the system prompt
:maxTokens overrides the per-provider default (anthropic default 4096)
Returns:
{:text "" :toolCalls [{:id :name :arguments}] :finishReason
"stop"|"tool_calls"|"length"|"content_filter"
:usage {:prompt-tokens :completion-tokens :total-tokens}
:model "" :raw <the provider's decoded response>}
`:arguments` is a JSON STRING — the OpenAI wire form.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |