[Agents API]
[PyPI]
[Python versions]
[License: MIT]
Python SDK for H Company's Agents API.
Documentation
·
Get an API key
·
PyPI
·
TypeScript SDK
·
H Company
Contents
Installation
Python 3.10 or newer is required.
Quickstart: command line
holo login signs you in with Google in the browser, or takes a key you paste with holo login --key, and stores it in ~/.config/hai/.env. Any command does the same on first use in a terminal, so this step is optional. The task then runs on a hosted agent with its own browser: its steps stream to your terminal, and its answer prints at the end. In a terminal you can follow up on the same session, or run holo alone to start an interactive session.
Quickstart: Python
Get an API key at platform.hcompany.ai/settings/api-keys and export it, or run holo login once:
Launch the built-in h/web-surfer-pro agent, which ships with its own browser, and describe the task in plain language. run_session polls until the agent finishes and returns the final answer.
Client() reads HAI_API_KEY from the environment, else the key holo login stored in ~/.config/hai/.env.
result is a SessionRunResult: id, status, answer, the accumulated events, and final_changes.
Command line
The cli extra installs the holo command, also available as hai.
Tasks run on h/web-surfer-flash unless you pass --agent or set a default with holo agents use. Run holo --help, or holo <command> --help, for every option.
~/.holo/agents.md joins the instructions of every agent holo runs, and ~/.holo/skills/<name>/SKILL.md joins its skills.
Interactive sessions
holo in a terminal opens a session you talk to in plain words. Each message continues the same session, with its browser and context, until you start fresh with /new.
An agent that drives this desktop, like h/holo-desktop, uses your mouse and keyboard, so typing goes to your apps instead: press esc twice, from any app, to stop it.
Commands
Scripts and CI
Scripts never prompt. Set HAI_API_KEY, or pipe a key into holo login --key, then use --json for machine-readable output or -q for the answer alone:
--json prints session_id, status, answer, outcome, error, error_code, and agent_view_url. The exit code is 0 when the session completes and 1 otherwise.
Credentials resolve from --api-key, then HAI_API_KEY, then ~/.config/hai/.env.
Python SDK guides
How a session works
A session is one run of an agent against a task. It moves through a small set of states: pending, running, and then a settled state such as completed, idle, failed, timed_out, or interrupted.
You drive a session two ways. run_session creates it and blocks until it settles, which suits one-shot tasks. start_session creates it and returns a handle right away, so you can read and steer the agent while it works.
Watch and steer a running session
A handle bound to the session id exposes the full lifecycle. Read the agent's progress at three levels of detail:
status() is a cheap snapshot with the state, step count, and token usage. changes(from_index=0) long-polls for new events and the final answer. get() returns the full Session resource.
While the session is not in a terminal state, you can intervene:
send_message redirects the agent on its next step and wakes an idle session. pause halts with state preserved until resume. force_answer makes the agent stop exploring and answer from what it has. cancel ends the session as interrupted.
Multi-turn sessions
By default a session ends as soon as the agent answers. Set idle_timeout_s to keep it open: after each answer the session goes idle and waits that long for your next message, carrying its full context and browser state across turns.
Structured output
Pass a pydantic model as answer_schema and the agent's final answer comes back as a validated instance. The model's JSON schema is sent as the agent's answer format; the raw wire value stays at result.final_changes.answer.
A completed answer that does not match the schema raises AnswerValidationError, with the raw payload on .raw. Sessions that end without completing return their raw answer untouched.
Custom tools
Expose your own Python functions to the agent. Pass them to run_session and the polling loop runs each one when the agent calls it, then posts the result back so the session continues. Any function with typed parameters and a docstring works; the input schema is derived from the signature.
Use the @tool decorator to override the name or description:
A tool that raises is reported to the agent as a tool error rather than crashing the run. With AsyncClient, tools may be async def.
Prebuilt: one-time passwords (2FA)
hai_agents_tools ships ready-made tools. otp_tool lets the agent ask for a one-time password, verification code, or confirmation link when a login or signup step needs one. Without a handler it prompts on stdin; imap_otp_handler reads the code straight from a mailbox over IMAP (for Gmail, use an app password).
Like every custom tool, the handler runs entirely in your process: the IMAP credentials never leave your machine, and the agent only receives the single extracted code or link -- never mailbox contents.
Browser profiles and vaults
Start a session on a browser that already knows the user. A browser profile restores saved cookies and storage from an earlier session, and a vault lets the agent sign in to sites with secrets that never enter its context. Bind both through per-run overrides:
Async
AsyncClient mirrors Client for asyncio. Every session method is a coroutine.
Local agents
Client.local() and await AsyncClient.local() run the agent on this machine through a local agent runtime,
started on demand or passed in with runtime=.... A desktop is this machine; a browser picks host="user_device" or
host="cloud".
Client() keeps using the hosted Agents API. Closing the client stops a runtime it started, unless other clients still
have active sessions there.
Inference stays hosted (HAI_API_KEY) unless you pass inference=Inference.self_hosted(url, model=...)
(from hai_agents_local.runtime import Inference).
One agent drives this machine's desktop at a time: a second process asking for a desktop bridge fails fast instead of
sharing the mouse. holo local stop stops every local turn on the machine; so does a double Esc
once hai_agents_local.killswitch.arm_esc_listener() is armed (macOS, Windows, and X11 Linux).
Code on this machine
A desktop in shell mode gives the agent a shell on this machine. It runs commands, edits files and writes code in a
folder, and drives the screen from the same shell when a result only shows in a window.
Without HAI_SHELL_WORKSPACE the agent works in a folder of its own, ~/hai/<session id>. With
command_approval: "required", holo asks before each command your allowlist does not cover: y runs it, a runs it
and always allows it, n refuses. From code, read result.pending_approvals and answer with session.approve(call_id)
or session.deny(call_id, message).
On macOS every command runs inside Anthropic's sandbox-runtime,
downloaded on the first session: it writes in the workspace only, reaches the Python and npm registries, and cannot
read your credentials. On Linux and Windows the sandbox is off until you install it. The
guide covers both.
Inspect and share sessions
List past sessions and create a public replay link:
Regions and configuration
The client targets the EU region by default; pass environment to use the US region instead:
Client also accepts a custom base_url, and an api_key when you do not want to use the environment variable:
Errors
ApiError is the base for HTTP failures and carries .status_code and .body. UnprocessableEntityError is the 422 raised when a request fails validation. AnswerValidationError is raised when a completed answer does not match answer_schema, with the unparsed value on .raw.
Webhooks
Verify the signature on an incoming webhook before trusting it:
Documentation
Guides, core concepts, and the full API reference live at hub.hcompany.ai/agents-api.
License
MIT