Skip to content
Sessions: several conversations with one agent

Sessions: several conversations with one agent

An agent’s machine holds several sessions: conversations with the agent, each with its own history, side by side on the one machine. Every agent has a main session. It is never deleted, only cleared: clearing it keeps its conversation as a session of its own, titled “Main until” its last day. Any other session can be deleted. Sessions cost nothing extra: no second machine, nothing in your quota.

All sessions share the machine: its disk, checkouts, memory, credentials and tool link. A session that hasn’t been used for 10 minutes leaves the agent’s memory and comes back, with its history, the next time it is used. A turn in one session doesn’t wait for a turn in another. Every coding agent but pi has sessions; pi keeps its main session only, for now.

In the portal, the chat panel’s session menu starts, switches, renames, clears and deletes them (A chat’s sessions).

Where messages land

FromSession
A fresh space-env send agent:NAMEmain; --session <id> names another
An answer to a message an agent’s session sentthat session
A machine, a schedule, a topicmain
A Telegram topicthe session it was opened for: /new picks the agent, then a new, the main or an existing session (Telegram)
Telegram’s chat itself, Google Chat’s DMmain
A Google Chat threada session of its own, made on its first message (Google Chat)
A session the agent started itselfthat session; its report goes to the one that started it

An answer finds its way back by itself: a message sent from a session carries that session, and the agent that gets it answers with space-env send … --reply (or in the same --context), which sends the answer to that session. If the session was deleted meanwhile, the answer goes to main and says so.

space-env send agent:dev --qos notify --text "Add a /health page to web."
space-env send agent:dev --session s-3f9a0c12b7de --text "Also add it to the README."
space-env send agent:lead --reply --context health --text "Done: branch health pushed."

space-env notify from a session answers in the chat that last prompted that session; a session the agent started itself uses the chat of the session that started it.

Sessions an agent starts on itself

An agent can hand a task to a new session of its own: a cheap subagent that needs no machine. space-env sessions new "<task>" starts it with the task as its first prompt and prints its id; when its turn ends, its last answer comes back to the session that started it, as a report. space-env sessions wait <id> waits for that answer instead and prints it (then no report is sent). A session deleted before its task ran ends there: sessions wait fails with “the session was deleted”, and so does its report. space-env sessions lists them all, main first, * marking the one the command runs in.

space-env sessions
space-env sessions new "Count the TODOs in ~/web and list the files they are in."
space-env sessions wait s-3f9a0c12b7de --timeout 600

Write the task for a newcomer: the new session doesn’t share the conversation that started it, only the disk. A session other than main changes work kept in git only in a git worktree of its own (git worktree add beside the checkout, named after the session), so two sessions never edit one checkout; main works in the checkouts. Deleting a session leaves its worktrees for the agent to merge or remove.

For work that needs its own disk, checkout or coding agent, start a subagent with space-env agents spawn instead (Agents).

Last updated on