types

Canonical message/tool types.

AgentContext

Per-call payload handed to a provider's :complete.

Fields for AgentContext type contract
FieldTypeRequiredSummary
:max-tokens numberyesMaximum output token budget requested for the provider call.
:messages [Message]yesCanonical conversation history to convert into provider wire format.
:system-prompt string|nilFully rendered system prompt for the current step, or nil when omitted.
:tools [Tool]yesProvider-visible tool specs available for this step.

AgentTool

Tool extended with execution metadata for the agent loop. Registered through (api.register :tool ...).

Fields for AgentTool type contract
FieldTypeRequiredSummary
:description stringyesProvider-facing description included in the tool schema.
:execute (args ?yield-fn) -> AgentToolResultyesRuntime callback that executes the tool with decoded arguments.
:label stringUI label.
:name stringyesRegistry name used to merge and dispatch the tool.
:parameters JSONSchemayesProvider-facing argument schema used for validation and prompting.

AgentToolResult

Outcome of a tool execution.

Fields for AgentToolResult type contract
FieldTypeRequiredSummary
:content [TextContent]yesText content returned to the provider as the tool observation.
:details anyOpaque presenter payload (UI-only).
:is-error? booleanyesTrue when the tool observation represents a failed call.

AssistantMessage

Single model response. Content is always an array, even when empty.

Fields for AssistantMessage type contract
FieldTypeRequiredSummary
:api keyword:openai-completions | :openai-responses | :anthropic-messages | :openai-codex
:content [TextContent|ThinkingContent|ToolCall]yesOrdered assistant output blocks, including visible text, reasoning, and tool calls.
:error-message stringPresent only when stop-reason = :error.
:model stringProvider model identifier that produced this response.
:provider keywordRegistered provider :name (e.g. :openai, :anthropic).
:role :assistantyesMessage role discriminator for model-authored turns.
:stop-reason StopReasonNormalized reason the provider stopped generation.
:timestamp numberyesMilliseconds since epoch when the assistant message was recorded.
:usage UsageOptional token accounting returned by the provider for this response.

Message

Union of UserMessage, AssistantMessage, ToolResultMessage. Stored on agent.messages and passed to providers in AgentContext.messages.

Members for Message type contract
MemberKindSummary
UserMessage variantUserMessage is a Message union variant.
AssistantMessage variantAssistantMessage is a Message union variant.
ToolResultMessage variantToolResultMessage is a Message union variant.

StopReason

Why the assistant stopped producing output.

Members for StopReason type contract
MemberKindSummary
:stop enum:stop is a StopReason enum value.
:length enum:length is a StopReason enum value.
:tool-use enum:tool-use is a StopReason enum value.
:error enum:error is a StopReason enum value.
:aborted enum:aborted is a StopReason enum value.

TextContent

Plain visible text block.

Fields for TextContent type contract
FieldTypeRequiredSummary
:text stringyesVisible UTF-8 text payload.
:type :textyesContent-block discriminator for visible text.

ThinkingContent

Reasoning/extended-thinking block. Surfaces both Anthropic extended thinking and OpenAI reasoning items.

Fields for ThinkingContent type contract
FieldTypeRequiredSummary
:redacted? booleanTrue when the provider redacted visible text.
:thinking stringyesReasoning or extended-thinking text emitted by the provider.
:thinking-signature stringOpaque echo signature; required for multi-turn extended thinking.
:type :thinkingyesContent-block discriminator for provider reasoning text.

Tool

Provider-agnostic tool spec — what providers see in AgentContext.tools.

Fields for Tool type contract
FieldTypeRequiredSummary
:description stringyesProvider-visible explanation of when and how to call the tool.
:name stringyesProvider-visible tool name used in tool-call blocks.
:parameters JSONSchemayes{:type :object :properties {...} :required [...]}

ToolCall

Assistant request to invoke a tool. Arguments are a parsed Lua table — providers JSON-decode wire arguments before constructing this block.

Fields for ToolCall type contract
FieldTypeRequiredSummary
:arguments tableyesDecoded argument table validated by the target tool implementation.
:id stringyesProvider- or agent-generated id used to match the eventual tool result.
:name stringyesRegistered tool name to execute.
:type :tool-callyesContent-block discriminator for tool invocation requests.

ToolResultMessage

Result of a single tool call, carried back to the provider on the next turn.

Fields for ToolResultMessage type contract
FieldTypeRequiredSummary
:content [TextContent]yesTool output blocks returned to the provider on the next turn.
:details anyOpaque presenter payload (UI-only).
:is-error? booleanyesTrue when the tool result should be treated as an error observation.
:role :tool-resultyesMessage role discriminator for tool execution results.
:timestamp numberyesMilliseconds since epoch when the tool result was recorded.
:tool-call-id stringyesMatches the originating ToolCall.id.
:tool-name stringyesTool name that produced the result, copied from the originating call.

Usage

Token usage counters returned by the provider (best-effort — providers fill what they can).

Fields for Usage type contract
FieldTypeRequiredSummary
:cache-read numberProvider cache-read tokens credited for the response.
:cache-write numberProvider cache-write tokens billed or recorded for the response.
:input numberInput or prompt tokens counted for the response.
:output numberGenerated output tokens counted for the response.
:total-tokens numberProvider-reported total tokens, or the best available aggregate.

UserMessage

Single user turn. Content is either a plain string or an array of TextContent blocks.

Fields for UserMessage type contract
FieldTypeRequiredSummary
:content string|[TextContent]yesVisible user input as plain text or canonical text content blocks.
:role :useryesMessage role discriminator for user-authored turns.
:timestamp numberyesMilliseconds since epoch.