0aff31e2d3
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
772 B
Markdown
45 lines
772 B
Markdown
---
|
|
layout: default
|
|
---
|
|
|
|
# Tools: Definiendo Herramientas
|
|
|
|
<div class="mt-6 text-xs">
|
|
|
|
<v-click>
|
|
|
|
```typescript
|
|
import { tool } from "@langchain/core/tools";
|
|
import { z } from "zod";
|
|
|
|
const weatherTool = tool(
|
|
async ({ location }) => {
|
|
// Llamar a API del tiempo
|
|
return `El tiempo en ${location} es soleado, 22°C`;
|
|
},
|
|
{
|
|
name: "get_weather",
|
|
description: "Obtiene el tiempo actual de una ubicación",
|
|
schema: z.object({
|
|
location: z.string().describe("Ciudad o ubicación"),
|
|
}),
|
|
}
|
|
);
|
|
```
|
|
|
|
</v-click>
|
|
|
|
<v-click>
|
|
|
|
```typescript
|
|
// El agente decide automáticamente cuándo usar cada tool
|
|
const agent = createAgent({
|
|
model: "mistral:mistral-large-latest",
|
|
tools: [weatherTool, calculatorTool, searchTool],
|
|
});
|
|
```
|
|
|
|
</v-click>
|
|
|
|
</div>
|