Expand description
Helper for registering an agent process in zag’s ProcessStore and
producing the env vars (ZAG_PROCESS_ID, ZAG_SESSION_ID, etc.) that
zag ps kill self / zig self terminate use to resolve the running
agent from inside the agent’s own subshell.
Two callers need this exact sequence:
zag-cli/src/commands/agent_action.rs— thezag agentCLI path.zag-agent::AgentBuilder— used by library consumers (e.g.zig runinteractive steps in thezigworkflow tool) that drive an agent programmatically without going through thezagCLI.
Before this module existed, only agent_action.rs did the registration
(and via unsafe std::env::set_var, polluting the parent process’s env).
Library callers got no registration and no env vars, so zig self terminate failed with Cannot resolve "self": ZAG_PROCESS_ID is not set
from inside any zig-run interactive step.
This module is now the single source of truth. Callers either:
- Call
registerdirectly and wire the returnedProcessRegistrationto theirAgent/AgentBuilderviaset_env_vars+set_on_spawn_hook(or [AgentBuilder::env] / [AgentBuilder::on_spawn] / the convenience [AgentBuilder::register_process]), then callProcessRegistration::update_statuswhen the agent exits. - Or pass a
RegisterOptionsOwnedto [AgentBuilder::register_process] and let the builder handle registration + finalisation automatically.
Structs§
- Process
Registration - A live process registration. Holds the generated
proc_idand the env vars to inject into the agent subprocess. Callers wireenv_vars()andon_spawn_hook()to the agent and callupdate_status()once the agent exits. - Register
Options - Borrowed options for
register. Field semantics mirrorProcessEntryone-for-one. - Register
Options Owned - Owned variant of
RegisterOptionsfor storage on a builder before the terminal method runs.
Functions§
- register
- Register a new process entry in zag’s
ProcessStoreand return aProcessRegistrationholding the proc_id and the env vars to inject into the agent subprocess.