import { type BedrockAgentCoreClient } from '@aws-sdk/client-bedrock-agentcore'; import type { MessageData } from '@strands-agents/sdk'; import { type ExtractionMode, type MetadataProvider } from './types.js'; export interface AgentCoreEventSenderConfig { client: BedrockAgentCoreClient; memoryId: string; actorId: string; sessionId: string; metadataProvider?: MetadataProvider | undefined; /** * Run-unique id anchoring the idempotency `clientToken`. Defaults to a fresh UUID per sender. A new * sender is built per `(actorId, sessionId)` per process, so this distinguishes runs even when the * framework's per-message sequence numbers reset to 0 (e.g. on session restore). */ runId?: string; /** * Maximum conversational turns packed into a single `createEvent`. A batch larger than this splits * into `ceil(n / maxTurnsPerEvent)` events. Defaults to {@link DEFAULT_MAX_TURNS_PER_EVENT}; bounds * the payload well under the service limit. */ maxTurnsPerEvent?: number; /** * Controls long-term memory extraction for events sent by this sender. When set to `"SKIP"`, events * are stored in short-term memory but excluded from long-term extraction. */ extractionMode?: ExtractionMode | undefined; } /** * Writes a batch of role-tagged messages to AgentCore, packing the turns into as few `createEvent` * calls as possible. `createEvent` accepts an array of conversational turns, so one flush of N turns * becomes a single call (chunked at `maxTurnsPerEvent`) rather than N calls — this is what lets the * extraction trigger cadence actually control API-call volume. AgentCore extracts a multi-turn event * into the same long-term records it would from N single-turn events. * * Error handling is delegated to the Strands `ExtractionCoordinator`: a failed `createEvent` throws * out of {@link sendBatch}, which makes the coordinator roll back its high-water mark and re-fire the * batch on the next trigger (with its own backoff and repeated-failure logging). The sender therefore * keeps no retry/timeout/drop machinery of its own — that would duplicate or fight the coordinator. A * caller that wants a per-request timeout configures it on the `client` it passes in (which also bounds * the read path). * * Idempotency: when the framework provides per-message sequence numbers (via * `AddMessagesContext.sequenceNumbers`), each event gets a deterministic `clientToken` derived from the * sequence range it covers, so a coordinator re-fire of the same batch dedups exactly. Because sequence * numbers reset to 0 across runs, the token also folds in a run-unique id (see * {@link AgentCoreEventSenderConfig.runId}). Without sequence numbers no token is sent; a re-fire then * writes one duplicate event, which AgentCore's server-side consolidation collapses at the record level * (wasteful but not incorrect). The token derivation is isolated in {@link tokenForSeqs} so it can move * to a stable per-message id when the framework exposes one. */ export declare class AgentCoreEventSender { private readonly client; private readonly memoryId; private readonly actorId; private readonly sessionId; private readonly metadataProvider; private readonly runId; private readonly maxTurnsPerEvent; private readonly extractionMode; constructor(config: AgentCoreEventSenderConfig); /** * Send a batch. The writable turns are packed into one `createEvent` per {@link EventGroup} (chunked * by `maxTurnsPerEvent` and split where per-message metadata changes). `sequenceNumbers` (when the * framework provides them) are index-aligned with `messages` and key each event's `clientToken`. * Throws an `AggregateError` if any event fails, so the coordinator retries the batch. */ sendBatch(messages: MessageData[], sequenceNumbers?: readonly number[]): Promise; /** * Partition the sendable turns into events. A new event starts when the per-message metadata changes * (the event's `metadata` is per-event in AgentCore, so turns in one event must share it) or when the * current event reaches `maxTurnsPerEvent`. With no `metadataProvider`, all turns share the empty * signature and collapse into size-capped events. */ private groupIntoEvents; private sendEvent; /** * Deterministic re-fire-stable token for an event covering the given sequence numbers, or `undefined` * when any is missing (then we tolerate error-path duplicates; consolidation is the backstop). The * token spans the event's `[firstSeq, lastSeq]`; a coordinator re-fire of the same batch reproduces * the same range. Never time/random-based per call — the run-unique part is fixed for the sender's * lifetime. Isolated here so it can switch to a stable per-message id when the framework exposes one. */ private tokenForSeqs; } //# sourceMappingURL=sender.d.ts.map