agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
96 lines (95 loc) • 4.2 kB
TypeScript
/**
* BedrockAgentMemory — read the **auto-generated session-summary memory** of a
* (legacy) Amazon **Bedrock Agents** agent (peer-dep `@aws-sdk/client-bedrock-agent-runtime`).
*
* import { BedrockAgentMemory } from 'agentfootprint/memory';
*
* const mem = new BedrockAgentMemory({ agentId, agentAliasId, region: 'us-west-2' });
* const summaries = await mem.readSummaries(userMemoryId); // string summaries Bedrock wrote
*
* **This is NOT a `MemoryStore`** — and intentionally so. Bedrock Agents *owns the writes*:
* the agent generates `SESSION_SUMMARY` records itself (`GetAgentMemory` reads them,
* `DeleteAgentMemory` clears them). There is no "put an arbitrary entry" operation, so wrapping
* it as a `defineMemory({ store })` would be a "store that can't store." Instead it's a small
* **reader** you use to *surface* Bedrock's built-in memory — e.g. inject the summaries as a
* Fact/context block into an agentfootprint agent.
*
* For a real read/write agent memory store on AWS, use `AgentCoreStore` (the newer
* Bedrock **AgentCore** platform) — that's the go-forward path; this targets the prior-gen
* Bedrock Agents product and exists for teams migrating off it.
*
* Role: Outer ring. Lazy-requires the AWS SDK; zero cost when unused.
*/
/** One auto-generated session summary from Bedrock Agents memory. */
export interface BedrockAgentSummary {
readonly sessionId: string;
readonly summaryText: string;
/** ISO timestamps (the SDK returns Date; serialized here for portability). */
readonly sessionStartTime?: string;
readonly sessionExpiryTime?: string;
}
/** Minimal surface the reader uses; tests inject a mock via `_client`. */
export interface BedrockAgentMemoryLikeClient {
getSessionSummaries(input: {
agentId: string;
agentAliasId: string;
memoryId: string;
maxItems?: number;
nextToken?: string;
}): Promise<{
summaries: readonly BedrockAgentSummary[];
nextToken?: string;
}>;
deleteMemory(input: {
agentId: string;
agentAliasId: string;
memoryId: string;
sessionId?: string;
}): Promise<void>;
}
export interface BedrockAgentMemoryOptions {
/** The Bedrock Agent id whose memory to read. Required. */
readonly agentId: string;
/** The Bedrock Agent alias id. Required. */
readonly agentAliasId: string;
/** AWS region (when constructing the SDK client internally). */
readonly region?: string;
/** Pre-built client (shares one SDK config across the host app). */
readonly client?: BedrockAgentMemoryLikeClient;
/** Default page size for `readSummaries`. Default 20. */
readonly maxItems?: number;
/** @internal Test injection — skips the SDK require. */
readonly _client?: BedrockAgentMemoryLikeClient;
/** @internal Test injection — the AWS SDK module. */
readonly _sdk?: BedrockAgentRuntimeSdkModule;
}
/**
* Read-only reader for Bedrock Agents' auto session-summary memory.
*
* @throws when `@aws-sdk/client-bedrock-agent-runtime` is not installed and no
* `_client`/`_sdk` is supplied.
*/
export declare class BedrockAgentMemory {
private readonly client;
private readonly agentId;
private readonly agentAliasId;
private readonly maxItems;
constructor(options: BedrockAgentMemoryOptions);
/** All session summaries Bedrock generated for `memoryId` (paginated). */
readSummaries(memoryId: string, opts?: {
maxItems?: number;
}): Promise<BedrockAgentSummary[]>;
/** The concatenated summary text — handy to inject as a single context/Fact block. */
readText(memoryId: string): Promise<string>;
/** Clear Bedrock's memory for `memoryId` (optionally a single `sessionId`). */
forget(memoryId: string, sessionId?: string): Promise<void>;
}
export interface BedrockAgentRuntimeSdkModule {
readonly BedrockAgentRuntimeClient?: new (config: {
region?: string;
}) => {
send(cmd: unknown): Promise<unknown>;
};
readonly GetAgentMemoryCommand?: new (input: unknown) => unknown;
readonly DeleteAgentMemoryCommand?: new (input: unknown) => unknown;
}