Hai agents

From hcompai/computer-use-agents-demos · View interactive version

Hai agents is an AI agent skill from the GitHub repository hcompai/computer-use-agents-demos. Expert knowledge of the two H Company backends — the portal (portal, API at portal.api.eu.hcompany.ai / portal.production.hcompany.ai — auth, organizations, API keys, invitations, billing) and the agent platform v2 API (agp.hcompany.ai — sessions, agents, skills, environments, vaults, long-polling,

How to use this skill

Skill file

H Company APIs (portal + agent platform)

H runs two backends, joined by one key. Figure out which you need — then read the live docs, don't answer from this file's memory. This skill is a router and a key-bootstrapper, not a copy of the docs: it deliberately holds almost no endpoint/param/field/limit/model detail, because hardcoding that here goes stale and has repeatedly been wrong.

| You're touching… | Backend | Base URL | Source of truth |

|---|---|---|---|

| Users, orgs, API keys, invitations, billing, STT | Portal | EU https://portal.api.eu.hcompany.ai/api · US https://portal.production.hcompany.ai/api | no public docs → references/portal/ |

| Running agents: sessions, agents, skills, environments, vaults, events/long-poll, SDK, MCP | Agents API (agp) | EU (default) https://agp.eu.hcompany.ai/api · US https://agp.hcompany.ai/api | live docs + swagger (below) |

The hk-… key is created on the portal (by a logged-in user) and consumed by agp (Authorization: Bearer hk-…). "Get a key" → portal; "use a key" → agp. The full value is shown only once at creation — to "retrieve" one, make a new key and revoke the old.

https://platform.hcompany.ai is the product frontend (API-keys UI at /settings/api-keys), not an API.

Before anything on agp: fetch the live docs index

Start every agp task by fetching the live docs index. Find the pages for your task and fetch their .md URLs. Use the live index rather than a bundled copy so renamed and newly added pages stay discoverable. If the index is unavailable, use the OpenAPI for request and response shapes; don't guess model or agent ids.

Two anchors the index points into, worth calling out:

Get a key into .env (the one thing the docs can't do for you)

python scripts/h_login.py            # desktop PKCE flow → writes HAI_API_KEY into ./.env; no-op if already set
python scripts/h_login.py --force    # rotate/replace; also --region us|eu (default eu), --env-file, --key-name, --no-rotate

Opens the browser (one Google click), exchanges the code, picks the org, writes .env (chmod 600). Headless fallback and full portal auth details: references/portal/auth.md.

The SDK reads the HAI_API_KEY environment variable, not the .env file. A key freshly written to .env still gives ApiError: ... setting HAI_API_KEY until it's loaded into the environment (source .env or equivalent — and since each Bash call is a fresh shell, do it in the same command as the Python). Classic false alarm: the key is fine, it's just not exported.

Using the hai-agents SDK

Prefer the SDK over hand-rolled HTTP — but the SDK's shape is not the HTTP shape, so introspect the installed package instead of guessing. Its module layout, the session handle's surface, and several field names diverge from the wire; guessing them is the single biggest source of crashes, and nothing I write here would stay accurate. One line settles it:

python3 -m venv .hai-venv && .hai-venv/bin/pip install -q hai-agents   # `pip` is often absent and system pythons are externally-managed (PEP 668); a venv sidesteps both
.hai-venv/bin/python -c "import hai_agents, inspect; print(dir(hai_agents)); print(inspect.signature(hai_agents.run_session))"   # dir()/signature() need no key

Pure dir()/inspect.signature() introspection needs no key, but the moment you instantiate a Client() or list the agent catalog you do — so load .env first (see above), or you'll waste round-trips chasing a phantom HAI_API_KEY error.

Package surfaces (versions, examples): PyPI / npm. Both default to the EU endpoint — set base_url for US.

The trap the docs won't warn you about

The task goes in messages, never in instructions. instructions is the system prompt — who the agent is and its guardrails; messages is what to do now. A session created with rich instructions but no message starts, immediately flips to idle, and does nothing — which reads like a dead platform but is just a missing message. (Easiest path: use a pre-built h/ agent — the environment, model, and instructions are already wired and you only supply the message. But never guess an agent id — list the catalog first with GET /api/v2/agents (SDK: client.agents.list_agents()) and pick from the result; an invented h/... name just 404s.)

Show the user the run — offer to open it

When a runnable script is ready, don't end with a prose "Want me to run it?" buried under a wall of explanation — put a clean yes/no choice in front of the user (an explicit prompt / choice, not an open question they have to answer in free text). The decision is theirs, but make saying yes a single tap.

The instant they say yes, hand them the agent-view (replay) link. Don't disappear into a long blocking run and surface the link at the end — surfacing it after the fact is the failure. Create the session, print the link, and offer to open it first thing, then let the run proceed (see ordering below).

The agent-view link is deterministic from the session id, which you have the instant you create the session — long before the run finishes. The whole point is to let the user watch live, so the link has to reach them while the agent is still working.

The trap that defeats this: wait_for_session / run_session blocks for the entire run, and you only see a command's stdout when it returns. So if you create the session and block inside one foreground command, the link doesn't surface until the run is already over — which is exactly the after-the-fact replay you're trying to avoid. The fix is structural: the create+link step must hand control back to you before the long wait begins. Two ways:

Either way, build the URL yourself from the id (https://<host>/agent-view/{id}) — don't scrape it from stdout, and don't busy-loop grep-ing a log file for agent-view/ (that just hangs).

The host must match the region you called, and these APIs default to EU — so the link is usually https://platform.eu.hcompany.ai/agent-view/{id}; only US sessions use https://platform.hcompany.ai/agent-view/{id}. Don't hand an EU session a bare platform.hcompany.ai link — it points at the wrong region's UI and the run won't be there.

Deeper UI/UX notes (deep-linking, sharing outside the org): references/extras/agent-view-replay.md.

Something broken? Report it to support@hcompany.ai

If agp behaves differently than the docs say — unexplained 5xx, a session stuck with no events, a key rejected right after creation — write the report for the user: region + host, exact endpoint + method, full response (status, detail, headers like ETag/Retry-After), UTC timestamp, session id + agent-view link, expected vs observed, minimal repro. Never include hk- keys or tokens. Then offer a pre-filled mailto:support@hcompany.ai (or a draft via a connected mail tool) — the user hits Send, not you.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.