@@ -55,12 +55,15 @@ Every piece of information an agent processes becomes a Memory:
5555interface Memory {
5656 id? : UUID ; // Unique identifier
5757 entityId: UUID ; // Who created this memory (user/agent)
58+ agentId? : UUID ; // Associated agent ID
5859 roomId: UUID ; // Conversation context
5960 worldId? : UUID ; // Broader context (e.g., server)
6061 content: Content ; // The actual content
6162 embedding? : number []; // Vector representation
62- createdAt? : number ; // Timestamp
63- metadata? : MemoryMetadata ; // Additional data
63+ createdAt? : number ; // Timestamp (ms since epoch)
64+ unique? : boolean ; // Prevent duplicates
65+ similarity? : number ; // Similarity score (set on search)
66+ metadata? : MemoryMetadata ; // Additional data
6467}
6568
6669interface Content {
@@ -78,21 +81,22 @@ interface Content {
7881``` typescript
7982// Creating a memory through the runtime
8083async function createMemory(runtime : IAgentRuntime , message : string ) {
81- const memory: CreateMemory = {
84+ const memory: Memory = {
8285 agentId: runtime .agentId ,
8386 entityId: userId ,
8487 roomId: currentRoom ,
85- content: {
88+ content: {
8689 text: message ,
8790 metadata: {
8891 source: ' chat' ,
8992 processed: Date .now ()
9093 }
9194 }
9295 };
93-
94- // Runtime automatically generates embeddings if not provided
95- const memoryId = await runtime .createMemory (memory );
96+
97+ // Runtime creates memory with table name and optional unique flag
98+ // Signature: createMemory(memory: Memory, tableName: string, unique?: boolean)
99+ const memoryId = await runtime .createMemory (memory , ' messages' , true );
96100 return memoryId ;
97101}
98102```
@@ -146,7 +150,8 @@ export class AgentRuntime {
146150 readonly #conversationLength = 32 ; // Default messages to consider
147151
148152 // Dynamically adjust based on token limits
149- async buildContext(roomId : UUID ): Promise <State > {
153+ // Actual signature: composeState(message: Memory, includeList?: string[], onlyInclude?: boolean, skipCache?: boolean)
154+ async composeState(message : Memory ): Promise <State > {
150155 const memories = await this .getMemories ({
151156 roomId ,
152157 count: this .#conversationLength
@@ -235,10 +240,22 @@ State composition brings together memories and provider data:
235240``` typescript
236241// The runtime's state composition pipeline
237242interface State {
238- messages: Memory []; // Conversation history
239- facts: string []; // Known facts
240- providers: ProviderData []; // Provider contributions
241- context: string ; // Formatted context
243+ [key : string ]: unknown ; // Dynamic properties
244+ values: { // Key-value store for state variables
245+ [key : string ]: unknown ;
246+ };
247+ data: StateData ; // Structured data cache (room, world, entity, providers)
248+ text: string ; // String representation of context
249+ }
250+
251+ interface StateData {
252+ room? : Room ; // Cached room data
253+ world? : World ; // Cached world data
254+ entity? : Entity ; // Cached entity data
255+ providers? : Record <string , Record <string , unknown >>; // Provider results
256+ actionPlan? : ActionPlan ; // Current action plan
257+ actionResults? : ActionResult []; // Previous action results
258+ [key : string ]: unknown ; // Allow dynamic properties
242259}
243260
244261// Provider contribution to state
@@ -443,12 +460,13 @@ async function semanticSearch(
443460 options : SearchOptions = {}
444461): Promise <Memory []> {
445462 const embedding = await runtime .embed (query );
446-
447- return await runtime .searchMemoriesByEmbedding (embedding , {
463+
464+ // Signature: searchMemories(params: { embedding, query?, match_threshold?, count?, roomId? })
465+ return await runtime .searchMemories ({
466+ embedding ,
448467 match_threshold: options .threshold || 0.75 ,
449468 count: options .limit || 10 ,
450- roomId: options .roomId ,
451- filter: options .filter
469+ roomId: options .roomId
452470 });
453471}
454472
@@ -567,33 +585,27 @@ class VectorIndex {
567585The complete state object:
568586
569587``` typescript
588+ // State is defined in packages/core/src/types/state.ts
570589interface State {
571- // Core conversation context
572- messages: Memory [];
573- recentMessages: string ;
574-
575- // Agent knowledge
576- facts: string [];
577- knowledge: string ;
578-
579- // Provider contributions
580- providers: {
581- [key : string ]: {
582- text: string ;
583- data: any ;
584- };
585- };
586-
587- // Composed context
588- context: string ;
589-
590- // Metadata
591- metadata: {
592- roomId: UUID ;
593- entityId: UUID ;
594- timestamp: number ;
595- tokenCount: number ;
590+ [key : string ]: unknown ; // Dynamic properties allowed
591+
592+ values: { // Key-value store populated by providers
593+ [key : string ]: unknown ;
596594 };
595+
596+ data: StateData ; // Structured data cache
597+
598+ text: string ; // Formatted text representation
599+ }
600+
601+ interface StateData {
602+ room? : Room ; // Cached room data
603+ world? : World ; // Cached world data
604+ entity? : Entity ; // Cached entity data
605+ providers? : Record <string , Record <string , unknown >>; // Provider results cache
606+ actionPlan? : ActionPlan ; // Current multi-step action plan
607+ actionResults? : ActionResult []; // Previous action results
608+ [key : string ]: unknown ; // Dynamic properties
597609}
598610```
599611
@@ -939,7 +951,8 @@ async function debugSearch(runtime: IAgentRuntime, query: string) {
939951 // Test with different thresholds
940952 const thresholds = [0.9 , 0.8 , 0.7 , 0.6 , 0.5 ];
941953 for (const threshold of thresholds ) {
942- const results = await runtime .searchMemoriesByEmbedding (embedding , {
954+ const results = await runtime .searchMemories ({
955+ embedding ,
943956 match_threshold: threshold ,
944957 count: 5
945958 });
0 commit comments