# Agents The agents extension exposes session relationships and operations to Python code. Its routes are implemented by [`agents/extension.gleam`](../src/albedo/harness/extensions/agents/extension.gleam), with daemon operations in [`daemon/agents.gleam`](../src/albedo/daemon/agents.gleam). Each agent is a session. See [session attachment](sessions.md). ## Starting agents The [Python binding](../priv/python/albedo_plugins/agents.py) exposes `agents.start` for a root peer and `agents.self.spawn` for a child. Both return an `Agent` handle. Spawn also accepts a verifier and cyber access choice. The host rejects an empty task or model, validates the name, and limits the verifier to 4096 Unicode scalars. [`dispatch`](../src/albedo/harness/extensions/agents/extension.gleam) passes the request to the daemon. [`with_worktree`](../src/albedo/harness/extensions/agents/extension.gleam) handles the requested workspace before starting an agent. A workspace and its files are shared resources unless the chosen worktree gives the agent a separate directory. ## Relationships and operations `agents.self` is the caller's handle. `agents.get` resolves another handle. A handle's `children` and `siblings` methods report family state, while `switch`, `close`, and `cancel` operate on an owned target. `agents.models` asks for available models. `agents.cancel_all` can include descendants. See the [Python binding](../priv/python/albedo_plugins/agents.py) and [`service.act` and `stop_all`](../src/albedo/harness/extensions/agents/service.gleam). `agents.set_role` permits changing the caller's role or that of an owned child or peer. Only a child's parent can call `child.set_verifier`. `agents.progress` publishes a nonempty status of at most 512 Unicode scalars. These checks are in [`dispatch`](../src/albedo/harness/extensions/agents/extension.gleam). ## Messages and resources An `Agent` handle's `messages` method reads its transcript with sequence and pagination arguments. `search_messages` searches that transcript. `agents.sessions` searches sessions and clamps its result limit to 1 through 100. See the [Python binding](../priv/python/albedo_plugins/agents.py) and [`agents/sessions.gleam`](../src/albedo/harness/extensions/agents/sessions.gleam). `resources.query` reports process and session resource observations through the [Python binding](../priv/python/albedo_plugins/agents.py). Its host implementation is [`agents/resources.gleam`](../src/albedo/harness/extensions/agents/resources.gleam). An observation does not guarantee that a process remains alive after the read. ## Agent workflow Read `agents.models()` before choosing a model for a child. `agents.self.spawn` returns a handle, not the child's answer. Use [mail](../priv/python/albedo_plugins/mail.py) for the result rather than treating an idle snapshot as proof of completion. Use `child.set_verifier(command)` for an observable completion check. The [agents hook](../src/albedo/harness/extensions/agents/extension.gleam) checks normal parent submissions and stops while a reply is owed. Ask questions with `mail.request("parent", ...)`. Report a blocker with `mail.submit("parent", ..., blocker=True)` when the verifier cannot pass. Clear or replace a verifier whose condition is no longer relevant. ## Limits The `subagents` settings section defaults to 12 open children per parent and three generations below a root. `-1` removes either cap. The declarations are in [`family.limits_section`](../src/albedo/daemon/family.gleam). Use mail by session ID to reach another session rather than adding nesting solely for communication. ## The order of agents Clients rank working agents before idle agents, then closed agents. More recent activity ranks first within a state. A branch uses its best descendant rank so a working child can bring its ancestors forward. Equal branches use creation order and ID. See [TUI ordering](../cli/internal/tui/agents_order.go) and [web ordering](../web/src/lib/agentTree.ts). Check both clients when changing this policy. ## Deletion boundary `agents.delete` refuses the request. Its error directs the user to delete through the session browser because deletion loses the child's work. `agents.close` is a separate operation. See [`dispatch`](../src/albedo/harness/extensions/agents/extension.gleam) and [session lifecycle](sessions.md). ## Related pages - [All topics](README.md) - [Change guidance](contributing.md) - [Session attachment](sessions.md) - [Worktrees](worktrees.md)