openai-agents
Version:
A TypeScript library extending the OpenAI Node.js SDK for building highly customizable agents and simplifying 'function calling'. Easily create and manage tools to extend LLM capabilities.
59 lines • 2.55 kB
TypeScript
import { ChatCompletionMessageParam } from 'openai/resources';
import { RedisClientType } from 'redis';
import { HistoryOptions, SaveHistoryOptions } from './types';
/**
* @class AgentStorage
* @description Manages chat history and session metadata persistence using Redis.
*/
export declare class AgentStorage {
private readonly redisClient;
historyOptions: HistoryOptions | undefined;
constructor(client: RedisClientType);
/**
* Validates the user ID, returning a 'default' value if undefined
* and throwing errors for invalid formats.
*/
private validateUserId;
/**
* Generates the Redis key for a given user ID.
*/
private getRedisKey;
/**
* Filters out tool-related messages from the chat history.
*
* @param {ChatCompletionMessageParam[]} messages - The chat history messages.
* @returns {ChatCompletionMessageParam[]} The filtered messages.
*/
removeToolMessages(messages: ChatCompletionMessageParam[]): ChatCompletionMessageParam[];
/**
* Removes tool messages that don't have a corresponding assistant or tool call ID.
*
* @param {ChatCompletionMessageParam[]} messages - The chat history messages.
* @returns {ChatCompletionMessageParam[]} The filtered messages.
*/
removeOrphanedToolMessages(messages: ChatCompletionMessageParam[]): ChatCompletionMessageParam[];
private filterMessages;
private calculateHistoryLength;
saveChatHistory(messages: ChatCompletionMessageParam[], userId?: string, options?: SaveHistoryOptions): Promise<void>;
/**
* Retrieves the chat history from Redis.
*
* @param {string} userId - The user ID.
* @param {HistoryOptions} options - Options for retrieving the history.
* @returns {Promise<ChatCompletionMessageParam[]>} The retrieved chat history.
* @throws {StorageError} If retrieving the chat history fails.
* @throws {MessageValidationError} If a message is invalid.
* @throws {RedisKeyValidationError} If the user ID is invalid.
*/
getChatHistory(userId: string, options?: HistoryOptions): Promise<ChatCompletionMessageParam[]>;
/**
* Deletes the chat history from Redis for a given user ID.
*
* @param {string} userId - The user ID.
* @returns {Promise<number>}
* @throws {StorageError} If deleting the chat history fails.
* @throws {RedisKeyValidationError} If the user ID is invalid.
*/
deleteHistory(userId: string): Promise<boolean>;
}
//# sourceMappingURL=storage.d.ts.map