Skip to content

Step Lifecycle Events

The step loop emits mutable events at every boundary. Matchers registered for the event type string may modify event fields (the hook reads them back) or raise StepAbortError for control flow.

python
from amrita_sense.hook.matcher import Matcher

matcher = Matcher("agent.tool_call", priority=1)


@matcher.handle()
async def guard(event):
    event.cancel = True


# clean up after the test / run:
# matcher._dead_at = <past datetime>

Use the literal string ("agent.step_intro"), not StepIntroEvent.event_type — the latter is a property object.

StepAbortError

BaseException raised by matchers to abort the current operation — passed via exception_ignored so it propagates out of trigger_event to the hook, which decides how to act (skip the work, end the Step early, ...).

Events

StepIntroEvent — agent.step_intro

Broadcast when a Step begins (intro_step).

FieldMeaning
step_indexGlobal step counter
phaseThe phase being entered
simple_modeBare run (no DAG)?
plan_summaryFirst 5 plan descriptions
override_phaseMutable — redirect the phase name

StepLeaveEvent — agent.step_leave

Broadcast when a Step finishes (leave_step).

FieldMeaning
step_index / phaseWhich Step
verb / objectThe auto summary (subject-predicate)
stall_injectedGive-up prompt was injected?
override_verb / override_objectMutable — replace the summary

StepIterationEvent — agent.step_iteration

Broadcast after each tool round inside the execute Step.

FieldMeaning
step_index / phaseWhich Step
tool_signaturesSignatures in the current window
end_stepMutable — force-end the Step

StepToolCallEvent — agent.tool_call

Broadcast before a regular tool executes (built-in tools excluded).

FieldMeaning
tool_name / tool_idThe tool call
argumentsMutable — rewrite the call arguments
cancelMutable — cancel without executing (returns "Cancelled: ...")

StepToolReturnEvent — agent.tool_return

Broadcast after a regular tool returned.

FieldMeaning
tool_name / tool_idThe tool call
resultMutable — rewrite what the model sees
skip_appendMutable — skip writing the result back to context

All events are constructed from AgentRunState via their constructor() classmethod.

Apache 2.0 License