Events & Observability
Subscribe to lightweight runtime events for observability, progress reporting, and safety gates.
Overview
AbstractCore emits events for generation, tool execution, retries, sessions, and compaction. Use these hooks to build metrics, dashboards, or guardrails around tool usage without tying yourself to a specific provider.
Keep event handlers fast. If you need heavier work (I/O, uploads, analytics), enqueue to a background worker.
Global event handlers
Register a process-wide handler with on_global():
from abstractcore import create_llm
from abstractcore.events import EventType, on_global
def on_event(event):
print(event.type.value, event.source, event.data)
on_global(EventType.GENERATION_COMPLETED, on_event)
llm = create_llm("ollama", model="qwen3:4b")
llm.generate("Say 'ok' and nothing else.")
Common event types
EventType.GENERATION_STARTED/EventType.GENERATION_COMPLETEDEventType.TOOL_STARTED/EventType.TOOL_PROGRESS/EventType.TOOL_COMPLETEDEventType.RETRY_ATTEMPTED/EventType.RETRY_EXHAUSTEDEventType.VALIDATION_FAILEDEventType.COMPACTION_STARTED/EventType.COMPACTION_COMPLETED
For the full list, see API Reference (Event System).
Async handlers
If you need async handlers, use GlobalEventBus.on_async(...) (or per-emitter on_async(...)) and emit events with the
async emission methods. Most applications only need the sync hooks above.