Lifecycle Management

Runs

Runs track the execution lifecycle of an agent. All events within a run are correlated via run_id. A run.end event is automatically emitted when the context exits:

with alm.run(purpose="Answer user question"):
    # Your agent logic here
    pass
# run.end event automatically emitted with summary statistics

Tasks

Tasks represent logical units of work within a run. They automatically emit task.start and task.end events:

with alm.run():
    with alm.task(description="Process input"):
        # Task logic
        pass
    
    with alm.task(description="Generate output"):
        # Task logic
        pass

Handoffs

Handoffs represent agent-to-agent transitions. Emit a handoff event when delegating to another agent:

alm.handoff(
    to_agent_id="specialist-agent",
    reason="Requires domain expertise",
    context={"query": user_query}
)

Event Types

  • run.start – Run started
  • run.end – Run finished
  • tool.request – Tool call initiated
  • policy.decision – Allow or deny
  • tool.response – Tool completed
  • task.start / task.end – Task lifecycle
  • handoff – Agent-to-agent handoff