Starting and messaging sessions
A tool can start a session from the session that it runs in, send messages between such sessions, and stop or archive one. Agent Teams does this (agent-teams.ts). A team or orchestration extension uses the same calls. Use host.linkedSessions. Its members are in the host reference.
Experimental in 0.14: it can change in a minor release, but never in a patch release (API stability).
What a linked session is
Section titled “What a linked session is”A linked session is an ordinary session. The session list shows it under the session that started it (the source).
- It works in
cwdwhen supplied, otherwise the source’s folder. It does not get a worktree of its own. - It starts with a copy of the source’s agent settings. It does not get the source’s history, plan mode, or budget. The source’s budget covers it (see Limits of a team).
- The link (
linkedFromin its session entry) gives no access, and owns nothing.
Start a session
Section titled “Start a session”start(source, { title?, message, model?, thinking?, cwd? }, key) makes the session, and sends message to it as its first message. It returns { session, address }: the id of the new session, and the source’s address for it.
cwdselects an existing working folder using the same path rules as the folder picker (including~). Prefer an absolute path. A blankcwdcounts as nocwd. A relativecwdresolves against the folder of the server process, not the folder of the source. The child loads that folder’s project context and tools; the source stays in its own folder. A missing path or a file is rejected before a session is created. Since 0.19.0: an older HADAL ignorescwdand uses the source’s folder, so a gallery entry that needs it setsminPocketto0.19.0.- Without
title, the title is the first line of the message. modelisprovider/modelId. While the owner’s list (Menu → Providers → Subagent models) is empty, it must be the source’s model. Once the list has models, it must be one of them, and the source’s own model counts only when it is listed. Withoutmodel, the session uses the source’s model if the list is empty or has it. If the list does not have it, the call is refused with an error that names the allowed models: the caller must choose one (the error is a 400 for a human route).sendrefuses a session that runs on a model off the list (a person changed it, or the owner changed the list), when the list is not empty. A message from a linked session to the session that started it is a reply, not work: it goes whatever model that session runs on.thinkingcan be any level, also one above the source’s. Without it, the session uses the source’s level. HADAL lowers it to the highest level that the model has, or uses the lowest level of the model when it has none that low.- When a model cannot be used now, HADAL refuses the call before it makes anything.
Starts from a human page
Section titled “Starts from a human page”Since 0.16.0, a conversation-bound route gets request.linkedSessions.start({ title?, message, model?, thinking?, cwd? }, key) and list(). These methods act as the authenticated person and bound source, not host.requesterOf(source). They have no source-id or actor parameter. They end with the request, so await each start in the handler.
- The same team, source plan, turn, spend, allowed-model, and provider checks apply. No message is added to the source, and its requester is unchanged.
- Explicit thinking must be a level that the chosen model has. It is rejected rather than silently lowered. Omitted thinking inherits the source’s level, which HADAL lowers to a level that the model has. Read
request.conversation.modelandthinkingLevel, withhost.modelInfo("provider/modelId"), to show the effective choices. - Source folder/model/thinking changes while a start waits cause a 409. Other inherited agent settings are read fresh in the creation transaction. The target cannot be reconfigured to substitute another model, level, or folder before its first message is admitted.
- Keys share the existing receipt store. Prefix them with the module’s name and keep one stable key per logical role start. A receipt made for another clicking person is a 409, never permission to act as that person.
list()returnsHumanLinkedSession[]: the existing address and audience-safe metadata, plus aconversationIdvisible to this person. Usepocket.openConversation(item.conversationId)or a start’ssessionto open it. Do not put these ids in a model transcript. The host’slist(source)still gives opaque addresses only.- The route waits only for initial-message admission, not an answer. The final authorization boundary is when that admission enters Durable’s mutation line. A short child-context lease rejects intervening source/target policy changes and rechecks synchronous actor, model, and spend policy there. After admission, later cancellation does not undo work.
Check for web.conversationRoute at runtime and set gallery minPocket: "0.16.0". host.linkedSessions retains its previous requester behavior.
Send a message
Section titled “Send a message”send(source, { to, message, steer? }, key) sends message to the linked session at the address to.
- Since 0.28.0 the message lands at the session’s next pause, after its current tool round, as
steer: truedid before. Withsteer: falseit waits for the session’s run to end. Before 0.28.0 the default was to wait. sendreturns when the session takes the message, not when it answers.- It returns
{ answers }(since 0.28.0; before, nothing): whether the target’s final answer comes back to the source by itself, which it does only when the source started the target (see below). - The session that gets the message reads it in a fence. Words before it say that another session’s agent wrote it, that it is a request and not an order from a person, and which address to write to. From the session that started it, they say its final answer goes back by itself; from any other session (a linked session writing to its lead, or to a sibling), they ask it to send its answer to that address when the message asks for one.
- Every message that waits in a session’s queue goes in together at its next pause (HADAL sets the harness’s
steeringModeandfollowUpModetoallunless the owner set them in HADAL’s settings): a queue of agents’ messages costs one turn, not one each.
A session’s final answer comes back by itself
Section titled “A session’s final answer comes back by itself”Since 0.28.0, when a linked session’s run ends, HADAL sends the session that started it one message from the linked session’s address: its final answer, up to 6,000 characters (more says how much is in the session), or why it failed, or that it was stopped. It lands at the lead’s next pause, once for each run, through the same path as send, so the same checks apply there: a lead that cannot take it (plan mode, a spend limit, someone else’s turn) gets a notice instead, and nothing waits in silence. An archived lead gets nothing.
So a tool that starts linked sessions need not ask them to report, and need not poll: the lead ends its turn, and the answers wake it. The report’s fence shows as a linked session’s card, like a message. Only the session that started one hears its end of run: a linked session that asks its lead, or a sibling, gets an answer only when that session sends one, and the message tells it to.
Stop a run
Section titled “Stop a run”stop(source, { to }, key) stops the run of the linked session at the address to, and withdraws what waits in its queue. Stopping is the safe direction: it needs the same access as send, including the turn and room under the spend limit.
- When the session is idle, it has no run to stop: the call only withdraws what waits in its queue.
- It returns
{ busy }.busyis true when the session was working. - Since 0.28.0. An older HADAL has no
stop, so a module checks for it and setsminPocketto0.28.0when it needs it.
Archive a session
Section titled “Archive a session”archive(source, { to, archived? }, key) archives the linked session at the address to. With archived: false, it brings the session back. Without archived, it archives.
- It returns
{ archived, repeating }.archivedsays whether the session is archived now.repeatingis how many of its repeating schedules keep running: an archive does not stop them. - It needs the same access as
send. - Since 0.28.0, with the same check as
stop.
List the sessions
Section titled “List the sessions”list(source) gives the sessions linked to the source, at any distance, that the person whom HADAL works for can see.
- Each one has an
addressof the source’s own, so no session’s id goes into the source’s transcript. - Each one has its title, folder, and state only when all the people who see the source also see it. Since 0.28.0 that state includes
failed: why its last run gave up, the same short line the session list shows, and only while that failure stands. A later run clears it. A run that was stopped is not a failure.
Addresses belong to the session that has them. A fork starts with none, so it leaves the team: the addresses in the history that it copied do not work there.
Who it acts for
Section titled “Who it acts for”start, send, stop, and archive act for the person whom HADAL works for in the source. They need that person’s access and right to steer. To start a session, that person must also have access to all sessions. stop and archive reach only a session of this team that the person can see.
HADAL refuses them while the source is in plan mode, past a spend limit, or while another person has the turn. send also needs the turn, and room under the spend limit, in the target session.
Limits of a team
Section titled “Limits of a team”HADAL keeps a team small. Past these limits (Limits), it refuses the call with a plain error:
- A linked session can send messages to the other sessions of its team. It cannot start sessions.
- Since 0.19.0, no count limits the sessions that a session starts. Before 0.19.0, a session started a limited number.
- Since 0.19.0, no count of messages between the sessions of a team stops them, and since 0.28.0 none counts them. Before 0.19.0, they stopped after a limited number until a person wrote in one of them.
- The budget of the session that started a team covers all of the team. What its linked sessions spend counts against it.
- A message and a title have a length limit. A title is one line, without invisible or direction characters.
Note: since 0.19.0, no count limit applies to a team. The spend limit of the top session is the brake. The owner can set a session budget for a team in Menu → Spend.
Replays
Section titled “Replays”Give a key that stays the same when the call runs again: ${api.taskId}:${api.callId}. A call with a key that HADAL saw before returns what the first call returned, and does not act again. So a replay makes one session, sends one message, stops one run, and archives once. A repeated stop returns the first call’s { busy }. A repeated archive returns the first call’s { archived, repeating }, not a state someone changed later. HADAL keeps the record of a key for a limited time, and for a limited number of calls (limits).
The errors say what is wrong. They do not tell HADAL what to do about it: your tool tells HADAL that.
These pages describe HADAL 0.29.0. Your copy has the pages of its own version in its docs/ folder.