Skip to main content

Module agent_define

Module agent_define 

Source

Functions§

agent_define_core 🔒
allocate_agent_workdir
Atomically allocate an agent working directory.
check_provider_unchanged 🔒
check_volumes 🔒
An agent’s provider is read-only once set: its sessions, linked accounts and native memory all belong to that harness, so switching it would strand them. Run the same setup on another harness by forking the agent. The lock moved here from the agent’s bundle (SPEC_AGENT_BUNDLE_FORMAT_V0_3_2026_10_05.md §3.1). An empty stored provider can still be set once. A definition’s volumes list may not name a mount a container may not have (a container runtime’s socket or a folder holding one): saved with one, it is refused with the reason a start would give.
ensure_stub 🔒
The instance stub for a definition, as (stub id, newly created). A failure is logged and treated as “no stub”: the definition is already committed, so it is never fatal.
finish_created 🔒
A freshly inserted definition (def.slug is set by agent_def_find_or_insert). The stub is created first so listeners handling agents:changed can immediately find the new agent via ListRecentSessionsCommand. The definition is already committed, so a stub failure is non-fatal and the broadcast still goes out.
finish_skipped 🔒
if_exists=skip on an existing definition. Honors create_instance_stub even on skip: a definition created with create_instance_stub=false (or imported another way) might not have a stub yet, and a later idempotent call with create_instance_stub=true should make it visible in My Agents. agents:changed fires only when the stub was actually newly inserted.
infer_provider_from_model 🔒
Infer a provider slug from a model name prefix. Only maps prefixes that correspond to a registered provider slug. Callers must still validate the result via providers::get_provider.
make_stub_idempotent 🔒
Returns (agent_row_id, newly_inserted). In the consolidated model the definition row IS the agent, so the “stub instance” that makes a defined agent visible in My Agents is that same row carrying an instance_name; instance_create folds into it. newly_inserted = false when the row already carries a name (the stub already existed); callers use this to avoid broadcasting agents:changed on no-op calls. The returned id is the row’s id, which is what instance_create reports back.
new_definition 🔒
The definition row a define call inserts when no definition has the name yet.
persist_define_content 🔒
Core logic for the agent.define command, shared by the WebSocket RPC handler and the HTTP service dispatch (("agent", "define") in service.rs). Persist system_prompt and env content blobs for a freshly created or updated agent definition. Errors are logged but not propagated — the definition row is already committed and the caller has already published agents:changed, so a content-write failure must not abort the response.
register
register_agent_define 🔒
resolve_define_provider 🔒
The provider for a define call: an explicit provider wins; otherwise it is inferred from the model prefix; with neither it is “claude”.
update_existing 🔒
if_exists=update on an existing definition: overwrite only the fields the caller gave.
validate_vendor_base_url 🔒
Rejects a non-empty model_vendor_base_url unless provider_id’s ProviderConfig declares support for redirection via base_url_env_var. Pure — no I/O — so it’s directly unit-testable without the async Store/Broker harness agent_define_core needs. An empty base_url is always fine — that’s “use the harness’s default vendor endpoint,” never rejected regardless of provider.