11import { tool } from "@langchain/core/tools" ;
22import type { DynamicStructuredTool , ToolRuntime } from "@langchain/core/tools" ;
33
4- import { StateFileSystem } from "./utils/StateFileSystem.js" ;
5- import { CommandHandler } from "./utils/CommandHandler.js" ;
6- import { handleMemoryCommand } from "./utils/index.js" ;
7- import type { FileData } from "./utils/FileData.js" ;
8- import type { FileSystem } from "./utils/FileSystem.js" ;
94import type { MemoryTool20250818Options } from "./types.js" ;
105
116/**
@@ -29,13 +24,19 @@ import type { MemoryTool20250818Options } from "./types.js";
2924 * },
3025 * });
3126 *
32- * const memory = memory_20250818();
27+ * const memory = memory_20250818({
28+ * execute: async (args) => {
29+ * // handle memory command execution
30+ * // ...
31+ * },
32+ * });
3333 * const llmWithMemory = llm.bindTools([memory]);
3434 *
3535 * const response = await llmWithMemory.invoke("Remember that I like Python");
3636 * ```
3737 *
3838 * @param options - Optional configuration for the memory tool (currently unused)
39+ * @param options.execute - Optional execute function that handles memory command execution.
3940 * @returns The memory tool object that can be passed to `bindTools`
4041 *
4142 * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/memory-tool
@@ -50,7 +51,6 @@ export function memory_20250818(
5051 ) => string | Promise < string > ,
5152 {
5253 name : "memory" ,
53- description : "Memory tool" ,
5454 schema : {
5555 type : "object" ,
5656 properties : {
@@ -71,7 +71,8 @@ export function memory_20250818(
7171 }
7272 ) ;
7373
74- memoryTool . metadata = {
74+ memoryTool . extras = {
75+ ...( memoryTool . extras ?? { } ) ,
7576 providerToolDefinition : {
7677 type : "memory_20250818" ,
7778 name : "memory" ,
@@ -80,27 +81,3 @@ export function memory_20250818(
8081
8182 return memoryTool ;
8283}
83-
84- interface MemoryToolOptions {
85- allowedPrefixes ?: string [ ] ;
86- filesystem ?: FileSystem ;
87- }
88-
89- /**
90- * useful implementation
91- */
92- export function memory ( options ?: MemoryToolOptions ) : DynamicStructuredTool {
93- const filesystem : Record < string , FileData > = { } ;
94- return memory_20250818 ( {
95- execute : async ( args ) => {
96- const updates : Record < string , FileData | null > = { } ;
97- const fileSystem =
98- options ?. filesystem ??
99- new StateFileSystem ( filesystem , options ?. allowedPrefixes , ( files ) => {
100- Object . assign ( updates , files ) ;
101- } ) ;
102- const commandHandler = new CommandHandler ( fileSystem ) ;
103- return await handleMemoryCommand ( commandHandler , args ) ;
104- } ,
105- } ) ;
106- }
0 commit comments