---
layout: default
---

# Context Engineering

<v-clicks>

### Inyección de dependencias en runtime

```typescript
const contextSchema = z.object({
  userId: z.string(),
  apiKey: z.string(),
});

const fetchUserData = tool(
  async ({ query }, runtime: ToolRuntime<any, typeof contextSchema>) => {
    const { userId, apiKey } = runtime.context;
    return await performQuery(query, apiKey, userId);
  },
  { name: "fetch_user_data", schema: z.object({ query: z.string() }) }
);

const agent = createAgent({
  model: "gpt-4.1",
  tools: [fetchUserData],
  contextSchema
});

// Cada usuario tiene su propio contexto
await agent.invoke(messages, {
  context: { userId: "user_123", apiKey: "sk-..." }
});
```

</v-clicks>

