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

> ## Agent Instructions
> H Platform has three products: the Agents API (managed computer-use agents, base URL https://agp.eu.hcompany.ai/api/v2 or https://agp.hcompany.ai/api/v2 for the US), the Models API (OpenAI-compatible Holo vision-language models at https://api.hcompany.ai/v1), and HoloTab (a free no-code Chrome extension that runs Holo in the user's browser, with recordable routines and schedules). The `holo` CLI (`pip install "hai-agents[cli]"`) runs Agents API agents from a terminal, drives the user's own desktop with `-a h/holo-desktop`, and serves coding agents through `holo mcp`.
> Authenticate with a bearer API key from the HAI_API_KEY environment variable. SDKs: `pip install hai-agents` (Python, `from hai_agents import Client`) and `npm install hai-agents` (TypeScript, `import { HaiAgentsClient } from "hai-agents"`). CLI: `holo`.
> Agents do work in a browser or on a desktop; describe the task as an imperative instruction. To run a task quickly, prefer the pre-built agent `h/web-surfer-flash`. Read results from the session's `latest_answer` after it reaches a terminal status.
> Sessions are the unit of work; wait for a terminal status (completed, failed, timed_out, interrupted) before reading the answer. Use webhooks or the `changes` long-poll endpoint to follow progress.

# Watch and steer

> Follow a session live and redirect the agent while it works.

## Agent View

Every session shows up in **Agent View** on the [H Platform](https://platform.hcompany.ai/?product=computeruseagents\&source=docs), and its `agent_view_url` links straight there. Watch it live, or replay it after. Agent View reads the same [`events`](https://hub.hcompany.ai/agents-api/sessions/events) stream as your code.

## Watch a session

A blocking call (`run_session` / `runSession`) returns only at the end. To read or intervene while it works, start the session and keep its handle. Then stream its events, or block until it settles:

```bash CLI theme={"system"}
holo sessions watch "$SESSION_ID"   # stream events until the session settles
```

```python Python theme={"system"}
from hai_agents import Client

client = Client()
session = client.start_session(
    agent="h/web-surfer-flash",
    messages=[{"type": "user_message", "message": "Find the top story on Hacker News"}],
)

for event in session.stream():  # `async for` with the async client
    print(event.type)

result = session.wait_for_completion()  # block until it settles
print(result.status, result.answer)
```

```typescript TypeScript theme={"system"}
import { HaiAgentsClient } from "hai-agents";

const client = new HaiAgentsClient();
const session = await client.startSession({
  agent: "h/web-surfer-flash",
  messages: [{ type: "user_message", message: "Find the top story on Hacker News" }],
});

for await (const event of session.stream()) {
  console.log(event.type);
}

const result = await session.waitForCompletion(); // block until it settles
console.log(result.status, result.answer);
```

### Stream events as they arrive

The SDK handle's `stream()` runs the [`changes`](https://hub.hcompany.ai/agents-api/sessions/changes) long-poll loop for you and yields each [event](https://hub.hcompany.ai/agents-api/sessions/event-object.md) in order.

* It stops when the session settles: a [terminal state](https://hub.hcompany.ai/agents-api/sessions/overview.md#lifecycle), or `idle`. Pass `until="terminal"` to keep it open across the idle turns of an [interactive session](#hold-an-interactive-conversation).
* With [custom tools](https://hub.hcompany.ai/agents-api/custom-tools.md), it answers their calls: after each batch of events, it runs the calls the agent is waiting on and posts the results. It uses the tools the handle was started with, or the `tools` you pass.
* Without tools it is read-only, so another process can answer the calls while you watch.

```python Python theme={"system"}
for event in session.stream(tools=[get_order_status]):  # also answers tool calls
    print(event.type)
```

```typescript TypeScript theme={"system"}
for await (const event of session.stream({ tools: [getOrderStatus] })) {
  // also answers tool calls
  console.log(event.type);
}
```

A handle's `stream` and `wait_for_completion` share its tools and run each call once between them. Loops on separate handles or processes don't coordinate: give tools to one of them only, or a call can run twice.

### Get the files the agent sends

The agent sends each file once it is final, mid-run, as an [`AttachmentEvent`](https://hub.hcompany.ai/agents-api/sessions/event-object#event-types-type) with `origin: "agent"`. [Download it](https://hub.hcompany.ai/agents-api/sessions/resources.md#download-a-shared-file) by its `file_id`:

```python Python theme={"system"}
for event in session.stream():
    if event.type == "AttachmentEvent" and event.data.origin == "agent":
        with open(event.data.name, "wb") as out:
            for chunk in client.session_files.download_file(event.data.file_id):
                out.write(chunk)
```

```typescript TypeScript theme={"system"}
import { writeFileSync } from "node:fs";
import type { HaiAgents } from "hai-agents";

for await (const event of session.stream()) {
  if (event.type !== "AttachmentEvent") continue;
  const data = event.data as HaiAgents.AttachmentData;
  if (data.origin === "agent" && data.fileId) {
    const file = await client.sessionFiles.downloadFile({ fileId: data.fileId });
    writeFileSync(data.name, Buffer.from(await file.arrayBuffer()));
  }
}
```

`file_id` is set on hosted sessions; in [local mode](https://hub.hcompany.ai/agents-api/local-runtime.md), download by `url`. Files the agent leaves in a cloud browser's `~/Downloads` without sending stay reachable through [list files](https://hub.hcompany.ai/agents-api/sessions/list-files.md) and [read file](https://hub.hcompany.ai/agents-api/sessions/read-file.md) while the browser runs.

### Read the raw state

| Read | Returns | Use it to |
| - | - | - |
| [`status`](https://hub.hcompany.ai/agents-api/sessions/status) | Current [state](https://hub.hcompany.ai/agents-api/sessions/overview.md#lifecycle), step count, token usage | Poll as a cheap health check |
| [`changes`](https://hub.hcompany.ai/agents-api/sessions/changes) | New events past an index, plus the final `answer`, long-polled | Follow an active session by its [polling rules](https://hub.hcompany.ai/agents-api/sessions/changes.md#polling-rules) |
| [`events`](https://hub.hcompany.ai/agents-api/sessions/events) | The full, paginated record | Replay or audit after the fact |

```bash CLI theme={"system"}
holo sessions status "$SESSION_ID"
```

```python Python theme={"system"}
session.status()               # cheap snapshot
session.changes(from_index=0)  # new events + final answer, long-polled
session.get()                  # the full Session resource
```

```typescript TypeScript theme={"system"}
await session.status();                  // cheap snapshot
await session.changes({ fromIndex: 0 }); // new events + final answer, long-polled
await session.get();                     // the full Session resource
```

```bash cURL theme={"system"}
curl "https://agp.eu.hcompany.ai/api/v2/sessions/$SESSION_ID/status" -H "Authorization: Bearer $HAI_API_KEY"
curl "https://agp.eu.hcompany.ai/api/v2/sessions/$SESSION_ID/changes?from_index=0&wait_for_seconds=25" -H "Authorization: Bearer $HAI_API_KEY"
curl "https://agp.eu.hcompany.ai/api/v2/sessions/$SESSION_ID/events?size=50" -H "Authorization: Bearer $HAI_API_KEY"
```

## Steer a running agent

A real session, redirected mid-task with one message:

While the session runs, you can:

| Action | Effect |
| - | - |
| [Send a message](https://hub.hcompany.ai/agents-api/sessions/send-messages.md) | Adds context or redirects the agent. The agent picks it up on the next step. Wakes an `idle` session and auto-resumes a `paused` one. |
| [Pause](https://hub.hcompany.ai/agents-api/sessions/pause.md) / [Resume](https://hub.hcompany.ai/agents-api/sessions/resume.md) | Halts the agent with its state preserved, then continues. |
| [Force an answer](https://hub.hcompany.ai/agents-api/sessions/force-answer.md) | The agent stops exploring and answers from what it has. |
| [Cancel](https://hub.hcompany.ai/agents-api/sessions/cancel.md) | Stops the agent. It ends `interrupted`. |
| [Approve or deny](https://hub.hcompany.ai/agents-api/sessions/tool-approvals.md) | Decides a call the agent holds for you, such as a [shell command](https://hub.hcompany.ai/agents-api/your-desktop.md#approve-commands). |

```bash CLI theme={"system"}
holo sessions send "$SESSION_ID" "Only consider results from the last 24 hours"
holo sessions cancel "$SESSION_ID" --yes
```

```python Python theme={"system"}
session.send_message({"type": "user_message", "message": "Only consider results from the last 24 hours"})
session.pause()
session.resume()
session.force_answer()
session.cancel()
session.approve(call_id)       # or session.deny(call_id, "Do not push.")
```

```typescript TypeScript theme={"system"}
await session.sendMessage({ type: "user_message", message: "Only consider results from the last 24 hours" });
await session.pause();
await session.resume();
await session.forceAnswer();
await session.cancel();
await session.approve(callId);  // or session.deny(callId, "Do not push.")
```

```bash cURL theme={"system"}
API=https://agp.eu.hcompany.ai/api/v2/sessions/$SESSION_ID
AUTH="Authorization: Bearer $HAI_API_KEY"

curl -X POST "$API/messages" -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"type": "user_message", "message": "Only consider results from the last 24 hours"}'
curl -X POST "$API/pause" -H "$AUTH"
curl -X POST "$API/resume" -H "$AUTH"
curl -X POST "$API/force_answer" -H "$AUTH"
curl -X DELETE "$API" -H "$AUTH"   # cancel
```

## Hold an interactive conversation

By default a session ends when the agent answers. Set [`idle_timeout_s`](https://hub.hcompany.ai/agents-api/sessions/create) at create time to keep it open: after each answer it goes [`idle`](https://hub.hcompany.ai/agents-api/sessions/overview#lifecycle) and waits that long for your next message, keeping its context and environment across turns. It terminates once a turn goes unanswered for `idle_timeout_s`.

```python Python theme={"system"}
session = client.start_session(
    agent="h/web-surfer-flash",
    idle_timeout_s=600,
    messages=[{"type": "user_message", "message": "Find the top story on Hacker News"}],
)
print(session.wait_for_completion().answer)
session.send_message({"type": "user_message", "message": "Now open its comments and summarize the discussion"})
```

```typescript TypeScript theme={"system"}
const session = await client.startSession({
  agent: "h/web-surfer-flash",
  idleTimeoutS: 600,
  messages: [{ type: "user_message", message: "Find the top story on Hacker News" }],
});
console.log((await session.waitForCompletion()).answer);
await session.sendMessage({ type: "user_message", message: "Now open its comments and summarize the discussion" });
```

```bash cURL theme={"system"}
SESSION_ID=$(curl -sX POST https://agp.eu.hcompany.ai/api/v2/sessions \
  -H "Authorization: Bearer $HAI_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "agent": "h/web-surfer-flash",
    "idle_timeout_s": 600,
    "messages": [{"type": "user_message", "message": "Find the top story on Hacker News"}]
  }' | jq -r .id)

# Once it answers and goes idle, follow up in the same context
curl -X POST "https://agp.eu.hcompany.ai/api/v2/sessions/$SESSION_ID/messages" \
  -H "Authorization: Bearer $HAI_API_KEY" -H "Content-Type: application/json" \
  -d '{"type": "user_message", "message": "Now open its comments and summarize the discussion"}'
```


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