---
layout: default
---

# Streaming: Tokens y Mensajes

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

<v-click>

**`messages`**: Stream de tokens del LLM + metadata

```typescript
for await (const [mode, chunk] of await agent.stream(
  { messages: [{ role: "user", content: "Explica qué es TypeScript" }] },
  { streamMode: ["updates", "messages"] }
)) {
  if (mode === "messages") {
    const [token, metadata] = chunk;
    if (token.content) {
      process.stdout.write(token.content);  // Token a token
    }
  } else if (mode === "updates") {
    // Paso completo del agente
    console.log("\n[Paso completado]", Object.keys(chunk));
  }
}
```

</v-click>

<v-click>

<div class="mt-4 text-xs opacity-80">
Combina múltiples modos: `streamMode: ["updates", "messages"]`
</div>

</v-click>

</div>
