Agent management and audit
Console APIs to list managed agents, edit drafts and activations, control access, probe capabilities, promote candidates, and query audit history.
Admin-owned agent management: configuration changes stay as drafts until a revision is explicitly activated. The module mounts four routers under the console HTTP API.
What this API area is for
The agent-management API separates configuration proposals from live versions. Listing, editing a draft and activating a revision have different effects and authority requirements.
These routes support the agent control plane in RecoX. Operators with read access can browse the managed agent fleet, read revision config, review recent activity, list system capabilities, inspect promotion candidates, and search audit events or lineage. Inspecting one agent returns agent_control.detail, fleet overview, and max_run_seconds from effective_budget. Administrators (and other roles allowed by each handler) can save configuration drafts, activate a revision, change per-agent or fleet-wide access, run a safe capability check, promote a candidate, and read prompt-cache diagnostics.
Edits that mutate runtime configuration or access require console write trust on the request where the handlers call require_console_write_trust. Several handlers add stricter role checks beyond the route permission ceiling (for example require_admin on cache diagnostics and capability checks).
Routes
| Method | Path | Permission | Handler | What it does |
|---|---|---|---|---|
| GET | /api/agents/caching/status | agents.read | cache_status | Returns prompt-cache diagnostics and storage status; also calls require_admin(). |
| GET | /api/agents/capabilities | agents.read | capabilities | Returns what RecoX can do as one system and whether each capability works right now (capability_board.board). |
| POST | /api/agents/capabilities/check | agents.manage | check_capabilities | Tests what can be tested safely; writes and billed web search are never called; requires write trust and require_admin(). |
| GET | /api/agents/candidates/{candidate_id} | agents.read | candidate | Returns detail for one agent candidate. |
| POST | /api/agents/candidates/{candidate_id}/promote | agents.manage | promote_candidate | promote_candidate requires write trust and an admin actor, then returns agent_candidates.promote(...). |
| POST | /api/agents/access/all | agents.manage | set_all_access | Changes access for all agents (registered before per-agent access so access is not parsed as an agent id); requires write trust and require_admin("agents.manage"). |
| POST | /api/agents/{agent_id}/access | agents.manage | set_access | set_access sets one managed agent's stopped flag with expected_version (AccessConflict becomes stale) and requires write trust plus require_admin("agents.manage"). |
| GET | /api/agents | agents.read | agents | Returns the managed agent directory (agent_fleet.directory). |
| GET | /api/agents/{agent_id} | agents.read | agent | Returns agent detail, fleet overview, and max_run_seconds from effective budget. |
| GET | /api/agents/{agent_id}/activity | agents.read | activity | Returns recent audit events for the agent (limit query, default 5, clamped between 1 and 20). |
| POST | /api/agents/{agent_id}/drafts | agents.manage | save | Saves a configuration draft (HTTP 201); idempotent when request_id is set; requires write trust and require_role(DRAFT_ROLES). |
| GET | /api/agents/{agent_id}/revisions/{revision} | agents.read | revision | Returns stored config and effective_config for a revision id. |
| POST | /api/agents/{agent_id}/revisions/{revision}/activate | agents.manage | activate | Activates a draft revision; idempotent when request_id is set; requires write trust and admin. |
| GET | /api/audit/events | agents.read | audit_events | Queries agent audit events with filters and cursor pagination. |
| GET | /api/audit/lineage | agents.read | audit_lineage | Queries governance lineage events and returns them under events. |
The candidate router is mounted so /api/agents/candidates/... is not interpreted as /api/agents/{agent_id}.
Request and response models
Body models (JSON)
DraftRequest (POST .../drafts)
| Field | Type | Notes |
|---|---|---|
base_digest | string | Required. |
base_revision | string or null | Optional. |
settings | object | Keys map to string | bool | int | float | null; default empty. |
harness | dict[str, str] | Default empty. |
tools | dict[str, bool] | Default empty. |
request_id | string or null | Optional; used for idempotent replay. |
Extra properties are forbidden (extra="forbid").
AccessRequest (POST .../{agent_id}/access)
| Field | Type | Notes |
|---|---|---|
stopped | bool | Strict boolean. |
expected_version | int | ge=0, strict. |
reason | string | Default "", max_length=2000. |
reviewed | bool | Default false, strict. |
AccessAllRequest (POST .../access/all)
| Field | Type | Notes |
|---|---|---|
stopped | bool | Strict boolean. |
reason | string | Default "", max_length=2000. |
reviewed | bool | Default false, strict. |
ActivationRequest (POST .../revisions/{revision}/activate)
| Field | Type | Notes |
|---|---|---|
expected_generation | int | ge=1, strict. |
restore | bool | Default false. |
request_id | string or null | Optional; used for idempotent replay. |
Query parameters
GET .../activity
| Parameter | Type | Default |
|---|---|---|
limit | int | 5 (effective count uses max(1, min(limit, 20))) |
GET /api/audit/events
| Parameter | Type |
|---|---|
actor | string or null |
agent_id | string or null |
action | string or null |
target_type | string or null |
target_id | string or null |
correlation_id | string or null |
since | string or null |
until | string or null |
limit | int or null (passed through bounded_limit) |
cursor | string or null |
GET /api/audit/lineage
| Parameter | Type |
|---|---|
column | string or null |
table | string or null |
subject | string or null |
actor | string or null |
channel | string or null |
since | string or null |
until | string or null |
limit | int or null (passed through bounded_limit) |
Representative response shapes
Handlers return JSON objects unless noted. Shapes inferred from return statements and delegations:
| Handler | Response |
|---|---|
cache_status | { "diagnostics": ..., "storage": ... } |
capabilities | Capability board payload from capability_board.board. |
check_capabilities | Result of capability_board.check. |
candidate | Candidate detail from agent_candidates.detail. |
promote_candidate | Result of agent_candidates.promote. |
set_all_access | set_all_access returns the list produced by agent_access.change_all. |
set_access | Single change record from agent_access.change. |
agents | Fleet directory from agent_fleet.directory. |
agent | Merged agent_control.detail, overview, and max_run_seconds. |
activity | { "events": [...] } |
save | { "revision_id", "agent_id", "activation": null } on success (201). |
revision | { "config", "effective_config" } |
activate | { "state": "active", "agent_id", "active_revision", "generation", "activated_by" } |
audit_events | Result of agent_audit.query. |
audit_lineage | { "events": events } |
Behaviour and errors
Unknown agents. _known(agent_id) raises not_found("Agent is not registered") when agent_id is not in MANAGED_IDS. Used by agent detail, activity, drafts, revisions, activate, and per-agent access.
Candidates. candidate and promote_candidate translate LookupError to not_found with the lookup message.
Access changes. If stopped is false and reviewed is false, both access endpoints raise invalid("Review active actions before enabling agent access"). Per-agent access maps agent_access.AccessConflict to stale and ValueError to invalid.
Drafts and activation. save maps agent_control.AgentConflict to stale and ValueError to invalid. activate maps AgentConflict to stale, UnknownRevision to not_found, and ValueError to invalid. On successful activation the handler returns generation as expected_generation + 1.
Revisions. Unknown revision rows raise not_found("Unknown revision").
Audit queries. ValueError from agent_audit.query or governance_audit.query_lineage is turned into invalid.
Capability probe helper. _run_read_tool raises ProbeRefused when the tool handler is missing or when invoke_capability raises an HTTP error with status below 500; 5xx errors become RuntimeError.
Idempotency. save and activate wrap their mutations in idempotent with kinds agent.draft and agent.activate respectively.
Status codes. save is registered with status_code=201. Other routes use default success codes unless helpers map errors to specific HTTP statuses (for example not_found, invalid, stale from agent_http).
How the permission model applies
Each route’s handler is keyed in ROUTE_PERMISSIONS as agent_routes.<handler_name>. The console gate dependency refuses signed-in users whose role does not hold that permission (403 with a denied error). The table above lists those permission strings.
That mapping is a ceiling: handlers may require additional checks. Examples in this module:
require_role()orrequire_role(DRAFT_ROLES)for read and draft saves.require_admin()orrequire_admin("agents.manage")for admin-only mutations and diagnostics.require_console_write_trust(request)runs on every POST in this module, including the capability check, which does not call writes.
When sign-in is off, route role documentation notes the caller is treated as the OS admin on the machine; bearer-authenticated machine calls carry their own grants. Every handler in this module has a declared route permission; none are missing from the registry.
How is this page?
Last updated on