---
layout: default
---

<h1 class="!text-2xl">Human-in-the-Loop</h1>

<div class="mt-1">

<v-click>

````md magic-move
```typescript
import { createAgent, humanInTheLoopMiddleware } from "langchain";
import { Command, MemorySaver } from "@langchain/langgraph";

const agent = createAgent({
  model: "gpt-4.1",
  tools: [sendEmailTool, deleteRecordTool],
  checkpointer: new MemorySaver(),
  middleware: [
    humanInTheLoopMiddleware({
      interruptOn: {
        send_email: { allowedDecisions: ["approve", "edit", "reject"] },
        delete_record: { allowedDecisions: ["approve", "reject"] },
      },
    }),
  ],
});
```
```typescript
const config = { configurable: { thread_id: "thread-1" } };

// Se pausa antes de ejecutar tools sensibles
let result = await agent.invoke({ messages: [...] }, config);

// Aprobar y continuar
result = await agent.invoke(
  new Command({ resume: { decisions: [{ type: "approve" }] } }),
  config
);
```
````

</v-click>

</div>


---
