Alloy 0.16 adds major-lab wire parity (multimodal PDFs/documents, image URLs,
dynamic :api_key callbacks, provider caching, Gemini native tools, portable
:reasoning), uniform v1 streaming events, cooperative cancellation
(Alloy.Cancel), mid-run :steering and completion :follow_up callbacks,
Alloy.Tool.Executor.run_tool/3, and optional Alloy.ModelCatalog capability
and pricing metadata — all with zero new mandatory runtime dependencies.
Most v0.14 callers upgrade cleanly; review the contract additions and stricter checks below before bumping.
1. Cooperative cancellation (:cancelled status and error kind)
Runs given a :cancel_token (Alloy.Cancel.new/0) return
{:error, %Alloy.Result{status: :cancelled, error: :cancelled}} when cancelled
cooperatively.
- Exhaustive pattern matches &
result.errortype:Alloy.Agent.State.status/0,Alloy.Result.status, andAlloy.Provider.Error.kind/0now include:cancelled. Update any exhaustivecasematches on run status,:turn_endevent status,[:alloy, :run, :stop]telemetry status, orerror.kind. Note thatresult.erroron{:error, result}is now the atom:cancelledrather than aString.t()(any underlying%Alloy.Provider.Error{kind: :cancelled}remains inresult.metadata.run.provider_error), so callers passingresult.errordirectly toString.*helpers must handle:cancelled. - Persistent Codex sessions after cancellation: Callers using
Alloy.Provider.Codexwithpersist_session: trueshould rotate:session_generationafter a:cancelledrun before starting new work so an interrupted CLI session is not resumed in a partial state. - Fail-closed middleware check:
Alloy.Middleware.run_before_tool_call/2now returns:cancelledwhenstate.config.cancel_tokenis cancelled (while preserving explicit{:block, reason}verdicts). Callers invokingrun_before_tool_call/2directly must handle:cancelled. - Runtime provider config keys: When
:cancel_tokenis set, Alloy injects:alloy_cancel_tokeninto theprovider_configmap passed to providers (alongside:alloy_request_deadline), and when top-level:reasoningis set, Alloy injects normalized:reasoning(%{effort: ..., display: ...}). Custom providers using strict option validators should tolerate unknown:alloy_*keys and:reasoning.
2. Dynamic :api_key callbacks, static key validation & required :origin_key
Built-in HTTP providers (Anthropic, OpenAI, XAI, Gemini, OpenAICompat)
now accept a 0-arity :api_key callback returning
String.t() | {:ok, String.t()} | {:error, term()} resolved per HTTP attempt.
- Required
:origin_key(applies to every primary and fallback provider):Alloy.Agent.Configenforces:origin_keyvalidation across all primary and:fallback_providersconfigs — including custom providers. Using a 0-arity:api_keyfunction ORauth_scheme: :bearer(supported onAnthropicandGeminiamong built-ins) now requires a non-empty string:origin_keyso rotating credentials preserve account provenance across turns and origin-scoped file attachments (file_id/ Gemini File API URIs). Passing either without:origin_keyraisesArgumentErrorat startup. - Key validation: Both static string
:api_keyvalues and callback results must be printable ASCII (0x20..0x7E, no CR/LF characters). Arbitrary callback failures map to non-retryable%Alloy.Provider.Error{kind: :auth}with sanitized messages (explicit{:error, %Alloy.Provider.Error{}}returns preserve allowlisted kinds, including:cancelled, with diagnostic fields redacted).
3. Portable :reasoning option
Pass :reasoning at the top level (Alloy.run/2, Alloy.stream/3,
Alloy.Agent.State.prepare/2) or inside provider config:
nil | :off | :low | :medium | :high | :xhigh | %{effort: ..., display: ...}.
- Global config validation (including custom providers):
Alloy.Agent.Configvalidates and normalizes:reasoningon every primary and fallback provider config at startup (and viaState.prepare/2). Custom providers that previously stored a custom non-portable:reasoningvalue in their provider config will now raiseArgumentError; rename that provider-specific option or accept the normalized%{effort: ..., display: ...}map. - Anthropic
reasoning: :off: Explicitly sends%{"thinking" => %{"type" => "disabled"}}(whereasreasoning: nilomits"thinking"as in v0.14). Explicit"thinking"insideextra_bodystill takes precedence. - Compaction summary stripping:
:reasoning(along with:prompt_cache_key,:prompt_cache_retention,:cached_content,:google_search,:url_context, and Gemini:code_execution) is stripped automatically on compaction summary requests.
4. Uniform v1 streaming events (events.md)
Alloy.Events v1 adds five additive event types:
:turn_start(%{turn:}) and:turn_end(%{turn:, status:, stop_reason:, usage:}):thinking_deltaacross Anthropic, OpenAI/xAI Responses, Gemini, and OpenAICompat:tool_call_delta(%{id:, index:, name:, arguments_delta:}):tool_update(%{id:, name:, chunk:, start_event_seq:}), marshalled to the caller process and wired toAlloy.Tool.Core.Bash- Optional
:parent_call_idon:tool_start,:tool_update, and:tool_endwhen emitted for nested calls viaAlloy.Tool.Executor.run_tool/3orexecute_all/4
Subscribers matching on v1 envelopes should keep a catch-all clause for unknown
event atoms. Note that :thinking_delta, :tool_call_delta, and
:tool_update are emitted only when :on_event is subscribed so unsubscribed
Alloy.stream/3 callers preserve retry/fallback resilience across non-text
deltas.
5. Stricter OpenAI / OpenAIStream tool-call validation & Events.build_correlation_id/1
Alloy.Provider.OpenAIStream(Chat Completions streaming viaOpenAICompat): Negative/malformed tool-call indices and conflicting tool identities (id/namechanges on the same slot) now return non-retryable:protocol_error; non-empty invalid JSON or non-object tool arguments return retryable:malformed_reply(with retries suppressed once any output has been emitted to caller callbacks).Alloy.Provider.OpenAI(OpenAI / xAI Responses streaming): Conflicting streamed tool-call headers (id/namemismatches) and contradictory completed tool arguments return:malformed_reply(retryable before output is emitted; retry/fallback-suppressed once output has been emitted to caller callbacks) instead of silently corrupting tool calls.Alloy.Events.build_correlation_id/1: Now requires non-empty valid UTF-8 strings forcontext[:request_id]andcontext[:correlation_id]; empty strings ("") or invalid UTF-8 fall back cleanly to a generated correlation ID instead of propagating invalid IDs toAlloy.Tool.Executor.
6. Mid-run :steering and completion :follow_up
:steering((State.t() -> [Message.t()])) is polled between completed tool batches; non-empty messages skip remaining unstarted batches with synthetic errortool_resultblocks, append the steering messages, and advance to the next turn (bypassing:stop_after_tool).:follow_up((State.t() -> [Message.t()])) is polled right before normal non-refusal:end_turncompletion once:until_toolis satisfied, bounded by:max_turns,:timeout_ms, and:cancel_token.- Both callbacks strictly validate returned
[%Alloy.Message{}]lists (roles, UTF-8, JSON-compatible block fields, andAlloy.Transcript.validate/1 == :ok) and sanitize exceptions/throws/exits with:redact.
7. Reusable single-tool execution & optional Alloy.ModelCatalog metadata
Alloy.Tool.Executor.run_tool/3executes a single tool call through the same middleware, schema validation, supervised worker, deadline clamping, composed cancellation, and event/telemetry pipeline asexecute_all/4, with native:parent_call_idsupport.Alloy.ModelCatalogkeepsAlloy.ModelCatalog.context_window/1as the sole required callback and adds optionalAlloy.ModelCatalog.max_output_tokens/1,Alloy.ModelCatalog.capabilities/1, andAlloy.ModelCatalog.pricing/1callbacks plusAlloy.ModelCatalog.info/1,2. Minimal v0.14 catalogs implementing onlycontext_window/1continue to work unchanged (the optional fields returnnil). See llm-db-catalog.md for a provider-scopedLLMDBadapter.