Skip to main content
Want a ready-made UI? See the Chat UI tutorial.
Poll sessions.messages() while a task runs to get the agent’s reasoning, tool calls, and results.
import asyncio
from browser_use_sdk.v3 import AsyncBrowserUse

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

seen = set()
while True:
    msgs = await client.sessions.messages(session_id, limit=100)
    for m in msgs.messages:
        if str(m.id) not in seen:
            seen.add(str(m.id))
            print(f"[{m.role}] {m.data[:200]}")

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

# Final output
print(s.output)
Each message has a role (user, assistant, tool), a summary for display, and a type (e.g. browser_action, browser_action_result). Browser action results include a screenshot_url. See List session messages for all fields.