mirror of
https://github.com/langchain-ai/docs.git
synced 2026-08-27 21:00:00 -04:00
70 lines
1.4 KiB
Plaintext
70 lines
1.4 KiB
Plaintext
```ts
|
|
import { tool } from "langchain";
|
|
import { createDeepAgent } from "deepagents";
|
|
import { MemorySaver } from "@langchain/langgraph";
|
|
import { z } from "zod";
|
|
|
|
const removeFile = tool(
|
|
async ({ path }: { path: string }) => {
|
|
return `Deleted ${path}`;
|
|
},
|
|
{
|
|
name: "remove_file",
|
|
description: "Delete a file from the filesystem.",
|
|
schema: z.object({
|
|
path: z.string(),
|
|
}),
|
|
},
|
|
);
|
|
|
|
const fetchFile = tool(
|
|
async ({ path }: { path: string }) => {
|
|
return `Contents of ${path}`;
|
|
},
|
|
{
|
|
name: "fetch_file",
|
|
description: "Read a file from the filesystem.",
|
|
schema: z.object({
|
|
path: z.string(),
|
|
}),
|
|
},
|
|
);
|
|
|
|
const notifyEmail = tool(
|
|
async ({
|
|
to,
|
|
subject,
|
|
body,
|
|
}: {
|
|
to: string;
|
|
subject: string;
|
|
body: string;
|
|
}) => {
|
|
return `Sent email to ${to}`;
|
|
},
|
|
{
|
|
name: "notify_email",
|
|
description: "Send an email.",
|
|
schema: z.object({
|
|
to: z.string(),
|
|
subject: z.string(),
|
|
body: z.string(),
|
|
}),
|
|
},
|
|
);
|
|
|
|
// Checkpointer is REQUIRED for human-in-the-loop
|
|
const checkpointer = new MemorySaver();
|
|
|
|
const agent = createDeepAgent({
|
|
model: "google_genai:gemini-3.6-flash",
|
|
tools: [removeFile, fetchFile, notifyEmail],
|
|
interruptOn: {
|
|
remove_file: true, // Default: approve, edit, reject, respond
|
|
fetch_file: false, // No interrupts needed
|
|
notify_email: { allowedDecisions: ["approve", "reject"] }, // No editing
|
|
},
|
|
checkpointer, // Required!
|
|
});
|
|
```
|