CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.
Python agent-frameworkagent-harnessagent-runtimeagentic-aiai-agentsai-frameworkanthropicharnessharness-engineeringharness-frameworklanggraphlanggraph-alternativellmmcpopenaipi-agentpi-agent-corepythonpython-agent
fix(hitl): thread cur_ctx through middleware chain + document loop silent catch design
xf gong5dcd38bdd4a4
diff --git a/cubepi/agent/loop.py b/cubepi/agent/loop.pyindex cc09a64..1dd78b3 100644--- a/cubepi/agent/loop.py+++ b/cubepi/agent/loop.py@@ -180,9 +180,14 @@ async def _run_loop(emit=emit,)except (HitlDetached, HitlAborted):- # Caller (Agent.detach / Agent.abort_pending) emitted the event- # already. Loop exits silently — assistant message and pending- # state remain intact for the next respond() call.+ # Per the spec design, HITL terminal events (AgentSuspendedEvent /+ # AgentAbortedEvent) are emitted by the Agent layer (Agent.detach()+ # / Agent.abort_pending()) BEFORE these exceptions are raised — they+ # are mutually exclusive with AgentEndEvent. The loop intentionally+ # exits silently here: emitting AgentEndEvent would double-signal+ # termination to event-stream consumers who already saw the HITL+ # event. Assistant message and pending state remain intact for the+ # next respond() call.returndiff --git a/cubepi/middleware/base.py b/cubepi/middleware/base.pyindex 013715e..9f33bd6 100644--- a/cubepi/middleware/base.py+++ b/cubepi/middleware/base.py@@ -102,7 +102,7 @@ def compose_middleware(middlewares: list[Middleware]) -> dict[str, Callable]:cur_ctx = ctxfor mw in before_chain:if edited_args is not None:- cur_ctx = _rebuild_ctx_with_args(ctx, edited_args)+ cur_ctx = _rebuild_ctx_with_args(cur_ctx, edited_args)result = await mw.before_tool_call(cur_ctx, signal=signal)if result is None:continue