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

# Live messages

> Stream the agent's messages in real time to build custom UIs or monitor progress.

<Note>
  Want a ready-made UI? See the [Chat UI tutorial](/cloud/tutorials/chat-ui).
</Note>

Stream messages as the agent works — reasoning, tool calls, browser actions, and results. Each message has `role`, `type`, `summary`, `data`, and `screenshot_url`. See [List session messages](/cloud/api-v3/sessions/list-session-messages) for all fields.

<CodeGroup>
  ```python Python theme={null}
  from browser_use_sdk.v3 import AsyncBrowserUse

  client = AsyncBrowserUse()

  run = client.run("Find the top story on Hacker News")
  async for msg in run:
      print(f"[{msg.role}] {msg.summary}")

  print(run.result.output)
  ```

  ```typescript TypeScript theme={null}
  import { BrowserUse } from "browser-use-sdk/v3";

  const client = new BrowserUse();

  const run = client.run("Find the top story on Hacker News");
  for await (const msg of run) {
    console.log(`[${msg.role}] ${msg.summary}`);
  }

  console.log(run.result.output);
  ```
</CodeGroup>

```
[user] Find the top story on Hacker News
[assistant] Navigating to https://news.ycombinator.com/
[tool] Browser Navigate: Navigated
[assistant] Analyzing browser state
[tool] Browser Analyze State: The top story is "Coding Agents Could Make Free Software Matter Again"
[tool] Done Autonomous: The top story on Hacker News is "Coding Agents Could Make Free Software Matter Again"
```

## Cancel a running task

Use `stop(strategy="task")` to cancel the current task without destroying the session. The session goes back to `idle` and can accept a new task.

<CodeGroup>
  ```python Python theme={null}
  run = client.run("Find the top story on Hacker News")
  async for msg in run:
      if should_cancel():
          await client.sessions.stop(run.session_id, strategy="task")
          break
  # Session is now idle — send a different task or close it
  ```

  ```typescript TypeScript theme={null}
  const run = client.run("Find the top story on Hacker News");
  for await (const msg of run) {
    if (shouldCancel()) {
      await client.sessions.stop(run.sessionId!, { strategy: "task" });
      break;
    }
  }
  // Session is now idle — send a different task or close it
  ```
</CodeGroup>

<Warning>
  `run.result` is only available **after** the iterator finishes (all messages consumed or task completes). If you break early from `async for` / `for await`, the task may still be running — call `stop(strategy="task")` to cancel it before sending a follow-up.
</Warning>

## Manual polling

If you need full control over the polling loop (e.g. custom interval, filtering):

<CodeGroup>
  ```python Python theme={null}
  import asyncio
  from browser_use_sdk.v3 import AsyncBrowserUse

  client = AsyncBrowserUse()
  session = await client.sessions.create(task="Find the top story on Hacker News")

  cursor = None
  while True:
      msgs = await client.sessions.messages(session.id, after=cursor, limit=100)
      for m in msgs.messages:
          print(f"[{m.role}] {m.summary}")
          cursor = m.id

      s = await client.sessions.get(session.id)
      if s.status.value in ("idle", "stopped", "error", "timed_out"):
          break
      await asyncio.sleep(2)

  print(s.output)
  ```

  ```typescript TypeScript theme={null}
  import { BrowserUse } from "browser-use-sdk/v3";

  const client = new BrowserUse();
  const session = await client.sessions.create({
    task: "Find the top story on Hacker News",
  });

  let cursor: string | undefined;
  while (true) {
    const msgs = await client.sessions.messages(session.id, { after: cursor, limit: 100 });
    for (const m of msgs.messages) {
      console.log(`[${m.role}] ${m.summary}`);
      cursor = m.id;
    }

    const s = await client.sessions.get(session.id);
    if (["idle", "stopped", "error", "timed_out"].includes(s.status)) {
      console.log(s.output);
      break;
    }
    await new Promise((r) => setTimeout(r, 2000));
  }
  ```
</CodeGroup>

## Related

* [Live preview & recording](/cloud/browser/live-preview) — embed the browser alongside your message stream
* [Follow-up tasks](/cloud/agent/follow-up-tasks) — chain multiple tasks in one session while streaming each
