0aff31e2d3
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
719 B
719 B
layout
| layout |
|---|
| default |
Middleware Custom
import { createAgent, createMiddleware } from "langchain";
const loggingMiddleware = createMiddleware({
name: "LoggingMiddleware",
beforeModel: (state) => {
console.log(`Llamando modelo con ${state.messages.length} mensajes`);
return; // No modificar estado
},
afterModel: (state) => {
const lastMsg = state.messages[state.messages.length - 1];
console.log(`Modelo respondió: ${lastMsg.content?.slice(0, 50)}...`);
return;
},
});
const agent = createAgent({
model: "mistral:mistral-large-latest",
tools: [weatherTool],
middleware: [loggingMiddleware],
});