---
layout: default
---

# Combinando Middleware

<div class="mt-4 text-xs">

<v-click>

```typescript
import {
  createAgent,
  summarizationMiddleware,
  humanInTheLoopMiddleware,
  toolCallLimitMiddleware,
  modelRetryMiddleware,
} from "langchain";
import { MemorySaver } from "@langchain/langgraph";

const agent = createAgent({
  model: "mistral:mistral-large-latest",
  tools: [searchTool, sendEmailTool, databaseTool],
  checkpointer: new MemorySaver(),
  middleware: [
    modelRetryMiddleware({ maxRetries: 3, backoffFactor: 2 }),
    summarizationMiddleware({ model: "mistral:mistral-small-latest", trigger: { tokens: 4000 } }),
    toolCallLimitMiddleware({ toolName: "search", runLimit: 5 }),
    humanInTheLoopMiddleware({
      interruptOn: { send_email: { allowedDecisions: ["approve", "reject"] } },
    }),
  ],
});
```

</v-click>

<v-click>

<div class="mt-3 text-xs opacity-80">
El orden de los middleware importa: se ejecutan en secuencia
</div>

</v-click>

</div>
