Alloy 0.14 hardens run deadlines, worker supervision, provider wire parsing,
and tool/config validation, and adds first-class portable :output_schema
structured outputs. Most callers upgrade with no changes; review the breaking
contracts below before bumping.
1. Run-wide :timeout_ms enforcement (and :infinity opt-out)
Previously, actively streaming HTTP/SSE responses and long tool batches could
run past :timeout_ms (default 120_000 ms). In 0.14, :timeout_ms bounds the
entire run — stalled or trickling HTTP/SSE streams, retries, tool batches, and
turn boundaries.
- Long-running agents (> 2 minutes): Raise
:timeout_msor passtimeout_ms: :infinityto disable the run-level deadline. Under:infinity, per-tool:tool_timeout, Codex's per-invocation:timeout_ms, and a 60s retry-delay ceiling still apply, while HTTP requests default toreceive_timeout: :infinity(passreq_options: [receive_timeout: ms]if you want a per-request idle/socket timeout). - Outer
Task.await/2buffer: Add ~2–5 seconds of buffer above:timeout_msso Alloy's worker/subprocess teardown can return a clean:timeoutresult. - Completed answers preserved: Already-completed
:end_turnanswers andstop_after_toolresults are returned rather than discarded on timeout; otherwise an expired deadline fails with:timeoutahead of:max_turns.
2. Supervised HTTP/SSE workers (Alloy.TaskSupervisor)
When :timeout_ms is finite (the default), built-in HTTP/SSE providers execute
Req inside a linked worker under Alloy.TaskSupervisor so caller death,
cancellation, and deadlines stop requests immediately.
- Ensure the
:alloyapplication is started (standard in Mix apps; in standalone scripts callApplication.ensure_all_started(:alloy)). Logger.metadata/0, OpenTelemetry context (:"$__current_otel_ctx"), and$callersare propagated automatically. CustomReqtest plugs that callsend(self(), ...)now run inside the worker process — capturetest_pid = self()in a closure before defining the plug.
3. New Alloy.Provider.Error kinds: :protocol_error and :shutdown
:protocol_error(non-retryable) is now used for deterministic wire-schema contract violations (valid non-object JSON replies, malformed choices/candidates/content/blocks, missing required tool-callid/name, mismatched Anthropic SSE deltas).:malformed_reply(retryable) remains for transient JSON/SSE corruption and model-generated invalid tool-argument JSON.:shutdown(non-retryable, skips retries and fallback providers) is returned when a request is interrupted by supervisor shutdown (including resumed Codex sessions, where you should still rotate:session_generation).- Update any exhaustive
case error.kindmatches to handle:protocol_errorand:shutdown.
4. Custom providers & Alloy.Provider.decode_body/1
- When
:timeout_msis finite, Alloy passes internal:alloy_request_deadlineinprovider_config. When the caller sets:output_schema, Alloy also injects:output_schema(anAlloy.OutputSchema.t()struct; omitted when unset). Custom providers using strict validators (Keyword.validate!/2,NimbleOptions) should tolerate unknown:alloy_*keys and:output_schema, and custom providers that want to support:output_schemamust translateconfig.output_schema.schemainto their wire format (otherwise the run fails terminally at JSON decode unless the model happened to emit conforming JSON). Alloy.Provider.decode_body/1now rejects non-object JSON (null, arrays, scalars) with{:error, %Alloy.Provider.Error{kind: :protocol_error}}and invalid JSON with{:error, %Alloy.Provider.Error{kind: :malformed_reply}}instead of a bare string.
5. Stricter startup & tool validation
Alloy.Agent.Config.from_opts/1now raisesArgumentErroronprovider: nil, boolean providers, non-positive:max_turns/:max_tokens/:tool_timeout, non-positive/non-:infinity:timeout_ms, negative:max_retries/:retry_backoff_ms, invalid:context/:system_prompt/:working_directory/:on_compaction/:code_execution/:until_tool, and invalid:middleware/:fallback_providersentries.Alloy.Testing.run_with_responses/3now validates options throughAlloy.Agent.Config.from_opts/1(defaultingcompaction: false).Alloy.Tool.Executorrejects explicitinput: nilas a non-object tool input (omit:inputor pass%{}for no-arg calls).Alloy.Tool.resolve_path/2now expands relative:allowed_pathsentries against:working_directoryrather than the BEAM process CWD, and rejects non-string paths, NUL bytes, and non-list:allowed_paths.Alloy.Tool.Core.Editrejects binary files, files over 10 MiB, and non-booleanreplace_allvalues;Alloy.Memory.tool/1caps results at 50,000 characters and rejectscreate/str_replace/inserton/memories.Alloy.Provider.Codexlaunches via non-loginsh -cwith explicit:env(set:codex_binifcodexis only on a login-shellPATH) and treats non-zero exits underpersist_session: trueas errors even whenlast_messageexists.tool_validation: :schemaconverts unsupported$schemadialects (e.g. Draft 2020-12) into a descriptiveArgumentError.- Tool & custom
:bash_executorexception redaction: Raised exceptions other thanRuntimeError(capped to 500 bytes), standard:badarg, and atom-keyKeyErrornow report only their exception module intool_resultblocks,result.tool_calls[].error,[:alloy, :tool, :stop], and logs so capturedcontextor credential maps cannot leak. Return{:error, message}orraise "..."for errors the model or telemetry should see. - Strict middleware halt/block/edit validation:
{:halt, reason},{:halt, reason, state}, and{:block, reason}now requirereasonto be a string (String.t()), and{:edit, modified_call}requires a plain map; passing any other value (such as{:halt, state}or{:block, state}) raisesArgumentError.
6. Portable structured outputs (:output_schema)
You can now pass a single JSON Schema across Anthropic, OpenAI, xAI, OpenAICompat, Gemini, and Codex:
schema = %{
type: "object",
properties: %{summary: %{type: "string"}, score: %{type: "integer"}},
required: ["summary", "score"],
additionalProperties: false
}
{:ok, result} =
Alloy.run("Score this PR.",
provider: {Alloy.Provider.Anthropic, api_key: key, model: "claude-sonnet-5-5"},
output_schema: schema
)
result.output
#=> %{"summary" => "...", "score" => 9}Alloy translates :output_schema into each provider's native structured-output
field (output_config.format, text.format, response_format,
generationConfig.responseJsonSchema, or Codex prompt instructions), forwards
it to fallback providers, omits it (and drops raw extra_body output_config,
text, response_format, and Gemini schema/thinking containers, including
sibling keys such as output_config.effort and text.verbosity) during
compaction summaries, and decodes/validates the final JSON into result.output
before :after_completion.
Key highlights (see Alloy.OutputSchema for the full failure, refusal,
validation-tier, and Gemini conflict contract):
- Top-level option only: Pass
:output_schematoAlloy.run/2,Alloy.stream/3, orAlloy.Agent.State.prepare/2(passing it inside provider config raisesArgumentError). Wrapper keys:name(default"alloy_output") and:strict(defaulttrue) apply to OpenAI, xAI, and OpenAICompat and are ignored on Anthropic, Gemini, and Codex. - Validation tiers: Full Draft 4/6/7 validation runs when optional
:ex_json_schemais installed; without it (or for Draft 2019-09/2020-12), Alloy falls back to top-level JSON"type"and"required"checks only. - Terminal failures: Invalid JSON,
:max_tokenstruncation, refusals, missing/whitespace text, and schema mismatches return{:error, result}withoutput: niland machine-readableresult.metadata.run.output_error(no automatic repair turn). When:stop_after_toolcompletes or:after_completionreturns{:halt, reason}/{:halt, reason, state},result.outputisnil. - Tools + schema compatibility: Gemini models prior to Gemini 3 and some
OpenAICompat servers reject combining
toolswith JSON Schema output; use Gemini 3+ (gemini-3.8-flash),:until_tool/:stop_after_tool, or a separate follow-up no-tools turn.