Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

docs(hitl): fix 4 BLOCKING + 4 SHOULD-FIX from codex doc review

xf gong4c438ae4650c
diff --git a/website/docs/getting-started/core-concepts.md b/website/docs/getting-started/core-concepts.md
index 0112a2e..e9bd4e5 100644
--- a/website/docs/getting-started/core-concepts.md
+++ b/website/docs/getting-started/core-concepts.md
@@ -99,7 +99,7 @@ Streams and events are two layers:
- **Provider streams** — `MessageStream` yields *provider* events:
`start`, `text_start`, `text_delta`, `text_end`, `thinking_*`,
`toolcall_*`, `done`, `error`. This is the raw token stream.
-- **Agent events** — what `agent.subscribe(...)` receives. 15
+- **Agent events** — what `agent.subscribe(...)` receives. 14
types covering the entire loop + HITL: `agent_start`, `agent_end`,
`turn_start`, `turn_end`, `message_start`, `message_update`,
`message_end`, `tool_execution_start`, `tool_execution_update`,
diff --git a/website/docs/guides/agents/tool-use.md b/website/docs/guides/agents/tool-use.md
index b3b39b8..7efa9e7 100644
--- a/website/docs/guides/agents/tool-use.md
+++ b/website/docs/guides/agents/tool-use.md
@@ -81,9 +81,9 @@ There are two ways to opt out of parallel mode:
)
```
-The built-in `ask_user` HITL tool (see [HITL guide](../hitl)) uses
-`execution_mode="sequential"` — it pauses the agent for human input and
-cannot share a turn with other tools.
+The built-in `ask_user` HITL tool (see [HITL guide](../hitl)) sets
+`execution_mode="sequential"` — it pauses the agent for human input, so
+the tool batch runs one-by-one.
Use sequential mode when tools mutate shared state (a DB, a counter)
and you want a deterministic order.
diff --git a/website/docs/guides/hitl.md b/website/docs/guides/hitl.md
index f086927..a9338ae 100644
--- a/website/docs/guides/hitl.md
+++ b/website/docs/guides/hitl.md
@@ -229,7 +229,7 @@ The policy function can be sync or async (`await`-able). It returns one of:
|---|---|
| `Approve()` | Tool runs; channel never invoked. |
| `Deny(reason)` | Tool blocked; `hitl_trace["decision"]="policy_deny"`. |
-| `AskUser(timeout=..., details=...)` | Channel invoked; human chooses approve/deny/edit. |
+| `AskUser(timeout_seconds=..., details=...)` | Channel invoked; human chooses approve/deny/edit. |
Policy-deny and human-deny produce different `hitl_trace` keys (`policy_deny`
vs `human_deny`) so audit and trace can distinguish them.
diff --git a/website/docs/guides/middleware/composition.md b/website/docs/guides/middleware/composition.md
index 60341d7..d0a4c02 100644
--- a/website/docs/guides/middleware/composition.md
+++ b/website/docs/guides/middleware/composition.md
@@ -73,7 +73,7 @@ agent = Agent(
If `RateLimiter` returns `block=True`, `SafetyFilter` and
`AuditLogger`'s `before_tool_call` don't run. If `SafetyFilter` returns
`edited_args={"cmd": "rm /tmp/foo"}`, the *tool* runs with the edited
-args and `AuditLogger` sees the edit in `hitl_trace["_chain"]`.
+args and `AuditLogger` sees them via the rebuilt `ctx.args`.
`AuditLogger.after_tool_call` still fires because that's a different
hook.
diff --git a/website/docs/recipes/ask-user-form.md b/website/docs/recipes/ask-user-form.md
index c10ea90..0bc3374 100644
--- a/website/docs/recipes/ask-user-form.md
+++ b/website/docs/recipes/ask-user-form.md
@@ -29,8 +29,8 @@ agent = Agent(
```
The `ask_user` tool is registered like any other tool. Its
-`execution_mode="sequential"` ensures it runs alone in its turn — it can't
-be parallelised with other tool calls.
+`execution_mode="sequential"` makes the tool batch run one-by-one —
+the HITL pause can't overlap with parallel tool execution.
## Step 2: Host renders the form
diff --git a/website/docs/recipes/sandbox-confirm.md b/website/docs/recipes/sandbox-confirm.md
index 48f4ab0..e0eb804 100644
--- a/website/docs/recipes/sandbox-confirm.md
+++ b/website/docs/recipes/sandbox-confirm.md
@@ -26,7 +26,7 @@ def classify_command(cmd: str) -> tuple[str, str | None]:
def sandbox_policy(ctx):
- cmd = ctx.args.get("cmd", "")
+ cmd = ctx.args.cmd # ctx.args is the validated pydantic model
tier, reason = classify_command(cmd)
if tier == "allow":
@@ -39,9 +39,10 @@ def sandbox_policy(ctx):
)
```
-Arguments (`ctx.args`) are a **pydantic model** when the tool declares
-`parameters=SomePydanticModel`. Access fields as attributes
-(`ctx.args.cmd`) or dict-key (`ctx.args.get("cmd")` if using `_args_to_dict`).
+`ctx.args` is the **validated pydantic model**. Access fields as
+attributes (`ctx.args.cmd`). The middleware internally converts it to a
+dict via `_args_to_dict` for the channel's approve payload, but your
+policy receives the typed model.
## Step 2: Wire into the agent
@@ -92,10 +93,13 @@ async def host_loop(channel: CheckpointedChannel):
details=details,
timeout=timeout,
)
- # human_answer is an ApproveAnswer with one of:
- # {"decision": "approve"}
- # {"decision": "deny", "reason": "looks suspicious"}
- # {"decision": "edit", "edited_args": {"cmd": "rm /tmp/foo"}}
+ # Build an ApproveAnswer from the human's decision.
+ from cubepi.hitl import ApproveAnswer
+ human_answer = ApproveAnswer(
+ decision=ui_response["decision"], # "approve" | "deny" | "edit"
+ reason=ui_response.get("reason"), # only for deny
+ edited_args=ui_response.get("edited_args"), # only for edit
+ )
await channel.answer(req.question_id, human_answer)
elif req.payload.kind == "ask":
await channel.answer(req.question_id, await my_frontend.show_form(req))
@@ -107,7 +111,7 @@ async def host_loop(channel: CheckpointedChannel):
| Human chose | Tool outcome | `hitl_trace["decision"]` | Model sees |
|---|---|---|---|
-| Approve | Runs with original args | `"approved"` | Normal `tool_result` |
+| Approve | Runs with original args | unset (passthrough, no HITL details) | Normal `tool_result` |
| Deny | Blocked | `"human_deny"` | `tool_result.is_error=True` with user's reason |
| Edit | Runs with edited args | `"edit"` + `original_args` / `edited_args` | Normal `tool_result` (from the edited execution) |