Steering¶
The steering inbox and event types that let external callers cancel or redirect an in-flight planner run.
steering
¶
Steering event models and inbox for bidirectional control.
SteeringInbox
¶
SteeringInbox(*, maxsize: int = 100, max_pending_user_messages: int = 2)
Async inbox that buffers steering events and exposes cancellation state.
A running task (typically the ReactPlanner loop) polls or awaits this inbox to react to
externally published :class:~penguiflow.state.models.SteeringEvent records —
cancelling, pausing/resuming, or draining events to fold into the next planning step.
CANCEL and PAUSE/RESUME events are handled specially at :meth:push time so
their effects (cancelled, wait_if_paused) are visible even before the event is
drained from the queue.
Initialize the inbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maxsize
|
int
|
Maximum number of buffered steering events before :meth: |
100
|
max_pending_user_messages
|
int
|
Maximum number of undrained |
2
|
cancel_reason
property
¶
cancel_reason: str | None
The reason string from the most recent CANCEL event, if any was pushed.
cancel_event
property
¶
cancel_event: Event
The underlying :class:asyncio.Event set when a CANCEL event is pushed.
push
async
¶
push(event: SteeringEvent) -> bool
Queue a steering event, returning False if the queue is full.
CANCEL events set :attr:cancel_event and record :attr:cancel_reason;
PAUSE/RESUME events immediately toggle the pause gate used by
:meth:wait_if_paused — both take effect even if the queue itself is full.
USER_MESSAGE events are additionally capped by max_pending_user_messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
SteeringEvent
|
The steering event to enqueue. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
has_event
¶
has_event() -> bool
Check if there are queued steering events without draining them.
Returns:
| Type | Description |
|---|---|
bool
|
|
drain
¶
drain() -> list[SteeringEvent]
Drain any queued steering events without blocking.
Returns:
| Type | Description |
|---|---|
list[SteeringEvent]
|
All currently buffered events, in FIFO order; an empty list if none are queued. |
next
async
¶
next() -> SteeringEvent
Wait for the next steering event.
Returns:
| Type | Description |
|---|---|
SteeringEvent
|
The next :class: |
wait_if_paused
async
¶
wait_if_paused() -> None
Block until a RESUME arrives if the task is paused.
No-op if the inbox is not currently paused (i.e. no PAUSE event is outstanding).
SteeringEvent
¶
SteeringEventType
¶
Bases: str, Enum
SteeringCancelled
¶
SteeringCancelled(reason: str | None = None)
Bases: RuntimeError
Raised when a steering cancel event terminates a task.
Attributes:
| Name | Type | Description |
|---|---|---|
reason |
Human-readable reason for the cancellation (defaults to
|
Initialize the exception with an optional cancellation reason.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
str | None
|
Human-readable reason for the cancellation, taken from the |
None
|