Repository navigation
Description
Hi guys!
TL;DR: Agent Zero currently strips Claude's encrypted reasoning blob, because the Agent Zero API gateway doesn't expose POST /v1/responses to relay it to Venice -> Anthropic. On chat completions endpoint thinking blocks are never received and so the model's deep reasoning is never persisted and must be re-derived on every LLM call (even in-between tool calls, based solely on visible chat history/context window. In my reasoning-intense workload I noticed worse results. When after heavy reasoning where most of the token output budget (128k for most new frontiers) is spent on thinking the model tries to respond (or write a file to store the results of its efforts) and the max output tokens limit is reached, A0's litellm_transport throws ...litellm.MidStreamFallbackError: ...: OpenAIException - Response payload is not completed: <TransferEncodingError: 400, message='Not enough data to satisfy transfer length header.'> .
(rather bizarre way to inform user about the limit breached imo. Maybe I'll file a bug to change this error to better reflect what actually happened...)
The crux of the matter is that no thinking block round-trips means paying extra for thinking that's already been done a (tool) call earlier. This hurts all Agent Zero API users most, 'cause we can't benefit from preserved reasoning for tasks that require lots of thinking and end up paying extra for re-derived reasoning output tokens that otherwise would be much cheaper input tokens with 100% cache hit rate. Users of Venice that support the responses endpoint reap all the benefits of roundtripping thinking blocks via the POST /v1/responses endpoint, even if only for OpenAI native lane, so should the users of Agent Zero. Besides, encrypted thinking blocks are a common feature among frontier labs, so undoubtedly proper support for all the flavors will on Venice.
This feature request is a labour of love ❤️
The info was scattered across so many places that, even with Claude's help, compiling this took several hours over a few days. Please consider prioritising it.
Right now, my heavy reasoning work that needs top intelligence (e.g. Fable 5.2 at xhigh) is impractical on the "Free Daily API Credits": the reasoning alone can burn the whole daily quota before anything is delivered, and the reasoning already paid for is lost when the session resumes.
Learning that a model's reasoning is lost even between tool calls, when the blob isn't sent back on each call, was a real revelation to me. It's like reasoning amnesia on every LLM call!
Agent Zero version: v2.15 (latest at time of writing; <confirm your running version>) · Provider: Agent Zero API (https://llm.agent-zero.ai) · Model: Claude Fable 5.2 (reasoning_effort="xhigh")
Summary
Claude's newest models return their reasoning as an encrypted, signed blob that only Anthropic can read. To keep that reasoning across turns, the blob must be stored by the client and sent back verbatim on the next request.
Agent Zero's client already supports this on the OpenAI Responses transport (reasoning items are kept in metadata.responses.output_items in chat.json; v2.12 notes: "Preserved native Responses history within prepared prompts, retaining original IDs and encrypted reasoning"). The Agent Zero API gateway does not expose POST /v1/responses, so Claude conversations through the gateway are stuck on Chat Completions, where the client deliberately strips the blob. Nothing in the v2.8 to v2.15 release notes adds Responses support for this provider. As a result, Claude's deep reasoning is discarded after every response, including between tool calls within a single task.
This request asks for an experimental / beta POST /v1/responses relay in the gateway that round-trips Claude's encrypted reasoning losslessly, plus the small client-side changes needed to use it reliably.
Motivation
- On hard tasks, reasoning is the expensive and valuable part of a Claude turn. With
xhigheffort, one session can burn most (if not all) of a day's staking-based inference allowance on thinking alone. Without the encrypted reasoning blob (never visible to the clientuser), that was paid for is gone on every LLM call! The model must re-derive it, which costs more quota and quality. - A persisted blob survives subsequent tool/LLM calls, and a out-of-quota pause. Anthropic defines a thinking block's validity by model, conversation prefix and account, not elapsed time, so a stored blob is still usable after a 24 h pause as long as the three conditions below hold.
Lost reasoning and inconsistent quality at steep API price hurts bad...
I use Agent Zero daily with Claude Fable 5.2 and Opus 5.5 on thought-intensive work (thousands of thinking tokens per turn). The quality has been inconsistent: some outputs are excellent, while others miss obvious facts that a shred of thought would have caught, or misread something the model handled correctly a step earlier. I read this as a result of model's reasoning beeing lost between steps:
- Reasoning is lost at every tool call. In a typical agent loop the model thinks, calls a tool, reads the result and continues. Anthropic's tool-use docs say that when the thinking isn't sent back with the tool result: "dropping thinking blocks loses the reasoning in them, even without an error." The plan, rejected options and intermediate conclusions are gone, and the model continues from the visible text, the tool call and the result alone. Since no error is raised, nothing signals that it happened (reasoning blob present/dropped indicator in A0 would be nice).
- Anthropic's own testing points to a quality and cost effect. Anthropic reports that "when earlier thinking was dropped on every turn, the model thought again and used more output tokens", and its docs warn that dropping blocks "can affect output quality and latency". This matches what I see: after a tool call the model either re-derives what it had already worked out or never revisits it.
- API users depend on the harness and gateway to handle sending thinking back to
Anthropic/LLM provider - the client's gotta do the job right. Through a third-party harness and gateway, users only get the full benefits of deep-thinkin capabilities of an LLM if both layers round-trip the blob losslessly.
Lost reasoning hinders Agent Zero's utility. I believe this is one of the highest-impact quality improvements available (especially to Claude users) on the Agent Zero API. Worth prioritisation imho (even as an experimental opt-in).
What must hold for a replayed Claude thinking block to be used (Fable 5.2)
| Condition | Requirement |
|---|---|
| Model | The model reads its own blocks (and those of a documented set of other models). Others are dropped silently. |
| Prefix | Top-level system, tools, and every earlier message must be unchanged. cache_control markers are excluded from the comparison. On Fable 5.2 a mismatch is a 400 unless thinking.block_binding.prefix_mismatch_behavior: "drop_block" is set (beta header thinking-binding-controls-2026-08-01). |
| Account | Fable 5.2 / Mythos 5.2 blocks are tied to the account that produced them (or a linked one). Another account's blocks are dropped silently (reason organization_binding_mismatch). |
| Content | The thinking text is empty by default; the signature carries the reasoning. A missing, modified, or empty signature is always a 400. |
Anthropic also has explicit guidance for gateways (do not rewrite history, forward the beta header and block_binding, return input_transformations). See References.
Current behaviour (evidence)
-
A scan of a real Fable 5.2 chat's
chat.json(sub-agent a1,streaming_agent: 1) found 0 encrypted reasoning items and 30 ×"mode":"chat_completions", 0 ×"mode":"responses". -
With
a0_api_mode="responses"anda0_responses_fallback=falsein the model's Additional parameters, the first turn fails (trimmed):litellm.exceptions.NotFoundError: OpenAIException - {"detail":"Not Found","error":{"message":"Not Found"}} Client error '404 Not Found' for url 'https://llm.agent-zero.ai/v1/responses' -
Client-side, the Chat Completions path cannot carry the blob even if the gateway returned it:
ChatCompletionsTransport.parsereads onlyreasoning_content/reasoningtext (notreasoning_details)._ChatReasoningFilterdrops everything after the__ENCRYPTED_REASONING__marker.output_items()on the chat path is built from tool calls only, andprepare_messagesreplays nothing from history metadata.- Test
test_chat_wrapper_never_emits_or_persists_encrypted_reasoningenforces this on purpose.
Open question for maintainers: the v2.12 notes say the filter exists to keep "provider encrypted-reasoning markers" out of readable output, which implies some provider or gateway emits
__ENCRYPTED_REASONING__…. Doesllm.agent-zero.aiemit it for Claude models, and what exactly is the payload? -
Since v2.11 the default transport is Chat Completions, and "new providers default to Chat Completions unless they explicitly opt in to Responses" (v2.8 also routes chat-only providers straight to Chat Completions to avoid unsupported
/responsesprobes). So even after the gateway gains the endpoint, the Agent Zero API provider needs an explicit opt-in (see Part 2).
Line and symbol references below come from a code index that may predate v2.15; maintainers, please treat them as pointers, not exact locations.
Proposal
Part 1 — Gateway: POST /v1/responses for Claude models
Goal: a Responses-API-shaped endpoint that turns Anthropic's signed thinking / redacted_thinking blocks into opaque reasoning items and back, without loss.
Mapping
| Anthropic content block | Responses item |
|---|---|
thinking (thinking may be empty, plus signature) and redacted_thinking (data) |
{"type":"reasoning","id":"rs_…","summary":[…],"encrypted_content":"<opaque>"} |
text |
message item with output_text |
tool_use |
function_call item |
encrypted_content should be an opaque envelope (for example base64url of versioned JSON) that holds the ordered block list exactly as received, plus the model ID and an upstream-account identifier. A gateway-keyed HMAC is recommended so tampered or foreign blobs are rejected cleanly instead of reaching Anthropic as a 400.
Behaviour requirements
- Honour
include: ["reasoning.encrypted_content"], and always emit the reasoning item for Claude models that produced signed thinking. - Streaming: include
encrypted_contenton the reasoning item inresponse.output_item.doneand inresponse.completed. (LiteLLM's Responses bridge had a bug where streamedoutput_item.doneomitted it, see #44657 / #46032.) Never emit it twice with different IDs. - Replay: on the next request, map each reasoning item back to the assistant turn's content blocks in the original order, directly before that turn's
text/tool_use. Never reorder, merge, deduplicate, or drop empty-thinkingblocks. - Do not mutate the prefix between requests: keep the top-level
systemandtoolsstable, and leaverole:"system"messages where the caller put them (moving them into the top-levelsystemfield invalidates every block). Either disable provider-injected system prompts (e.g. Venice'sinclude_venice_system_prompt) or make them byte-stable. - Upstream account affinity: Fable 5.2 blocks are account-bound. If the gateway pools or rotates upstream keys or accounts, requests for one chat must stick to the account that produced the blocks, otherwise reasoning is silently dropped with no error.
- Accept
store: false(stateless).previous_response_idmay be ignored or rejected with a clear error. The client already falls back to local replay (RESPONSES_STATE_LOCAL) on a state-unsupported error. - Optional controls: expose Anthropic's
thinking.block_binding.prefix_mismatch_behavior("error"/"drop_block") through a gateway-defined extension parameter (similar to Venice'svenice_parameters), forward thethinking-binding-controls-2026-08-01beta header upstream, and surfaceinput_transformations(dropped or flagged blocks) in the response or a header so clients can detect lost reasoning. - Report usage faithfully:
usage.output_tokens_details.reasoning_tokensandusage.input_tokens_details.cached_tokens. - Advertise support so clients can auto-select it, for example a
capabilitiesfield onGET /v1/modelsand/or anx-a0-responses-lane-style response header. - Mark the feature experimental in docs and the model picker; Chat Completions stays the default and the fallback.
Choosing the upstream route. The gateway relays to Venice.ai; my reading of Venice's public docs (I could not inspect the gateway):
| Route | Status |
|---|---|
Venice /responses in translated mode (non-OpenAI models) |
The docs list include: ["reasoning.encrypted_content"] as supported, but also state under Limitations that "Reasoning items sent back in input are not passed to the model" and that the endpoint is stateless. Not usable for replay today. |
Venice /chat/completions with reasoning_details |
Venice's chat-completions guidance (as mirrored in its agent-skill docs) says to pass reasoning_details back verbatim, since it encodes thought signatures for Claude. Suggested route: the gateway terminates /v1/responses, calls Venice Chat Completions upstream, and packs reasoning_details verbatim into encrypted_content. This does not depend on Venice's Alpha /responses. Needs a live check on Fable 5.2. |
| Native Anthropic Messages upstream | Cleanest mapping, if the operator has such a route. |
If Venice later replays reasoning items in /responses, the gateway can forward natively instead.
Part 2 — Client (Agent Zero harness)
Persistence is mostly ready (Responses mode, local state replay, recovery of reasoning items from stream events, storage in metadata.responses.output_items). Replay is narrower than it looks: in v2.15 (helpers/responses_history.py, prepare_groups / project_history), encrypted reasoning is only sent back for native tool-call turns that have an immediately paired tool result. Remaining work:
- Provider opt-in plus capability-aware default. Under the v2.11 policy, providers must explicitly opt in to Responses. Let the Agent Zero API provider (and Venice, if applicable) opt in for Claude models, ideally driven by the gateway's advertised capability, and expose the choice in the model-preset UI. Avoid depending on the process-global
RESPONSES_UNSUPPORTED_CACHE, where one pre-output failure pins the model to Chat Completions until restart. - Do not downgrade effort.
RESPONSES_REASONING_EFFORTS = {minimal, low, medium, high}, so a configuredreasoning_effort="xhigh"silently becomes"high"on the Responses path. Pass through effort levels the target model supports. - Confirm cache routing doesn't force Chat Completions for Claude via this provider (
_should_preserve_cache_control_on_chat; the README says Agent Zero API usesprompt_cache_key). - Append-only history in Responses mode. Replay exactly what was sent and received. Audit anything that changes the prefix of an in-progress conversation: system-prompt extras (date, memory/solution recall; v2.14 already keeps masked extras at their original boundaries for Responses prompt caching, which is the right direction), tool-list changes, compaction, branching (v2.11 rebuilds provider state from trimmed history), and the v2.15 behaviour that removes replayable Responses output items from the history copy for rejected or incomplete tool calls. Any of these can invalidate later reasoning blocks on Fable 5.2. Where a rewrite is unavoidable, drop the affected reasoning intentionally and tell the user.
- Replay reasoning for every turn, not only paired tool calls. As read at v2.15,
prepare_groupsskips turns without function calls and keeps an unpaired final turn as plain text, so its reasoning (output: []) is never replayed. The DOX contract says to "never fabricate a tool acknowledgement" or "invent a final response-tool result", and that stays true: the fix is to replay the originalreasoningitem (and its ordering) in front of the final assistant message without inventing a result. Without this, the reasoning behind the last response of each work session is dropped even after the gateway supports Responses. - Protect the history prefix from compression.
History.compress()runs frommessage_loop_end/_10_organize_historyonce history exceedsctx_length × ctx_history(default 0.7). It summarizes and merges old topics and bulks, which rewrites early messages and invalidates every later reasoning block on Fable 5.2. Options: compress in a way that drops affected reasoning intentionally and tells the user, prefer Anthropic's server-side compaction on Claude routes, or make the threshold aware of reasoning blocks. - Do not put quota or auth failures into agent history. When a request fails with
403 {'detail': 'User has no quota left'}, the_error_retryplugin (defaultretries: 1) callshist_add_warning(), which stores the full formatted error and traceback as a user-rolesystem_warningmessage in the agent's history. This message is sent to the model on every later turn and stays in the prefix permanently. It does not invalidate earlier reasoning (it is appended after the last assistant turn), but it adds noise and tokens, and removing it later would invalidate every block produced after it. Treat quota-exhausted, 401 and 403 responses as non-retryable: log them to the UI only, keep them out of history, and ideally show when the quota resets. - Handle the mismatch error. On Anthropic's "bound to a different conversation" 400, retry once with
drop_block(if the gateway exposes it) or strip the named block and all later reasoning items, and persist that choice for the chat. - Continuity indicator. Log or show
input_transformations/ dropped reasoning, e.g. a "reasoning preserved / lost" badge on the message, so users can tell whether continuity survived. - (Nice to have) A "drop reasoning from history" action, since Anthropic allows removing thinking blocks from the start of history, from the end, or all of them. This lets users trade reasoning continuity for cheaper input.
Part 3 — Interim / fallback (Chat Completions)
If a full /v1/responses relay is too large for a first iteration, a smaller step may already give most of the benefit:
- Gateway returns structured
reasoning_details(or documents the current__ENCRYPTED_REASONING__payload) on/v1/chat/completionsand re-accepts it on the next assistant message. - Client captures it from the chat stream into
LLMResult.output_items(instead of discarding it in_ChatReasoningFilter), persists it, and re-attaches it to the matching assistant message inprepare_messages.
This needs the same gateway-side guarantees (verbatim, ordered, prefix-stable, account-affine), so Part 1 remains the preferred, spec-aligned design.
Acceptance criteria
- With
a0_api_mode="responses"anda0_responses_fallback=false, a Fable 5.2 conversation with at least one tool call completes without a 404. - After a reasoning turn,
chat.jsoncontainsmetadata.responses.mode == "responses"and areasoningoutput item with non-emptyencrypted_content. - The next request replays the item, and the response reports no
thinking_dropped/thinking_mismatch_allowedentries. - After restarting the container and waiting longer than the prompt-cache TTL (and ideally ≥ 24 h), continuing the same chat still reports no dropped reasoning.
- A deliberately edited earlier message produces a handled outcome (drop plus UI notice, or a clear error), not an unexplained 400 loop.
reasoning_effort="xhigh"reaches the upstream request unchanged for models that support it.- Chat Completions continues to work and remains the fallback when the endpoint or capability is absent.
- A reasoning item attached to a final (
responsetool) turn is replayed on the next request, and nothinking_droppedentry is reported for it. - After a
403 User has no quota leftfailure and a resumed prompt, no quota error is present in agent history, and earlier reasoning blocks are still accepted. - Triggering history compression on a long chat either keeps later reasoning blocks valid or visibly drops them with a notice (never a silent loss).
Risks and open questions
- Is
llm.agent-zero.aiopen source, and which upstream route does it use for Claude (Venice Chat Completions, Venice/responses, or something else)? - Does Venice return and accept
reasoning_detailsfor Claude Fable 5.2 in a form that Anthropic validates? (Needs a live multi-turn tool-call test.) - How are upstream accounts and keys allocated across A0T-staking users? Account binding means blocks can be dropped silently if requests move between accounts.
- Prefix drift: does the harness change the system prompt or tools mid-chat in ways that invalidate blocks? An audit is needed before reasoning continuity is promised to users.
- Storage growth: signed blobs add to
chat.jsonsize. - Token accounting:
Topic._message_tokenscounts history extras but not reasoning blobs, soHistory.compress()may under- or over-estimate real prompt size once blobs are replayed. - Code-reading caveat: the replay, compression and error-retry behaviour above comes from reading the v2.15 source (commit
ba9b67d), not from running it. Maintainers, please correct anything I misread.
Out of scope
- Reading or displaying Anthropic's raw reasoning (not available by design).
- Fixes inside LiteLLM. Known Responses-bridge issues for Anthropic thinking exist upstream (doubled thinking text in streamed
encrypted_content#43010, with fix PRs #43196 / #44127; missingencrypted_contenton streamedoutput_item.done#44657 / #46032, with fix PR #47271) and only matter here if the gateway uses LiteLLM's bridge. Check their current status. The experimental label covers residual bugs of this kind.
References
- Anthropic — Preserved thinking (prefix/model/account checks,
drop_block, gateway guidance); Thinking in tool and multi-turn workflows (echo blocks back or reasoning is lost "even without an error"); Fix a thinking block bound to a different conversation ("What dropping thinking costs"); Prompting Claude Fable 5.2 (Anthropic's test of dropping thinking on every turn) - Venice — Responses API guide (native vs translated mode, Limitations table)
- LiteLLM — Anthropic preserved thinking, issues #43010, #44657, #46032, PRs #43196, #44127, #47271
- Agent Zero release notes — v2.15 (latest), v2.14 (Venice / Agent Zero API cache routing, Responses prompt-caching fix, LiteLLM 1.104.0), v2.12 (native Responses history with encrypted reasoning; Chat reasoning-marker filter), v2.11 (Chat Completions default, provider opt-in for Responses, branching detaches provider state), v2.8 (chat-only providers skip
/responsesprobes), v2.0 (first native Responses transport and 404 fallback) - Agent Zero code —
helpers/litellm_transport.py(TransportPolicy,_ChatReasoningFilter,RESPONSES_REASONING_EFFORTS),helpers/responses_history.pyand its DOX (replay scope),helpers/history.py(History.compress,group_messages_abab),plugins/_error_retry/(_80_retry_critical_exception.py,default_config.yaml),tests/test_chat_encrypted_reasoning.py,plugins/_model_config/README.md(cache routing)
Activity
[-][Feature] Add `/v1/responses` relay for Claude encrypted reasoning (Agent Zero API gateway + client) (Feature request, but I see it as a bug also)[/-][+][Feature] Add `/v1/responses` relay for Claude encrypted reasoning (Agent Zero API gateway + client) (Feature request, but personally I see lack of it as a bug)[/+][-][Feature] Add `/v1/responses` relay for Claude encrypted reasoning (Agent Zero API gateway + client) (Feature request, but personally I see lack of it as a bug)[/-][+][Feature] Add `/v1/responses` relay for Claude encrypted reasoning (Agent Zero API gateway + client, Venice already supports it) (Feature request, but personally I see lack of it as a bug)[/+][-][Feature] Add `/v1/responses` relay for Claude encrypted reasoning (Agent Zero API gateway + client, Venice already supports it) (Feature request, but personally I see lack of it as a bug)[/-][+][Feature] Add `/v1/responses` relay for Claude/Anthropic encrypted reasoning (Agent Zero API gateway + client, Venice already supports) (Feature request, but should it be a bug)[/+][-][Feature] Add `/v1/responses` relay for Claude/Anthropic encrypted reasoning (Agent Zero API gateway + client, Venice already supports) (Feature request, but should it be a bug)[/-][+][Feature] Add `/v1/responses` relay for encrypted reasoning (Agent Zero API gateway + client, all providers, Venice already supports)[/+]