Agent SDK
Drive Halo from your own programs and agents, with the same safety checks as the shell.
The SDK packages are not on npm, PyPI or crates.io yet. Install them from
github.com/memcode-ai/halo-client as shown below.
The halo-sdk package on PyPI is an unrelated project: don't install it.
The Agent SDK lets a program use Halo the way a person does at the prompt. You send a request in words and get a typed outcome back.
The SDK drives the Halo you already have installed. It needs no separate runtime, daemon or service, and no extra sign-in: it uses your Halo sign-in.
Halo applies the same checks and approvals as in the shell. Your program only answers the questions Halo asks, such as whether to approve a change.
How it fits together
Your application
│
│ one Halo client
▼
one local Halo process
│
├── session A (a conversation)
├── session B
└── session CCreate one Halo client for your application and reuse it. Creating a session does not launch another Halo process. Open a session per conversation, run as many requests in it as you like, and close it when the conversation is over.
Connecting and opening sessions happen on your machine. Only a request that Halo needs to interpret contacts the Halo service.
Install
| Language | Install |
|---|---|
| Go | go get github.com/memcode-ai/halo-client/sdk/go |
| TypeScript | git clone https://github.com/memcode-ai/halo-client then npm install ./halo-client/sdk/typescript |
| Python | pip install "halo-sdk @ git+https://github.com/memcode-ai/halo-client#subdirectory=sdk/python" (import halo_sdk) |
| Rust | cargo add halo-sdk --git https://github.com/memcode-ai/halo-client (it uses tokio) |
Each needs the halo command on your PATH (Installation), signed in with halo login.
Quick start
c, err := halo.Connect(ctx, halo.ClientOptions{}) // once, when your program starts
if err != nil {
log.Fatal(err)
}
defer c.Close()
s, err := c.NewSession(ctx, halo.SessionOptions{Cwd: "/path/to/project"})
if err != nil {
log.Fatal(err)
}
defer s.Close(ctx)
out, err := s.Run(ctx, "what is using port 5432?")
if err != nil {
log.Fatal(err)
}
fmt.Println(out.Kind, out.Message)What you can build
A session understands the same requests as the Halo shell, so one call covers questions about the machine, its files and data, calculations, and changes that wait for approval.
- On-call and ops bots. "what is using port 5432?", "why won't postgres start?", "show errors from the last hour in worker.log", answered with typed rows your bot can format.
- Data questions in your app. "average latency by endpoint in requests.csv", "how many rows in orders.csv have an amount over 1000": a table or a single number back, computed locally.
- Checks in CI. Run the project's tests or build, or ask which branches are merged, in plan mode or with read-only approvals.
- Agents that act on a machine. Give a coding or support agent a way to inspect and change a machine where every change goes through your approval handler.
const outcome = await session.run("average latency by endpoint in requests.csv");
switch (outcome.kind) {
case "answer": // a single value: "125.66 lb", "x = 4", "3"
console.log(outcome.message);
break;
case "result": // what ran and what it returned, typed
for (const row of outcome.result.rows ?? []) console.log(row.endpoint, row["avg latency"]);
break;
case "question":
case "choice": // Halo needs a detail: ask your user, then run their reply in the same session
console.log(outcome.message);
break;
default: // unsupported, denied, declined, cancelled
console.log(outcome.kind, outcome.message);
}In a server
Connect once at startup and share the client across every request handler. Keep a session per conversation. Creating a client per request starts a new Halo process each time; Halo warns when it sees that pattern.
import { createServer } from "node:http";
import { Halo, type HaloSession } from "@memcode-ai/halo";
const halo = await Halo.connect(); // once, when the server starts
const sessions = new Map<string, HaloSession>(); // one session per conversation
createServer(async (req, res) => {
const conversation = String(req.headers["x-conversation-id"] ?? "default");
let session = sessions.get(conversation);
if (!session) {
session = await halo.session({ cwd: "/path/to/project" });
sessions.set(conversation, session);
}
let text = "";
for await (const chunk of req) text += chunk;
const outcome = await session.run(text);
res.setHeader("content-type", "application/json");
res.end(JSON.stringify({ kind: outcome.kind, message: outcome.message }));
}).listen(8080);The Agent SDK controls the machine and account Halo runs on. Never pass untrusted users' requests to a Halo session on your own machine or server. A service that takes requests from other people must run each user's Halo in its own container or VM. Rate limits and permission modes do not make forwarding internet input safe.
A session lasts until you close it or the client closes. If you want sessions to end on their own, set an idle
timeout when you open them (idleTimeout / idle_timeout); there is none by default.
Outcomes
Every request ends with exactly one outcome or a typed error.
kind | Meaning |
|---|---|
answer | a direct answer (message) |
result | something ran; result holds what it returned, authorization says how it was allowed |
question / choice | Halo needs a detail, or the request had more than one meaning |
proposed | plan mode: what Halo would do, with nothing run |
denied / declined | not allowed by the session's settings, or refused by your program |
unsupported | understood, but not something Halo does yet |
cancelled | the request was cancelled |
Follow-ups like "kill it" or "only the PDFs" refer to what came before in the same session, just as in the shell. Sessions never share context with each other.
Permissions
A session starts with no permissions inherited from your interactive Halo. You choose them when you open it.
const session = await halo.session({
cwd: "/path/to/project",
permissionMode: "acceptEdits", // default | dontAsk | acceptEdits | plan | bypassPermissions
allowedOperations: ["git.*"], // pre-approved
disallowedOperations: ["files.delete"], // always denied, in every mode
});The other languages use the same options: PermissionMode in Go, and permission_mode in Python and Rust.
- Default. Anything that needs approval is denied unless your program answers approvals.
- Disallowed operations always win. This holds in every mode,
bypassPermissionsincluded. A disallowed operation is never proposed: Halo answersdeniedinstead of planning around it. - Some protections are never bypassed. The most dangerous actions each need their own explicit setting.
Naming operations
Both lists take operation names in three forms:
| pattern | matches |
|---|---|
files.delete | exactly that operation |
git.* | every operation in the git family |
* | every operation |
Every operation is family.action. The name of what Halo did or would do is in each outcome's operation field, so
run a request in plan mode to learn the name before you allow or deny it. The families: appearance, apps,
archive, audio, battery, bluetooth, clipboard, compose, containers, content, data, db,
diagnose, dirs, disk, display, docker, env, files, git, gpu, http, image, images, links,
logs, media, net, network, notify, packages, pdf, pkg, ports, processes, programs, project,
runtime, runtimes, schedule, scripts, security, services, ssh, startup, storage, system, text,
venv. Interactive Halo's /capabilities shows the same families with example requests.
A common shape is read-only automation: allowedOperations: ["*"] with disallowedOperations naming the writes you
never want (files.delete, files.move, git.push, processes.signal, services.restart, containers.*), or the
reverse, allowedOperations: ["git.*", "files.list"] and nothing else pre-approved.
Approvals, choices and offers
To have Halo ask instead of deny, give the client an interactor:
type reviewer struct{}
func (reviewer) Approve(ctx context.Context, r halo.ApprovalRequest) halo.Approval {
if r.Effect == "READ" {
return halo.Approval{Decision: halo.DecisionAllow}
}
return halo.Approval{Decision: halo.DecisionDeny, Message: "only reads in this job"}
}
func (reviewer) Choose(ctx context.Context, r halo.ChoiceRequest) (int, bool) { return 0, false } // cancel
func (reviewer) Offer(ctx context.Context, r halo.OfferRequest) bool { return false }
func connectReviewed(ctx context.Context) (*halo.Client, error) {
return halo.Connect(ctx, halo.ClientOptions{Interactor: reviewer{}})
}An approval can allow, allow for the rest of the session (allow_session), or deny. It cannot change the operation
it approves. To do something different, deny it and ask again in words.
Pinning the Halo model
A Halo model determines how Halo understands requests. Pin a model when reproducibility matters.
- IDs are stable. A model ID always behaves the same way.
- Halo never retargets a session, and a model that isn't available fails with
model_not_availableinstead of falling back to another. - Updates don't change it. Updating Halo or the SDK never changes which model you selected.
See Models.
s, err := c.NewSession(ctx, halo.SessionOptions{Model: "halo-solstice-preview"})
if err != nil {
log.Fatal(err)
}
fmt.Println("pinned to", s.Model())Errors
Failures that are not outcomes are typed errors with a code:
code | Meaning |
|---|---|
not_signed_in | run halo login |
model_not_available | the requested Halo model is not available |
version_mismatch | the installed Halo is too old for this SDK; run halo upgrade |
turn_in_progress | one request at a time per session (open another session for parallel work) |
unknown_session | the session was closed |
halo_exited | the Halo process ended |
rate_limit, capacity_unavailable | try again later (retryable, retry_after_ms) |