Skip to content

ResponseIdTracker

Track provider response IDs for incremental language model calls.

Some providers can continue from a prior response by accepting a previousResponseId plus only the messages added after that response. This module exposes a small mutable service that remembers which prompt message objects were included in each provider response and prepares a shorter prompt when a later call extends the same conversation.

4 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

Creates an in-memory ResponseIdTracker service.

Details

The tracker maps prompt message object identities to provider response IDs. prepareUnsafe returns a previous response ID and the messages after the latest assistant turn only when the existing prompt prefix is fully tracked; otherwise it clears the tracked state and returns Option.none().

Signature

declare const make: Effect.Effect<Service>;

Models

PrepareResult interface

Added in v4.0.0 Source

Result returned when a tracked prompt can be sent incrementally.

Details

It contains the provider response ID to pass as previousResponseId and the prompt fragment containing only the new messages after the latest assistant turn.

Signature

interface PrepareResult {
  readonly previousResponseId: string;
  readonly prompt: Prompt;
}

Service interface

Added in v4.0.0 Source

Mutable service that tracks prompt message object identities by provider response ID.

Details

markParts records the prompt messages that produced a response, prepareUnsafe returns a previousResponseId plus the untracked suffix when the prompt prefix is fully recognized, and clearUnsafe drops all tracked state.

Signature

interface Service {
  clearUnsafe(): void;
  markParts(parts: readonly Array<object>, responseId: string): void;
  prepareUnsafe(prompt: Prompt): Option<PrepareResult>;
}

Services

Service tag for enabling provider previous-response ID reuse across language model calls.

When to use

Use when you provide a language model with previous-response ID tracking so later calls can send only new prompt messages together with the provider's prior response ID.

Signature

declare class ResponseIdTracker extends Shape<"effect/ai/ResponseIdTracker", Service, this> {
  constructor(_: never);
}