Skip to content

Anthropic message threads

Anthropic request factories can retain bounded process-local message continuation state. The thread implementation stores transcript hashes and reply IDs, not prompts or credentials. Its default capacity is 10,000 sessions. It requires a session identity and compatible projected requests; support defaults to the direct Anthropic endpoint and can be controlled by SupportsMessageThreads / model compat.supportsMessageThreads.

On a matching transcript prefix, the next request sends only the suffix and the previous reply ID. Changes to the model, endpoint or relevant request settings create a new thread. Prefix hashing normalizes cache controls and equivalent text forms. A reply ID is reserved before network execution so concurrent calls cannot consume it twice. Failed, aborted or unreplayable replies do not become continuation state.

AnthropicMessageThreadStore is public in PiSharp.AI.Protocols.AnthropicMessages. Request-factory options accept ThreadStore; otherwise they use AnthropicMessageThreadStore.Shared.

using PiSharp.AI.Protocols.AnthropicMessages;
var threads = new AnthropicMessageThreadStore(maximumSessions: 1000);
// Pass threads as ThreadStore when constructing the Anthropic request factory.
threads.Cleanup(sessionId); // invalidates pending replies for this session too
// threads.Cleanup(); // clears all sessions in this store

Cleanup prevents a late reply from resurrecting a removed session. This is a request optimization, not durable conversation storage. Reopening a process starts without its continuation cache and retains the complete transcript path.

Known thread rejections trigger bounded full-request fallback. Unsupported requests disable continuation for the session; other recognized thread conflicts rebuild safely. The original full request remains available for replay. OAuth projection and cache-warming use the same compatibility policy. See authenticated factory and key factory.

Prepared payloads, metadata names, hooks, optional captures and public wire round trips preserve UTF-16 JSON values, including lone surrogates. Malformed payload and resource-limit checks remain active. Offline qualification is described in the acceptance report; it is not a live-provider validation claim.