File size: 2,126 Bytes
d086025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Hooks System (Usage Reference)

Hooks intercept agent lifecycle events to enforce limits and safety rules. They
are built in; no user code is required. Two hooks are manageable at runtime via
the manager control plane (`topic_agent_hooks_enable` / `topic_agent_hooks_disable` /
`topic_agent_hooks_get`): `search_budget` and `timeout_report`. The completion and
tool-access hooks are protected and cannot be disabled.

## Active hooks

| Hook | Applies to | Behavior |
|------|-----------|----------|
| CompletionCheckHook | main + sub-agents | Verifies all todo tasks are done; forces extra iterations if not. |
| HotContextHealthHook | main + sub-agents | Monitors context health during execution. |
| ToolAccessPolicyHook | main agent | Blocks tools not allowed by the current profile (allowlist/blocklist). |
| SubAgentSafetyHook | sub-agents | Restricts iterations, token budget, and blocks dangerous tools for delegated tasks. |
| SearchBudgetHook | main + sub-agents | Limits web-search tool calls per session (default 10). |
| TimeoutReportHook | main + sub-agents | Produces a structured report when the agent time limit is reached. |

## Configurable limits (environment)

| Variable | Default | Purpose |
|----------|---------|---------|
| `AGENT_TIMEOUT_SECS` | 1800 | Agent time limit (30 minutes). |
| `AGENT_MAX_ITERATIONS` | 200 | Max iterations, main agent (env-overridable). |
| `SUB_AGENT_MAX_ITERATIONS` | 2000 | Max iterations, sub-agent (env-overridable). |
| `AGENT_SEARCH_LIMIT` | 10 | Search tool calls per session. |
| `AGENT_CONTINUATION_LIMIT` | 10 | Max forced continuations from completion checks. |
| `AGENT_MAX_TOKENS` | 200000 | Max tokens in memory (main agent). |

Sub-agents inherit the main-agent token budget unless an explicit override is set.

## Main vs sub-agent behavior

- Main agent: orchestrates, can delegate to sub-agents, governed by the profile's
  tool access policy.
- Sub-agent: executes a delegated subtask in an isolated session with a
  task-specific tool whitelist; cannot spawn further sub-agents; governed by
  SubAgentSafetyHook instead of the profile policy hook.