Skip to main content

Module agent_runtime

Module agent_runtime 

Source
Expand description

What state every created agent is in, with or without a pane: agentruntime.list, the agentruntime:changed:<agent id> event that carries a change, and agent.start (the always-available agents spec, §3.4 and §5).

One source: the availability view (availability_view, which is what a message to the agent asks), mapped onto the states a viewer sees. An agent with no live pane is stopped; its row comes from its definition. A viewer (the Swarm) lists the rows once, then follows the event.

A pane whose process ended keeps its block_id (found by the block’s agent id) and reads stopped.

Two things a viewer must not wait for until the always-available agents build lands: starting is never produced (a controller just created, with no process yet, reads as idle), and no event says an agent was deleted (changed_rows only forgets it), so a viewer relists on agents:changed.

An agent wanted running with no process reads idle, not stopped: a persistent agent with no session on file starts on its first message, and an agent that has only ended its process is started by the next one. The failure states (limited, signed out, waiting) keep their place.

An agent between turns whose Browser request is still open reads waiting_on_user (browser_request, with the pane the request waits in): its call answered “waiting” and it ended its turn, so nothing else says the person is asked. Only what a viewer sees: the availability a message asks is unchanged, so a message still starts a turn. The same fact is kept in the block’s term:awaiting_browser for the rows that read block meta (the Swarm’s).

desired is the agent’s own desired state when its block records one (agent:desired, set by an open, a start and a stop), and otherwise running while a process is alive and stopped if not.

Structs§

AgentRuntime
One agent’s runtime state, with what a row needs to show it before it has a pane. The payload of agentruntime:changed:<agent id> and a row of agentruntime.list.
AgentStartResult
What a start gave: the block the agent runs in (the parked block, for an agent never opened).
CommandAgentStartData
agent.start.

Enums§

AgentDesiredState
Whether the agent should be running (spec rule 5).
AgentRuntimeState
The state of one agent as a viewer sees it.

Constants§

BROWSER_REQUEST
Why an agent between turns reads waiting_on_user: a Browser request of its is still open.
LOOK_EVERY 🔒
How often the runtime states are looked at for a change.
META_AWAITING_BROWSER
Block meta, true while the agent’s row waits on a Browser request (the Swarm row reads block meta).
STARTS_ON_FIRST_MESSAGE
Why an agent wanted running with no process reads idle (state_of’s reasons are codes too).

Functions§

agent_of_block 🔒
The agent a block belongs to, by the id its meta carries.
begins_waiting 🔒
Whether row just began waiting on the user: it is waiting now and was not at the last look. An agent with no block has nothing to notify about, and a Browser request was announced by its own banner, on the Browser pane, under the person’s setting for it.
block_color 🔒
The colour the agent’s pane shows (its border colour, frame:activebordercolor, set when it opens).
blocked_start 🔒
Why a start would be refused, for an agent that is stopped and wanted running: its block says running, or a message waits for it. why is asked only then, because it reads every live agent.
browser_flag_fix 🔒
What to write to the block’s META_AWAITING_BROWSER so it says what the row says, if it does not.
browser_flag_fixes 🔒
The blocks of rows whose META_AWAITING_BROWSER does not say what the row says, with what it should say. Blocking: reads the store.
changed_rows
The rows that differ from what was last sent, and what to remember now: an agent that is gone is forgotten.
desired_from
What the agent’s block says it should be doing, when it says: a stop sets stopped, an open or a start running. An agent whose block records nothing is wanted as its state says.
desired_of
A process is alive in every state but these two.
ends_waiting 🔒
The block an agent was waiting in, when it just stopped waiting (answered, cancelled or ended): the block of the last look, which the row may no longer name.
error_reason
Why an agent in error is, when its last run’s failure was classified (rate_limited, network…): whether it is worth another try is not in error itself (#2617).
list 🔒
The runtime state of every created agent, as of now_ms. Blocking: reads the store.
mirror_browser_wait 🔒
Keep each changed row’s block meta saying whether it waits on a Browser request. Every row is a change at the first look after a start, so a flag a stopped srv left behind is taken down then.
notify_waiting 🔒
“Waiting on you” as an OS notification, for an agent no pane need show (a headless or parked one): the router coalesces it with the question’s own report for the same block, so it adds nothing when the question already notified, and covers a wait that had no such report (an App Server approval).
pane_blocks_by_agent 🔒
The block of each agent that has one, by agent id: the one in a pane (the first by id when it has several), else the one parked in no tab, which holds the agent’s desired state while it has no process. One pass over the blocks for the whole list.
register
request_pane 🔒
The pane where the open Browser request of the agent bound under names waits. A request carries the name its call used, which is one of the names the agent’s block is bound under.
resolve_waiting 🔒
Take down the notice notify_waiting raised, so a wait that ended before it showed does not show a stale question, and the next wait on the block is a new notice and not coalesced into the old.
runtime_of
What a viewer sees of an agent from its status: the state, why, when a limit lifts and what is wanted. The one place the availability, the wanted state and the controller meet (state_of, desired_from and wanted_running_is_idle are its steps).
runtime_of_agent 🔒
Where an agent runs: its pane’s mode is the current truth; a definition with no pane says it by its type, so a stopped agent has an answer too.
spawn 🔒
Look at the states on a short interval and publish each change to agentruntime:changed:<id>.
state_of
The state, its reason and its reset, from what the availability view says.
waiting_on_browser_request
An idle agent with an open Browser request is waiting for the person. Only an idle one: an agent that works is working (a message started another turn), and one that cannot work says that first.
waits_on_browser_request 🔒
wanted_running_is_idle
What a viewer sees of an agent that the availability view calls stopped but its block says should run and a controller holds: it is waiting for a message to start it, which is idle. With no controller (the server restarted and nothing resumed it yet) it stays stopped: the Swarm lists only controller-backed agents as live, so an idle row there would be listed nowhere, with no Start.