Loops
Cognition loops: main plus an agent's inner loops, their persisted history, context usage and compaction.
On this page
List cognition loops (main plus inner loops)
/agents/{id}/loopsPath parameters
| Name | Type | Description |
|---|---|---|
idrequired | string | Loaded agent: its id, handle or name. |
Responses
| Status | Description | Body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 200 | Loops with live status and declarations | LoopListResponse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
paramsarray<object> | provider_paramsobject | compact_thresholdinteger | null | toolsarray<string> | Absolute allow-list, intersected with the host's enabled tools entryCountrequiredinteger | Rows in this loop's adf_loop stream effectiveToolsrequiredarray<string> | null | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Errors 401 · 403 · 404 · 500
| 401 | Missing or wrong bearer token (unauthorized) | |
| 403 | The request guard refused it: Host header not allowed (host_not_allowed, DNS-rebinding protection) or a browser cross-site request (cross_origin)host_not_allowedcross_origin | |
| 404 | Unknown agent (or the named resource: loop, task, file, …) | |
| 500 | Unexpected runtime failure |
Error bodies use the error format.
Example
curl "http://127.0.0.1:7385/agents/agent-1/loops" \
-H "Authorization: Bearer $ADF_DAEMON_TOKEN"Create an inner loop
/agents/{id}/loopsGoes through the agent's loop pool, the same path as the loop_manage tool: same validation, tool attenuation and owner locks (locked_fields: ["loops"]). Defaults: enabled and autostart true; tools loop_send + loop_list + sys_set_state (filtered to what the host can grant). An enabled autostart loop is kicked off at once through loop_send (kickoff). excludedTools: requested tools the host has disabled, carried by name and granted once enabled. 400 invalid declaration (bad name, unknown or never-grantable tool); 409 for main, a duplicate name, the loop cap, or loops locked by the owner.
Path parameters
| Name | Type | Description |
|---|---|---|
idrequired | string | Loaded agent: its id, handle or name. |
Request bodyapplication/json · LoopCreateBody · required
| Field | Type | Description |
|---|---|---|
namerequired | string | |
goalrequired | string | |
enabled | boolean | |
autostart | boolean | |
autonomous | boolean | |
model | object | |
compact_threshold | integer | null | |
tools | array<string> | Default: loop_send, loop_list, sys_set_state (filtered to what the host can grant) |
Responses
| Status | Description | Body | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 201 | Created | LoopCreateResponse | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
entryCountrequiredinteger | Rows in this loop's adf_loop stream effectiveToolsrequiredarray<string> | null | effectiveToolsrequiredarray<string> | excludedToolsrequiredarray<string> | kickoffrequiredLoopSendResult | null | 3 fields of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
deliveredrequired | boolean | |
wokerequired | boolean | |
reason | string |
Errors 400 · 401 · 403 · 404 · 409 · 500
| 400 | Invalid request: missing or malformed field, query parameter or body. A body Fastify cannot parse gets Fastify's own shape (statusCode, code, error, message).bad_requestFST_ERR_CTP_EMPTY_JSON_BODY | |
| 401 | Missing or wrong bearer token (unauthorized) | |
| 403 | The request guard refused it: Host header not allowed (host_not_allowed, DNS-rebinding protection) or a browser cross-site request (cross_origin)host_not_allowedcross_origin | |
| 404 | Unknown agent (or the named resource: loop, task, file, …) | |
| 409 | The resource is in a state that does not allow this now | |
| 500 | Unexpected runtime failure |
Error bodies use the error format.
Example
curl -X POST "http://127.0.0.1:7385/agents/agent-1/loops" \
-H "Authorization: Bearer $ADF_DAEMON_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "reflector",
"goal": "Review the day'\''s work and write lessons to mind.md."
}'Read one loop
/agents/{id}/loops/{name}Path parameters
| Name | Type | Description |
|---|---|---|
idrequired | string | Loaded agent: its id, handle or name. |
namerequired | string | Loop name ( |
Responses
| Status | Description | Body | ||||||
|---|---|---|---|---|---|---|---|---|
| 200 | The loop | LoopResponse | ||||||
| ||||||||
Errors 401 · 403 · 404 · 500
| 401 | Missing or wrong bearer token (unauthorized) | |
| 403 | The request guard refused it: Host header not allowed (host_not_allowed, DNS-rebinding protection) or a browser cross-site request (cross_origin)host_not_allowedcross_origin | |
| 404 | Unknown agent (or the named resource: loop, task, file, …) | |
| 500 | Unexpected runtime failure |
Error bodies use the error format.
Example
curl "http://127.0.0.1:7385/agents/agent-1/loops/reflector" \
-H "Authorization: Bearer $ADF_DAEMON_TOKEN"Patch an inner loop
/agents/{id}/loops/{name}Present keys replace wholesale; "model": null / "compact_threshold": null remove the override so the loop inherits main's again. The loop is re-derived at once; enabled: false stops a running loop now (its turn is aborted and flushed). Loops cannot be renamed and an empty patch is refused (400). main is not managed here (409; change the agent config).
Path parameters
| Name | Type | Description |
|---|---|---|
idrequired | string | Loaded agent: its id, handle or name. |
namerequired | string | Loop name ( |
Request bodyapplication/json · LoopPatchBody · required
At least one field. null clears model / compact_threshold. Loops cannot be renamed.
| Field | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
goal | string | |||||||||||||||||||||||||||||||||||||||||||||||||
enabled | boolean | false stops the loop immediately | ||||||||||||||||||||||||||||||||||||||||||||||||
autostart | boolean | |||||||||||||||||||||||||||||||||||||||||||||||||
autonomous | boolean | |||||||||||||||||||||||||||||||||||||||||||||||||
model | ModelConfig | null | |||||||||||||||||||||||||||||||||||||||||||||||||
9 fields of | ||||||||||||||||||||||||||||||||||||||||||||||||||
providerrequired | string | Provider id (app provider or one of the agent's own providers) | |||||||||
model_idrequired | string | ||||||||||
temperature | number | null | ||||||||||
max_tokens | integer | null | ||||||||||
top_p | number | null | ||||||||||
reasoning | object | Provider-agnostic reasoning ("thinking") config | |||||||||
multimodal | object | ||||||||||
3 fields of | |||||||||||
image | boolean | |
audio | boolean | |
video | boolean |
params2 fields of params
keyrequired | string | |
valuerequired | string |
provider_paramscompact_thresholdtoolsResponses
| Status | Description | Body | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 200 | Updated | LoopUpdateResponse | ||||||||||||
| ||||||||||||||
Errors 400 · 401 · 403 · 404 · 409 · 500
| 400 | Invalid request: missing or malformed field, query parameter or body. A body Fastify cannot parse gets Fastify's own shape (statusCode, code, error, message).bad_requestFST_ERR_CTP_EMPTY_JSON_BODY | |
| 401 | Missing or wrong bearer token (unauthorized) | |
| 403 | The request guard refused it: Host header not allowed (host_not_allowed, DNS-rebinding protection) or a browser cross-site request (cross_origin)host_not_allowedcross_origin | |
| 404 | Unknown agent (or the named resource: loop, task, file, …) | |
| 409 | The resource is in a state that does not allow this now | |
| 500 | Unexpected runtime failure |
Error bodies use the error format.
Example
curl -X PATCH "http://127.0.0.1:7385/agents/agent-1/loops/reflector" \
-H "Authorization: Bearer $ADF_DAEMON_TOKEN" \
-H "Content-Type: application/json" \
-d '{"enabled":false}'Stop, archive and remove an inner loop
/agents/{id}/loops/{name}Stops the loop (mid-turn included), archives its stream to adf_audit under loop:<name>, drops its timers (locked timers are kept), then removes it. 409 for main.
Path parameters
| Name | Type | Description |
|---|---|---|
idrequired | string | Loaded agent: its id, handle or name. |
namerequired | string | Loop name ( |
Responses
| Status | Description | Body | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 200 | Deleted | LoopDeleteResponse | ||||||||||||
| ||||||||||||||
Errors 401 · 403 · 404 · 409 · 500
| 401 | Missing or wrong bearer token (unauthorized) | |
| 403 | The request guard refused it: Host header not allowed (host_not_allowed, DNS-rebinding protection) or a browser cross-site request (cross_origin)host_not_allowedcross_origin | |
| 404 | Unknown agent (or the named resource: loop, task, file, …) | |
| 409 | The resource is in a state that does not allow this now | |
| 500 | Unexpected runtime failure |
Error bodies use the error format.
Example
curl -X DELETE "http://127.0.0.1:7385/agents/agent-1/loops/reflector" \
-H "Authorization: Bearer $ADF_DAEMON_TOKEN"Read persisted loop entries (paginated)
/agents/{id}/loopThe durable conversation history. limit default 50 (clamped 1–500); offset default = the last page.
Path parameters
| Name | Type | Description |
|---|---|---|
idrequired | string | Loaded agent: its id, handle or name. |
Query parameters
| Name | Type | Description |
|---|---|---|
limit | integer | Maximum rows to return |
offset | integer | Rows to skip |
loop | string | Cognition loop to address. Absent = main. Unknown loops answer 404. |
Responses
| Status | Description | Body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 200 | A page of adf_loop rows | LoopPage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
created_atrequiredinteger | Epoch ms | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Errors 400 · 401 · 403 · 404 · 500
| 400 | Invalid request: missing or malformed field, query parameter or body. A body Fastify cannot parse gets Fastify's own shape (statusCode, code, error, message).bad_requestFST_ERR_CTP_EMPTY_JSON_BODY | |
| 401 | Missing or wrong bearer token (unauthorized) | |
| 403 | The request guard refused it: Host header not allowed (host_not_allowed, DNS-rebinding protection) or a browser cross-site request (cross_origin)host_not_allowedcross_origin | |
| 404 | Unknown agent (or the named resource: loop, task, file, …) | |
| 500 | Unexpected runtime failure |
Error bodies use the error format.
Example
curl "http://127.0.0.1:7385/agents/agent-1/loop" \
-H "Authorization: Bearer $ADF_DAEMON_TOKEN"One loop's context usage
/agents/{id}/contextWhat the next request of main (or ?loop=) would carry: the executor's breakdown split into non-overlapping categories (system, files, tools, mcp:<server>, dynamic, messages; biggest first, summing to totalTokens) with their biggest items, plus the compact threshold that loop auto-compacts at. Figures are the executor's own: system prompt and tool schemas measured with the provider tokenizer when it rebuilds them; conversation (compaction summary included) and dynamic instructions estimated per read. compactThreshold resolves like the executor: the loop's compact_threshold, else the agent's context.compact_threshold, else the (loop's or agent's) model's, else 100000 (compactThresholdSource: loop · agent · model · default); agentCompactThreshold is main's, for comparison. available: false (empty categories, null totals) when the loop has no live executor: disabled, never woken or put to sleep.
Path parameters
| Name | Type | Description |
|---|---|---|
idrequired | string | Loaded agent: its id, handle or name. |
Query parameters
| Name | Type | Description |
|---|---|---|
loop | string | Cognition loop to address. Absent = main. Unknown loops answer 404. |
items | integer | Items per category (default 12, max 200) |
Responses
| Status | Description | Body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 200 | Context usage | AgentContextResponse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
compactThresholdrequiredinteger | compactThresholdSourcerequiredstring | agentCompactThresholdrequiredinteger | totalTokensrequiredinteger | null | percentrequiredinteger | null | totalTokens / compactThreshold, rounded percent categoriesrequiredarray<ContextCategory> | 7 fields of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
idrequired | string | The key, or | |||||||||
keyrequired | string | ||||||||||
labelrequired | string | ||||||||||
tokensrequired | integer | ||||||||||
count | integer | ||||||||||
itemsrequired | array<object> | ||||||||||
3 fields of | |||||||||||
namerequired | string | |
tokensrequired | integer | |
detail | string |
noterequiredbreakdownrequired9 fields of breakdown
system_prompt_tokensrequired | integer | |||||||||||||||||||
system_prompt_partsrequired | object | |||||||||||||||||||
3 fields of | ||||||||||||||||||||
base_and_sectionsrequired | integer | |
runtime_blocksrequired | integer | |
instructionsrequired | integer |
injected_filesrequired2 fields of injected_files
pathrequired | string | |
tokensrequired | integer |
tool_groupsrequired3 fields of tool_groups
sourcerequired | string |
| ||||||
tokensrequired | integer | |||||||
toolsrequired | array<object> | |||||||
2 fields of | ||||||||
namerequired | string | |
tokensrequired | integer |
tools_total_tokensrequireddynamic_instructions_tokensrequiredmessages_tokensrequiredoverhead_tokensrequiredcomputed_atrequiredEpoch ms
Errors 400 · 401 · 403 · 404 · 500
| 400 | Invalid request: missing or malformed field, query parameter or body. A body Fastify cannot parse gets Fastify's own shape (statusCode, code, error, message).bad_requestFST_ERR_CTP_EMPTY_JSON_BODY | |
| 401 | Missing or wrong bearer token (unauthorized) | |
| 403 | The request guard refused it: Host header not allowed (host_not_allowed, DNS-rebinding protection) or a browser cross-site request (cross_origin)host_not_allowedcross_origin | |
| 404 | Unknown agent (or the named resource: loop, task, file, …) | |
| 500 | Unexpected runtime failure |
Error bodies use the error format.
Example
curl "http://127.0.0.1:7385/agents/agent-1/context" \
-H "Authorization: Bearer $ADF_DAEMON_TOKEN"Compact one loop's history now
/agents/{id}/compactSummarize-and-replace on demand for main, or the named inner loop. Emits loop.compacted; triggers queue and chats replay after it. 409 mid-turn, already compacting, nothing to compact, or a disabled loop; 502 when summarization fails (history preserved).
Path parameters
| Name | Type | Description |
|---|---|---|
idrequired | string | Loaded agent: its id, handle or name. |
Query parameters
| Name | Type | Description |
|---|---|---|
loop | string | Cognition loop to address. Absent = main. Unknown loops answer 404. |
Request bodyapplication/json · LoopBody · optional
Optional; ?loop= wins.
| Field | Type | Description |
|---|---|---|
loop | string | Cognition loop; absent = main. The |
Responses
| Status | Description | Body | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 200 | Compacted | CompactResponse | |||||||||
| |||||||||||
Errors 401 · 403 · 404 · 409 · 500 · 502
| 401 | Missing or wrong bearer token (unauthorized) | |
| 403 | The request guard refused it: Host header not allowed (host_not_allowed, DNS-rebinding protection) or a browser cross-site request (cross_origin)host_not_allowedcross_origin | |
| 404 | Unknown agent (or the named resource: loop, task, file, …) | |
| 409 | The resource is in a state that does not allow this now | |
| 500 | Unexpected runtime failure | |
| 502 | An upstream call failed (e.g. the summarization request of a compaction); nothing was changed |
Error bodies use the error format.
Example
curl -X POST "http://127.0.0.1:7385/agents/agent-1/compact" \
-H "Authorization: Bearer $ADF_DAEMON_TOKEN" \
-H "Content-Type: application/json" \
-d '{}'