history
Retrieve recent conversation history for a session in chronological order to maintain context and continuity in AI agent interactions.
Instructions
Get recent conversation history for a session in chronological order.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session identifier | |
| limit | No | Max entries (default 20) |
Implementation Reference
- engram.ts:297-299 (handler)The 'history' method is the core handler that retrieves recent conversation history for a session. It delegates to the 'recall' method with the sessionId and limit parameters.
async history(sessionId: string, limit: number = 20): Promise<MemoryEntry[]> { return this.recall(sessionId, undefined, limit, {}); } - src/index.ts:68-78 (registration)Tool registration defining the 'history' tool with its name, description, and input schema (sessionId required, limit optional with default 20).
name: 'history', description: 'Get recent conversation history for a session in chronological order.', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session identifier' }, limit: { type: 'number', description: 'Max entries (default 20)', default: 20 }, }, required: ['sessionId'], }, }, - src/index.ts:232-238 (handler)The case handler that invokes memory.history() when the 'history' tool is called, passing sessionId and limit arguments, returning JSON-formatted entries.
case 'history': { const entries = await memory.history( args.sessionId as string, (args.limit as number) || 20 ); return { content: [{ type: 'text', text: JSON.stringify(entries, null, 2) }] }; } - engram.ts:4-12 (schema)MemoryEntry interface defines the output schema for history results: id, sessionId, content, role, timestamp, optional metadata and similarity.
export interface MemoryEntry { id: string; sessionId: string; content: string; role: 'user' | 'assistant' | 'system'; timestamp: Date; metadata?: Record<string, unknown>; similarity?: number; }