Skip to content

Commit adcf1de

Browse files
add docs
1 parent 4319335 commit adcf1de

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

libs/providers/langchain-anthropic/README.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,66 @@ const response = await model.stream({
7575
});
7676
```
7777

78+
## Tools
79+
80+
This package provides LangChain-compatible wrappers for Anthropic's built-in tools. These tools can be bound to `ChatAnthropic` using `bindTools()`.
81+
82+
### Memory Tool
83+
84+
The memory tool (`memory_20250818`) enables Claude to store and retrieve information across conversations through a memory file directory. Claude can create, read, update, and delete files that persist between sessions, allowing it to build knowledge over time without keeping everything in the context window.
85+
86+
```typescript
87+
import { ChatAnthropic, memory_20250818 } from "@langchain/anthropic";
88+
import type { Memory20250818Command } from "@langchain/anthropic";
89+
90+
// Create a simple in-memory file store (or use your own persistence layer)
91+
const files = new Map<string, string>();
92+
93+
const memory = memory_20250818({
94+
execute: async (command: Memory20250818Command) => {
95+
switch (command.command) {
96+
case "view":
97+
if (!command.path || command.path === "/") {
98+
return Array.from(files.keys()).join("\n") || "Directory is empty.";
99+
}
100+
return (
101+
files.get(command.path) ?? `Error: File not found: ${command.path}`
102+
);
103+
case "create":
104+
files.set(command.path!, command.file_text ?? "");
105+
return `Successfully created file: ${command.path}`;
106+
case "str_replace":
107+
const content = files.get(command.path!);
108+
if (content && command.old_str) {
109+
files.set(
110+
command.path!,
111+
content.replace(command.old_str, command.new_str ?? "")
112+
);
113+
}
114+
return `Successfully replaced text in: ${command.path}`;
115+
case "delete":
116+
files.delete(command.path!);
117+
return `Successfully deleted: ${command.path}`;
118+
// Handle other commands: insert, rename
119+
default:
120+
return `Unknown command`;
121+
}
122+
},
123+
});
124+
125+
const llm = new ChatAnthropic({
126+
model: "claude-sonnet-4-5-20250929",
127+
});
128+
129+
const llmWithMemory = llm.bindTools([memory]);
130+
131+
const response = await llmWithMemory.invoke(
132+
"Remember that my favorite programming language is TypeScript"
133+
);
134+
```
135+
136+
For more information, see [Anthropic's Memory Tool documentation](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/memory-tool).
137+
78138
## Development
79139

80140
To develop the Anthropic package, you'll need to follow these instructions:
@@ -103,8 +163,8 @@ Test files should live within a `tests/` file in the `src/` folder. Unit tests s
103163
end in `.int.test.ts`:
104164

105165
```bash
106-
$ pnpm test
107-
$ pnpm test:int
166+
pnpm test
167+
pnpm test:int
108168
```
109169

110170
### Lint & Format
@@ -124,5 +184,5 @@ If you add a new file to be exported, either import & re-export from `src/index.
124184
After running `pnpm build`, publish a new version with:
125185

126186
```bash
127-
$ npm publish
187+
npm publish
128188
```

0 commit comments

Comments
 (0)