Sessions and History
Sessions are durable AgentOS conversations. They let you inspect past work, resume a conversation, export a transcript, or stop a turn that is still running.
Use sessions when you want to:
- continue a previous chat from the CLI or Web UI;
- find the session key for an artifact, cost report, or channel thread;
- export a transcript for debugging or sharing;
- abort a long-running turn without deleting the session;
- delete old sessions after you no longer need them.
Requirements
Session commands use the gateway RPC surface. Start or connect to the gateway before running most session commands:
agentos gateway run
Or use the managed background gateway:
agentos gateway start --json
agentos gateway status
List Recent Sessions
agentos sessions list
agentos sessions list --limit 20
agentos sessions list --status idle
agentos sessions list --agent main
agentos sessions list --channel telegram
agentos sessions list --since 2026-05-01
agentos sessions list --search api-refactor
--search (-q) matches the session name, key, subject, and model, so a
renamed session is findable by the label you gave it.
Use --json for scripts:
agentos sessions list --json
Inspect a Session
agentos sessions show <session-key>
agentos sessions show <session-key> --json
The output includes the resolved session key, agent id, status, model, update time, title, and the latest preview when available.
Rename a Session
Sessions are auto-named. Give one a label you will recognize later:
agentos sessions rename <session-key> "api-refactor"
agentos sessions rename api-refactor "bug-46" # target by the current name
agentos sessions rename <session-key> --clear # back to the auto name
Inside a chat, /rename <name> renames the session you are in; /rename with
no argument clears the name. Names are trimmed, collapsed to a single line, and
capped at 120 characters. Once set, the name shows in sessions list, the chat
toolbar, and the Web UI session list, and resume/show/--search all accept
it in place of the key.
You can also just ask the agent — "call this session api-refactor". The
session_rename tool renames the session the agent is running in, and only
that one; asking it to clear the name drops back to the auto name.
Pin a Session
Pinned sessions sit in a Pinned section at the top of the session list, in the Web UI and in the desktop app (there, above the project folders). Pin the ones you keep coming back to:
agentos sessions pin <session-key>
agentos sessions pin api-refactor # target by name or short id
agentos sessions unpin <session-key>
In the Web UI and the desktop app, right-click a session and choose Pin or
Unpin. You can also ask the agent — "pin this session", or "pin the
session called api-refactor". The session_pin tool pins the session the agent
is running in unless you name another one.
Pins are stored on the gateway, so every client shows the same Pinned section. A pinned session stays listed however old it gets, and pinning is not activity: the session keeps its place in time. Deleting a session removes its pin.
Session Goals
/goal <objective> gives a session a persistent goal. Instead of stopping after
one reply, the agent keeps going until the goal is met:
/goal get the failing tests in tests/api green --max-turns 10
/goal # show the goal, turns used and the judge's last verdict
/goal pause # stop continuing (also happens if you abort a turn)
/goal resume # continue; after a limit it grants a fresh allowance
/goal clear # remove it
After every completed turn a small judge model (the auxiliary task
goal_judge, which prefers the router's cheapest text tier; no tools) reads the
goal and a bounded slice of the recent transcript and answers with strict JSON:
done, continue (with a suggested next step) or blocked (with what it
needs from you).
- continue queues an internal turn on the same session through the normal task queue. A message you send meanwhile runs first and is judged when it finishes, so you can steer at any time.
- done stops and posts a short status line. blocked stops and asks you;
answer, then
/goal resume. - Limits:
--max-turns N(default 20, at most 100) and an optional--budget-tokens Nmeasured on the session's token total. Hitting either stops the goal asexhausted;/goal resumestarts a new allowance. - Failures (a failed turn, an unparseable or unreachable judge) back off 5 s then 20 s and pause the goal on the third in a row.
- The goal is stored with the session and survives a gateway restart, but comes
back paused: nothing continues on its own after a restart. Set
[goals] resume_after_restart = trueto keep it active; it then continues after the session's next completed turn./resetand deleting the session remove the goal.
The agent can also read or finish the goal itself with the deferred goal
tool (get, set, update, complete); it cannot resume, un-pause or clear
one, which stays with you.
/goal is available in agentos chat against a gateway and on chat channels.
The web console does not have it yet. The terminal chat only streams turns it
started itself, so continuation turns run in the background there: check
progress with /goal or /history.
[goals]
enabled = true # AGENTOS_GOALS_ENABLED=false to turn the feature off
default_max_turns = 20
resume_after_restart = false
judge_timeout_seconds = 45.0
[auxiliary.tasks.goal_judge]
model = "openai/gpt-4o-mini" # or AGENTOS_GOAL_JUDGE_MODEL
Resume a Session
agentos sessions resume <session-key>
This opens terminal chat on the existing session. Use it when you want to keep the same conversation state instead of starting a fresh chat.
Abort a Running Turn
agentos sessions abort <session-key>
agentos sessions abort <session-key> --json
Abort stops the running turn if one exists, together with any coding-agent or subagent runs it spawned, and returns once they have ended. It does not delete the session.
This reaches through a team coordinator that is waiting for its own
specialists (it yielded, so no turn of its own is running): its specialists are
stopped, the coordinator ends as killed and is reported to its parent as
cancelled, and its wake is dropped. When you stop main, nothing below it is
woken and main does not answer your chat afterwards, the same as stopping main
with direct children. When you stop the waiting coordinator itself, main is
told it was cancelled and woken once, as for any child you stop.
The same holds when the coordinator's wake was already on its way: recorded because its last specialist had finished, but not sent yet (its own turn was still closing, or the hand-off was in flight). The wake is checked again right before it is sent and dropped if the coordinator was stopped meanwhile, so the coordinator runs nothing after the stop and its parent hears of it once.
The answer lists what was ended: children_aborted includes a coordinator
that was waiting, and aborted holds the last run of a waiting coordinator you
stopped directly.
A turn that is streaming or between steps when you stop it is asked to stop
first. The model's stream is closed at once, no further request is sent, and
the turn ends on its own with its reply so far marked [interrupted]. If it
has not stopped within task_runtime.turn_cancel_grace_seconds (default 5;
0 stops at once), its task is cancelled. Stopping it a second time during
that grace cancels it at once. A turn running tools, or an ACP harness turn, is
cancelled at once, so a stop never waits on a long tool.
[task_runtime]
turn_cancel_grace_seconds = 5
A turn that is aborted while tools are running leaves a transcript the next turn can replay as is. Every tool call that had not finished gets a "Cancelled" error result, and the turn ends with a note telling the model it was interrupted, so tools may have partly run.
Subagents of one parent session run at most two at a time by default. More
spawns are accepted and wait in spawn order (sessions_spawn reports them as
queued); children of other parents are not held back. Change the default
with subagents.max_concurrent_children (0 = no per-parent limit), or per
agent with subagents.max_concurrent_children in its entry. The hard cap on
how many children a parent may have at all is still
max_children_per_session.
[subagents]
max_concurrent_children = 2
Child runs have a separate nested pool of task_runtime.max_nested_concurrency
slots across all parents (default: the value of max_concurrency) that only
children use. While a parent's turn is still running (for example waiting on a
child with sessions_yield and a session_key), its children take nested
slots first, so they still start when every shared slot is busy. Any other
child takes a shared slot first and a nested one when the shared slots open to
children are taken. In the shared pool children always leave
subagents.subagent_reserved_slots (default 2, at most max_concurrency - 1)
free, so your own message starts at once even while children of finished turns
are still running. A child keeps its slot until it ends. Turns holding a slot
never exceed max_concurrency + max_nested_concurrency, at any nesting depth,
whatever max_concurrent_children is.
[task_runtime]
max_concurrency = 4
# max_nested_concurrency = 4 # default: max_concurrency
A turn waiting inline (sessions_yield with a session_key) holds no slot
while it waits: it gives its slot back, and takes one in the same pool back
before the wait returns, ahead of queued turns. The slot the awaited task frees
when it ends goes to the turn waiting on it first. So a chain of parents each
waiting on its own child, down to the spawn depth limit, never fills the pools
with turns that are only waiting. A turn waiting this way still counts as
running (for example in agentos gateway status), and still holds its place in
its own parent's max_concurrent_children lane.
If the gateway restarts while subagent runs are in progress, they are not
resumed. Each is marked abandoned (reason process_restart), and their
parent is woken once with all of its children's results, so it does not wait
forever. A second restart does not announce the same children again.
Waking the parent is durable. Each wake is written to the session database before it is sent, and counts as delivered only once the task runtime accepts it. If sending fails, for example while the runtime is draining, the wake is retried after 1 s, then 5 s, then 30 s, then every minute, for up to 30 minutes. A wake still pending when the gateway stops is sent by the next boot. A parent is never woken twice for the same group of children, and an aborted parent is not woken at all.
- A parent that closes its spawn group (
sessions_yieldwithout asession_key) while children still run records the group asawaiting. The last child's completion turns it into the pending wake. If the gateway stops in between, the next boot wakes the parent of every closed group whose children have all ended. - A parent that is itself a subagent (a team coordinator main handed a job
to) is not reported to its own parent when it yields: it stays
runninguntil its children are in. It is woken once, and that wake turn runs as the same subagent, under the same parent and ceiling; when it ends, its answer is reported to its parent like any child's, which wakes that parent in turn. This holds at every level up to the spawn depth limit, and when its wake turn yields to more children again (the next wake answers). - Such a coordinator reports to its parent exactly once, whatever happens
to it in between. The report is recorded on the reported run in the task
ledger (
details.parent_report), so a second one is refused, across restarts too. Its report is also its end: wakes it is still owed are dropped, and no wake is sent to it afterwards. - While it waits it is not finished by any other turn on its session. A
subagents steerfrom its parent, or a message you type into its session, runs as a turn of its own: the answer stays in the coordinator's session (its parent is not told, and sees it only by reading that session), the coordinator staysrunning, and when its children are in it is woken and reports as usual, with that exchange in its context. - When its parent kills it while it waits (
subagents kill), its children are stopped (unless the agent setscascade_on_parent_kill = false), its wake is dropped, and its parent is told at once that it wascancelled, the same as for any child it kills: the parent is woken once with that result. Nothing is left for a later restart to deliver. - When its own turn fails or times out after it handed the work out, it is reported with that failure and its children are stopped: nobody is left to take their results.
- A restart while such a coordinator's turn is running reports it to its
parent exactly once, as
abandoned: subagent turns are not resumed. If the restart cuts off the turn that yielded, its children's wake is dropped (reasonparent_finished) and it is not woken afterwards. If it cuts off the wake turn, that turn is the one reported. Either way its parent is woken once with that result. - A parent whose interrupted turn is being resumed by restart recovery is not also woken for its abandoned children; their results are still added to its transcript. The wake is only held back: if no resumed turn completes (every attempt failed and the run is tombstoned, your message cancelled the resume, or a later boot closes it), the parent is woken once for those children after all, on that boot or a later one. Once a resumed turn completes, the held wake is final: a later recovery of the same session (another interrupted turn) never sends it.
- A wake whose delivery has had no outcome for 10 minutes is taken over and
retried; one still not delivered 30 minutes after it was written is given up
(
delivery_timeout). Only then does the session's task-group card show the group as failed. - Deleting a session (or pruning stale sessions) deletes its wake records. Delivered, given-up and awaiting records are deleted after 7 days.
What a chat channel receives. A subagent's result reaches the chat that started it once:
- When the parent yielded to its subagents, the chat gets the parent's own answer from the wake turn and nothing else. No separate line is sent per subagent, whether it succeeded, failed or was cut off by a restart.
- When the parent did not yield to it (
sessions_yieldwithout asession_key; typically a subagent started in the background by a turn that then ended), no wake turn follows, so the gateway sends one line when it finishes:Subagent \<agent name\> completed with status \<status\>., then the first 500 characters of its answer. It names the agent (its ACP harness name, its[[agents]]name, or its id); a session key is never written into chat text. - A scheduled run sends neither: it collects its subagents inside its turn and its output goes to the job's delivery target.
- After
/abortnothing more arrives. The reply to/abortsays what was stopped:Turn aborted.,Turn aborted. Stopped 2 subagent runs it started.,Stopped 6 subagent runs this chat was waiting for.(the chat was waiting for its team and had no turn of its own running), orNo turn is currently running.when nothing was. - If the wake turn itself fails or times out, the chat is told once, in fixed words, that the answer could not be written; ask again to get the results, which are in the parent session's transcript.
The console and the desktop app are unchanged: every completion is still
recorded on the parent session and sent as session.event.subagent_completion.
Structured Subagent Results
sessions_spawn takes an optional output_schema, a JSON Schema object the
child's final answer must satisfy. The schema is appended to the child's task,
so the child is told to end with one JSON value (alone or in a single
```json block) that matches it.
When the child finishes, AgentOS takes the JSON from its final message, validates it against the schema, and reports the verdict with the completion:
| Field | Meaning |
|---|---|
schema_valid | true when the answer parsed and validated; false otherwise (also when the child failed or timed out). |
structured_result | The parsed JSON value when valid, otherwise null. |
schema_errors | Present when invalid: up to 8 short messages such as /score: 'x' is not of type 'integer'. |
result.text | The child's raw final answer, as for any child. |
The same fields appear on the completion payload, on each child row of
subagents(action="list") once the child has ended, and at the top level of
sessions_history for that child. In the message that wakes the parent, a
valid child's block holds the validated JSON instead of the surrounding prose,
and an invalid one keeps the raw text with schema_valid=false and the errors.
An invalid answer does not end the child. It gets one automatic correction
turn in the same session that lists the validation errors and asks for only the
corrected JSON; the correction turn runs without tools. Only the outcome of
that turn is announced to the parent. If the answer is still invalid, the raw
text is delivered with schema_valid: false and the errors. After a gateway
restart the retry is not repeated: a child that already received its
correction turn is announced as is.
Limits: the schema may be at most 8,000 characters when serialized, may only
use local #... $ref targets (validation never fetches anything), and must
itself be a valid JSON Schema (draft 2020-12), otherwise the spawn fails with a
tool error. A parsed result longer than 12,000 characters counts as invalid
(it is not truncated).
runtime="acp" children accept output_schema too: the harness is told the
schema and the result is validated and reported the same way, but a harness
child gets no automatic correction turn. Send a follow-up with sessions_send
if the parent wants a fix.
Session Access
[session_access] decides which sessions an agent's session tools reach, and
which agents may spawn or message each other. One check covers
sessions_send, sessions_list, sessions_history, sessions_yield (with a
session_key), session_pin, session_search, the acp tool's per-session
actions and its sessions listing, and cron jobs bound to a named session
(session_target = "session"), and the checkpoints.summary / checkpoints.diff
reads an agent's own connection makes of the sessions it spawned
(sessions.children of the agent's own session is a read of its own session
and lists every run it spawned in every mode). The defaults are fully open, which is how AgentOS
behaved before the section existed, and the section is not written to the
config file while it is at its defaults.
[session_access]
visibility = "tree" # all (default) | agent | tree | self
agent_to_agent = true # false: no cross-agent spawn, send or read
allow_pairs = [["coordinator", "researcher"], ["coordinator", "writer"]]
visibility | An agent's session tools reach |
|---|---|
all | Any session (subject to agent_to_agent and allow_pairs). |
agent | Sessions of the caller's own agent, plus the sessions it spawned on other agents. |
tree | The caller's session and every session it spawned, at any depth. |
self | Only the caller's session. Completions are still pushed to the parent; sessions_history(answer_offset=...) may still page a cut-off answer of any session the caller spawned, at any depth; subagents still lists, steers and kills the caller's direct children, and acp still controls the harness sessions it spawned. |
allow_pairslists[from, to]agent pairs;*matches any agent. An empty list allows every pair. Pairs are directional:["coordinator", "researcher"]does not letresearcherreachcoordinator.- Cross-agent
sessions_spawnandsessions_sendmust pass both the pair policy and the caller'ssubagents.allow_agents. A spawn you start yourself skips only the pair policy: it still obeysallow_agentswhen that is set. A refusal names the setting that refused it, for examplesession_access.allow_pairs does not list ['coordinator', 'writer']. - A session the caller spawned stays reachable under
all,agentandtree, even on another agent and even withagent_to_agent = false, so a parent can always follow up with its own children. - A hidden session answers exactly like a missing one:
Session not foundfromsessions_history,sessions_yieldandacp;sessions_sendgives the same refusal for a missing key as for a hidden one;sessions_list,session_searchandsession_pinleave hidden sessions out (a pin target or prefix only matches visible sessions). - Your own CLI and web console are not limited by this section.
Channel, cron, subagent and other agent callers are, and so is a turn one
of them queued on a console session with
sessions_send: the queued turn carries its sender's caller kind, and only a turn with no inherited authority, or with one captured from a CLI or web caller, counts as yours. The same holds for the turns that follow from one: a subagent or background-command completion wakes the parent session, and a/goalcontinuation turn runs, under the ceiling of the turn that spawned the child, started the command or set (or last refined) the goal. The ceiling is kept with the task record and the goal, so it survives a gateway restart; a wake for a child one of your own turns spawned stays yours. Text queued incollectmode with a different ceiling is never merged into a pending turn. A wake or continuation turn never starts from more than the turn behind it, and one whose origin carried no ceiling carries none. A turn an inbound hook starts (/api/v1/hooks/agent) counts as yours under[session_access]: it runs as a web turn with no ceiling, on the strength of the hooks token you issued. - Contexts that may not read private memory (group chats, cron, subagents)
were already confined to their own session and its children;
selfnarrows them further. - The
subagentstool is not affected: it only ever reaches the caller's direct children. - Not covered:
memory_search(source="sessions")searches snippets of the calling agent's own sessions (indexed only withmemory.session_source_enabled), so undertreeandselfit can still return text from the agent's other sessions;cron list/get/runsshow the agent's jobs, which belong to the agent rather than a session (a job already bound to a session the caller cannot reach can still not be updated, toggled, run or removed). Neither reaches another agent. A cron job stored before a policy was set keeps its binding and runs as scheduled; the policy gates changing it.cronscript and elevation grants still go by the envelope's caller kind, as before this section existed.
The order of these checks is drawn in
architecture.md#session-access-decision.
An agent cannot change this section through the config RPCs; set it with
agentos config set session_access.visibility tree --config <path> or by
editing the file, then restart the gateway. agentos doctor reports agent ids in allow_pairs that
match no configured agent (session_access.unknown_agent_in_pairs).
Export a Transcript
Export Markdown:
agentos sessions export \<session-key\>
agentos sessions export \<session-key\> --output session.md
Export JSON:
agentos sessions export \<session-key\> --format json --output session.json
Exported transcripts are useful for bug reports, audits, or moving a task into a document. Transcripts export messages from the gateway's active chat history window (up to the 200-message gateway limit). Remove secrets, private local paths, provider tokens, and private channel identifiers before sharing an export publicly.
Delete a Session
agentos sessions delete \<session-key\>
agentos sessions delete \<session-key\> --yes
Deleting a session is for cleanup. Export first if you may need the transcript later.
Projects: Group Sessions and Share Knowledge
agentos projects create "Token research" --knowledge-file notes.md
agentos projects move \<session-key\> \<project-id\> # 'none' detaches
agentos projects show \<project-id\>
agentos projects update \<project-id\> --knowledge "Revised shared context"
agentos projects delete \<project-id\> # sessions survive, detached
A project groups chat sessions and carries a shared knowledge text.
Projects sit above agents: sessions of any agent can join the same project,
and the project page lists its sessions grouped per agent. Every session in
the project gets the knowledge injected into its system prompt as a
Project Knowledge block on every turn — edit the knowledge and the next
turn of every member session sees the new version. A project's agent field
is only the default agent that "New chat in project" starts sessions
with, not a membership boundary.
- Create a session directly inside a project from the Web UI Projects page ("New chat in project"), or move existing sessions in and out at any time.
- Deleting a project never deletes its sessions — they detach, keep their history, and simply stop receiving the shared knowledge.
- The agent can manage projects from prompting via the
projects_create,projects_list,projects_update, andprojects_move_sessiontools, and can search sibling transcripts withsession_search scope=project. These tools are scoped to the calling session — knowledge is readable/writable only for the session's own project, and only the calling session itself can be moved — because knowledge a tool writes lands in every member session's system prompt. Cross-project management stays on the Web UI / CLI surface. - Existing databases migrate automatically on gateway start: old sessions
come up project-less (
project_idempty) and behave exactly as before.
ACP Harness Sessions
When the agent delegates to an external coding harness with
sessions_spawn(runtime="acp", acp_agent="claude", ...), the child is a
regular session whose key looks like agent:main:acp:1a2b3c4d. It shows up
in agentos sessions list, keeps its own transcript and token/cost totals,
and its final answer is pushed back to the parent with a Stats: line.
oneshot children close after one turn; persistent ones accept
sessions_send follow-ups (steer cancels the running turn first).
agentos acp sessions lists the harness side (process, resume record),
agentos acp cancel <key> stops a running turn and agentos acp close <key> ends the harness. See ACP Coding Harnesses.
Web UI Workflow
The Web UI uses the same session system. In the control console, the
Sessions list in the rail lists, searches and opens sessions (by name as
well as by key); a row's ⋯ menu (or right-click) has Open in new tab,
Rename, Pin, Move to project (choose a project, or No project to
detach the session), Reset, Export, Copy session key and Delete. The
Sessions page (/control/sessions) does the same in bulk; click a row's
name to rename it inline — Enter saves, Escape cancels, and an empty value
clears the custom name. In Chat, the header ⋯ menu has Rename, Compact,
Reset session, Export and Copy session key; the header shows the name once
set. See Web UI.
Open:
http://127.0.0.1:18791/control/
Troubleshooting
If commands cannot reach the gateway:
agentos gateway status
agentos doctor
If old context appears summarized, the session may have compacted older history. This is normal for long sessions under context pressure. Export the session when exact text matters.
Read next: