> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentium.in/llms.txt
> Use this file to discover all available pages before exploring further.

# 6. Stream and inspect a run

> Read incremental text while observing the tool loop.

[Support assistant tutorial](/learn/support-assistant)

This checkpoint returns to the read-only order tool. Text goes to stdout; the tool-start event goes to stderr. This makes tool use visible without treating it as user-facing answer text.

## Complete checkpoint

```typescript support.ts theme={null}
import { Agent, defineTool, openai } from "@agentium/core";
import { z } from "zod";

const orders = new Map([
  ["ORD-1042", { status: "shipped", delivery: "Friday", refundable: true }],
]);
const lookupOrder = defineTool({
  name: "lookup_order",
  description: "Look up an order's status and expected delivery by its ID.",
  parameters: z.object({ orderId: z.string() }),
  execute: async ({ orderId }) => JSON.stringify(orders.get(orderId) ?? { error: "Order not found" }),
});
const agent = new Agent({
  name: "support",
  model: openai(process.env.OPENAI_MODEL ?? "gpt-6.1-sol"),
  instructions: "Use lookup_order for order details. If the order is missing, say so.",
  tools: [lookupOrder],
  maxToolRoundtrips: 3,
});

agent.eventBus.on("tool.call", ({ toolName }) => {
  console.error(`[tool] ${toolName}`);
});

try {
  for await (const chunk of agent.stream("When will ORD-1042 arrive?")) {
    if (chunk.type === "text") process.stdout.write(chunk.text);
  }
  process.stdout.write("\n");
} finally {
  await agent.close();
}
```

## Run it

```bash theme={null}
npx tsx support.ts
```

## Verify the result

You should see a `lookup_order` diagnostic and incremental response text reporting Friday. Providers can buffer chunks, so visible token-by-token timing varies.

Consume the iterator until it ends. A `finish` chunk can finish one model call while the Agent still has tools to run. Do not break the loop on the first finish chunk.

An iterator error must reach your request handler. On an HTTP disconnect, abort the run and release the iterator; cancellation does not undo a tool that already completed. Read the [execution lifecycle](/learn/execution) and [observability guide](/observability/overview) before connecting logs to an external destination.

<Card title="Expose an HTTP API" icon="arrow-right" href="/learn/http">Continue to the next chapter.</Card>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.