Logging API Reference
The complete API reference for the event-based logging system of agent-actions.
Public API
fire_event()
Emits an event to all registered handlers.
from agent_actions.logging.core.manager import fire_event
from agent_actions.logging.events import WorkflowStartEvent
fire_event(WorkflowStartEvent(
workflow_name="my_workflow",
action_count=5,
))
Note: Every event class sets its own level, category, message and data in __post_init__. If you give a message, the event class replaces it.
Parameters:
event(BaseEvent): The event instance to fire
Returns: None
Context Enrichment:
Before dispatch, the EventManager copies its context into the meta of the event. invocation_id and correlation_id go to their own fields. Every other key goes to meta.extra.
get_manager()
Gets the EventManager singleton instance.
from agent_actions.logging.core.manager import get_manager
manager = get_manager()
manager.set_context(workflow_name="my_workflow")
Returns: EventManager instance
LoggerFactory
A factory class that initializes and manages the logging system.
LoggerFactory.initialize()
Initializes the unified logging system with event handlers.
from agent_actions.logging.factory import LoggerFactory
manager = LoggerFactory.initialize(
output_dir="/path/to/workflow/agent_io",
workflow_name="my_workflow",
invocation_id="run_abc123",
verbose=True,
force=True,
new_run=True,
)
Parameters:
config(Optional[LoggingConfig]): The logging configuration. If None, the factory keeps the configuration that an earlier call set. If there was no earlier call, the factory reads theAGENT_ACTIONS_*environment variables.output_dir(Optional[str | Path]): The directory whoselogs/subdirectory receivesevents.json,errors.jsonandrun_results.json. Defaults to None.workflow_name(str): The name of the workflow that runs. Defaults to "".invocation_id(Optional[str]): A unique ID for this invocation. If you do not give it, the factory generates an 8-character ID.verbose(Optional[bool]): Shows DEBUG level events, all categories and diagnostic events on the console.None(the default) keeps the value that a previous call configured. Thus aforce=Truere-init that does not giveverbosedoes not discard the flags of the CLI.quiet(Optional[bool]): Shows only WARN and ERROR events on the console.None(the default) keeps the value that a previous call configured.force(bool): Initializes again, also if the system is already initialized. Defaults to False.new_run(bool): Marks the start of a workflow run. The run logs inoutput_dir/logsrotate first. Thusevents.jsonholds only this run. Other commands append to the file of the current run. Defaults to False.
Returns: The EventManager instance
Side Effects:
- Creates and registers ProgressRenderer (the console handler of the run)
- Creates and registers two JSONFileHandler instances (if you give output_dir):
logs/events.jsonat DEBUG andlogs/errors.jsonat ERROR - Creates and registers RunResultsCollector (it writes
logs/run_results.jsononly if you give output_dir) - Configures LoggingBridgeHandler to convert Python logging to events
- Sets the correlation context (invocation_id, workflow_name)
Example:
# Typical CLI initialization
manager = LoggerFactory.initialize(
output_dir=agent_folder,
workflow_name="product_analysis",
invocation_id="run_xyz789",
verbose=args.verbose,
force=True,
)
# Events are now routed to:
# - Console (stderr, Rich-formatted when Rich is available)
# - agent_folder/logs/events.json
# - agent_folder/logs/errors.json
# - agent_folder/logs/run_results.json
LoggerFactory.get_logger()
Gets a Python logger that routes through the event system.
logger = LoggerFactory.get_logger("my_module")
logger.info("Processing item") # Converted to LogEvent
Parameters:
name(str): The logger name. If the name does not start with 'agent_actions.', the factory adds this prefix automatically.
Returns: A logging.Logger instance. If the factory is not initialized, the call initializes it first.
Note: Every record logged under the agent_actions namespace is converted to a LogEvent. EventManager routes the LogEvent.
LoggerFactory.set_context()
Sets shared context values for all events.
LoggerFactory.set_context(
workflow_name="my_workflow",
correlation_id="abc123",
)
Parameters:
**kwargs: Context key-value pairs of any kind
Returns: None
The context attaches automatically to all events emitted after this call, for all actions that fire them. Put a value for one action or one batch in EventManager.context() or in the fields of the event.
LoggerFactory.flush()
Flushes all event handlers (writes the buffered data).
try:
run_workflow()
finally:
LoggerFactory.flush() # Ensure all events are written
Returns: None
Important: Always call this method before the process exits. This makes sure that the buffered events are written.
LoggerFactory.get_event_manager()
Gets the current EventManager instance.
manager = LoggerFactory.get_event_manager()
Returns: Optional[EventManager]
Returns None if: LoggerFactory is not initialized yet.
LoggerFactory.reset()
Resets the state of the factory (for tests).
LoggerFactory.reset()
Returns: None
Warning: This method clears all handlers and the state. Use it only in tests.
EventManager
The central event dispatcher. It routes events to handlers.
EventManager.get()
Gets the EventManager singleton instance.
from agent_actions.logging.core.manager import EventManager
manager = EventManager.get()
Returns: EventManager instance
EventManager.initialize()
Marks the EventManager as initialized.
manager.initialize()
Returns: None
Note: LoggerFactory.initialize() calls this method automatically.
EventManager.register()
Registers an event handler.
from agent_actions.logging.core.handlers import ConsoleEventHandler
handler = ConsoleEventHandler()
manager.register(handler)
Parameters:
handler(EventHandler): A handler instance withaccepts(),handle()andflush()methods. If the handler has aclose()method, the manager calls it on reset.
Returns: None
EventManager.unregister()
Removes a registered handler. If the handler is not registered, the method does nothing.
manager.unregister(handler)
Parameters:
handler(EventHandler): The handler instance to remove
Returns: None
EventManager.fire()
Fires an event to all registered handlers.
from agent_actions.logging.events import WorkflowStartEvent
event = WorkflowStartEvent(workflow_name="my_workflow", action_count=3)
manager.fire(event)
Parameters:
event(BaseEvent): The event to fire
Returns: None
Note: The manager adds the context to the event before it dispatches the event.
EventManager.set_context()
Sets the correlation context for all events.
manager.set_context(
workflow_name="my_workflow",
correlation_id="abc123",
)
Parameters:
**kwargs: Context key-value pairs
Returns: None
The values apply to the full process. Every later event in the process carries them in meta, for all actions that fire it. A value for one action or one batch belongs in context() below, or in the data of the event. For example, a batch id is in data.batch_id of the batch events.
EventManager.context()
A context manager that overrides the context temporarily.
with manager.context(workflow_name="upstream"):
fire_event(WorkflowStartEvent(workflow_name="upstream", action_count=2))
# event.meta.extra["workflow_name"] == "upstream"
# Context restored to previous value
The override is local to the current thread or coroutine. Calls can nest.
Parameters:
**kwargs: Temporary context values
Returns: Context manager
Yields: None
EventManager.flush()
Flushes all registered handlers.
manager.flush()
Returns: None
EventManager.reset()
Resets the state of the EventManager (for tests).
EventManager.reset()
Returns: None
Warning: This method clears all handlers and the context. Use it only in tests.
Event Classes
All event classes inherit from BaseEvent. All event classes are dataclasses.
BaseEvent
The base class for all events.
from dataclasses import dataclass
from agent_actions.logging.core.events import BaseEvent, EventLevel
@dataclass
class MyEvent(BaseEvent):
custom_field: str = ""
def __post_init__(self) -> None:
self.level = EventLevel.INFO
self.category = "system"
self.message = f"My event: {self.custom_field}"
self.data = {"custom_field": self.custom_field}
Attributes:
level(EventLevel): The severitycategory(str): The event category. See EventCategoriesmessage(str): A message that a person can readmeta(EventMeta):timestamp,correlation_id,invocation_id,thread_idandextra(the other context keys)data(Dict[str, Any]): Structured event datadiagnostic(bool): Marks framework internals, not something that the user can act on. The file handlers keep these events. The console drops them, unless the run is verboseevent_type(str, read-only property): The event class name, such as"ActionStartEvent"
Workflow Events
WorkflowStartEvent
Emitted when a workflow starts to run.
from agent_actions.logging.events import WorkflowStartEvent
fire_event(WorkflowStartEvent(
workflow_name="my_workflow",
action_count=5,
execution_mode="async",
))
Note: The event class generates the message field from workflow_name and action_count.
Fields:
workflow_name(str): Workflow nameaction_count(int): The number of actions in the workflowexecution_mode(str):"sequential"or"async". The workflow runner sets it. It defaults to"sequential"
WorkflowCompleteEvent
Emitted when a workflow completes successfully.
from agent_actions.logging.events import WorkflowCompleteEvent
fire_event(WorkflowCompleteEvent(
workflow_name="my_workflow",
elapsed_time=119.5,
actions_completed=5,
actions_partial=0,
actions_skipped=0,
actions_failed=0,
total_tokens=12500,
))
Fields:
workflow_name(str): Workflow nameelapsed_time(float): The total execution time in secondsactions_completed(int): The number of actions that completedactions_partial(int): The number of actions that completed with failed recordsactions_skipped(int): The number of actions that were skippedactions_failed(int): The number of actions that failedtotal_tokens(int): The total number of tokens usedrecords_failed_checks(int): The records that the actions of the workflow hold and that shipped with an expectations verdict whoseoverall_passis false. Agent Actions reads the count from the store when the run ends. If a batch workflow completes over several runs, the count includes the records that the earlier runs collected. When the value is above zero, the workflow line turns to⚠and saysN records failed their checks
WorkflowFailedEvent
Emitted when a workflow fails.
from agent_actions.logging.events import WorkflowFailedEvent
fire_event(WorkflowFailedEvent(
workflow_name="my_workflow",
error_message="Dependency cycle detected",
error_type="CyclicDependencyError",
elapsed_time=5.2,
failed_action="extract_data",
))
Fields:
workflow_name(str): Workflow nameerror_message(str): The description of the errorerror_detail(str): More detail about the errorerror_type(str): The name of the exception typeelapsed_time(float): The time elapsed before the failurefailed_action(str): The name of the action that failed
StepStartEvent
Emitted when a dependency level starts. The event fires also when no action in the level is pending.
from agent_actions.logging.events import StepStartEvent
fire_event(StepStartEvent(
step_index=1,
total_steps=3,
actions=["extract_a", "extract_b"],
pending=["extract_b"],
))
Fields:
step_index(int): The position of the level, 0-based (shown 1-based)total_steps(int): The number of levels in the runactions(List[str]): Every action in the levelpending(List[str]): The subset of actions that will actually run
StepCompleteEvent
Emitted when a dependency level ends, for all outcomes.
from agent_actions.logging.events import StepCompleteEvent
fire_event(StepCompleteEvent(
step_index=1,
total_steps=3,
elapsed_time=12.4,
completed=2,
))
Fields:
step_index/total_steps(int): As aboveelapsed_time(float): The wall time of the levelcompleted/partial/skipped/failed/unfinished(int): The number of actions for each outcome. Their sum is the size of the levelbatch_pending(List[str]): The actions whose batch jobs are not complete yet. If the list is not empty, the level paused and did not finishpeak_rss_mb(float | None): The most resident memory the process has held so far, in MB, read when the level ends. It isNonewhere the platform does not report it (Windows). Compare it across steps to find the step that raised it
Action Events
ActionStartEvent
Emitted when an action starts to process.
from agent_actions.logging.events import ActionStartEvent
fire_event(ActionStartEvent(
action_name="extract_data",
action_index=0, # 0-based index
total_actions=5,
action_type="llm",
input_path="/path/to/input.json",
mode="online",
))
Fields:
action_name(str): Action nameaction_index(int): The position of the action in the workflow (0-based)total_actions(int): The total number of actionsaction_type(str): The kind of the action ("llm","tool","hitl")input_path(str): The path to the input filemode(str):"online"or"batch"
ActionCompleteEvent
Emitted when an action completes successfully.
from agent_actions.logging.events import ActionCompleteEvent
fire_event(ActionCompleteEvent(
action_name="extract_data",
action_index=0,
total_actions=5,
execution_time=15.2,
output_path="/path/to/output.json",
record_count=100,
tokens={"prompt_tokens": 800, "completion_tokens": 400, "total_tokens": 1200},
model_vendor="openai",
model_name="gpt-6.2-sol",
kind="llm",
))
Fields:
action_name(str): Action nameaction_index(int): The position of the action in the workflow (0-based)total_actions(int): The total number of actionsexecution_time(float): The execution time in secondsoutput_path(str): The path to the output filerecord_count(int): The number of records that this execution produced. If a run replaces records that are already stored, the count includes them again. Thusagac run --rerunandagac retryreport the records that they answered. The count does not include records carried forward from an earlier run. The✓ <action> N recordscompletion line shows the same number.guard_skipped(int): The part ofrecord_countthat the guard of the action skipped in this execution. Agent Actions keeps these records as tombstones. When the value is above zero, the completion line ends with— N skipped by guard.checks_failed(int): The records that this execution shipped with an expectations verdict whoseoverall_passis false (on_exhausted: return_last,repair: none). Agent Actions stores them as successes. When the value is above zero, the completion line turns to⚠and saysN failed their checks.tokens(Dict[str, int]): The token usage, item by itemmode(str):"online"or"batch"model_vendor/model_name(str): The model that ran the action. Empty for a tool action or a HITL actionkind(str):"llm","tool","hitl", … — consumers use it to decide if a model is meaningfulstubbed(bool): True for a tool action that the scenario of a sandbox run stubs. The code of the tool did not run, and the mock built its output. The completion line then shows(stubbed)after the time. The notes come after it, for example✓ retrieve_candidates 3 records in 0.1s (stubbed) — 1 skipped by guardcases(Dict[str, int] | None): For a built-in router, the number of records of each case in this execution, in the order of the cases of the router,defaultlast. None for every other action. The completion line ends with these counts, for example— a 2, b 3, default 1.
ActionSkipEvent
Emitted when an action is skipped. For example, the guard condition of the action filters every record.
from agent_actions.logging.events import ActionSkipEvent
fire_event(ActionSkipEvent(
action_name="optional_enrichment",
action_index=2,
total_actions=5,
skip_reason="guard condition not met",
))
Fields:
action_name(str): Action nameaction_index(int): The position of the action in the workflow (0-based)total_actions(int): The total number of actionsskip_reason(str): The reason why the action was skippedmode(str):"online"or"batch"
ActionFailedEvent
Emitted when an action fails.
from agent_actions.logging.events import ActionFailedEvent
fire_event(ActionFailedEvent(
action_name="extract_data",
action_index=0,
total_actions=5,
error_message="API rate limit exceeded",
error_type="RateLimitError",
execution_time=2.5,
suggestion="Try again after rate limit resets",
))
Fields:
action_name(str): Action nameaction_index(int): The position of the action in the workflow (0-based)total_actions(int): The total number of actionserror_message(str): The description of the errorerror_detail(str): More detail about the errorerror_type(str): The name of the exception classexecution_time(float): The time elapsed before the failuresuggestion(str): A suggested fix or the next stepmode(str):"online"or"batch"
Batch Events
BatchSubmittedEvent
Emitted when a batch job is submitted.
from agent_actions.logging.events import BatchSubmittedEvent
fire_event(BatchSubmittedEvent(
batch_id="batch_abc123",
action_name="extract_data",
request_count=1000,
provider="openai",
))
Fields:
batch_id(str): The ID of the batch jobaction_name(str): Action namerequest_count(int): The number of requests in the batchprovider(str): The LLM provider
BatchCompleteEvent
Emitted when a batch job completes.
from agent_actions.logging.events import BatchCompleteEvent
fire_event(BatchCompleteEvent(
batch_id="batch_abc123",
action_name="extract_data",
total=1000,
completed=995,
failed=5,
elapsed_time=3600.0,
total_tokens=75000,
))
Fields:
batch_id(str): The ID of the batch jobaction_name(str): Action nametotal(int): The total number of requests in the batchcompleted(int): The number of requests that completed successfullyfailed(int): The number of requests that failedelapsed_time(float): The total time in secondstotal_tokens(int): The total number of tokens used
BatchErrorEvent
Emitted when a batch job fails.
from agent_actions.logging.events import BatchErrorEvent
fire_event(BatchErrorEvent(
action_name="extract_data",
error_message="Batch expired",
error_type="BatchExpiredError",
))
Fields:
action_name(str): Action nameerror_message(str): The description of the errorerror_type(str): The name of the exception class
Validation Events
ValidationStartEvent
Emitted when validation starts.
from agent_actions.logging.events import ValidationStartEvent
fire_event(ValidationStartEvent(
target="extract_data_schema",
validator="schema",
))
Fields:
target(str): The item that is validatedvalidator(str): The name of the validator
ValidationCompleteEvent
Emitted when validation completes.
from agent_actions.logging.events import ValidationCompleteEvent
fire_event(ValidationCompleteEvent(
target="extract_data_schema",
validator="schema",
elapsed_time=0.02,
))
Fields:
target(str): The item that was validatedvalidator(str): The name of the validatorelapsed_time(float): The validation time in secondswarning_count(int): The number of warnings founderror_count(int): The number of errors found. When this value is not 0, the level of the event is ERROR
ValidationErrorEvent
Emitted when validation finds an error.
from agent_actions.logging.events import ValidationErrorEvent
fire_event(ValidationErrorEvent(
target="extract_data_schema",
field="title",
error="Missing required field",
))
Fields:
target(str): The item that was validatedfield(str): The field that failederror(str): The description of the errorvalue(Any): The invalid value (optional)
ValidationWarningEvent
Emitted for validation warnings.
from agent_actions.logging.events import ValidationWarningEvent
fire_event(ValidationWarningEvent(
target="extract_data_schema",
field="description",
warning="Optional field is missing",
))
Fields:
target(str): The item that was validatedfield(str): The field that caused the warningwarning(str): The warning messagevalue(Any): The value that caused the problem (optional)
Event Handlers
EventHandler (Base Class)
The base class for all event handlers.
EventHandler is a Protocol in agent_actions.logging.core.protocols. A handler is any object with these methods. A handler does not need to subclass EventHandler.
from agent_actions.logging.core.events import BaseEvent
class MyHandler:
def accepts(self, event: BaseEvent) -> bool:
"""Return True if this handler processes the event."""
return event.category == "workflow"
def handle(self, event: BaseEvent) -> None:
"""Process the event."""
print(f"Event: {event.message}")
def flush(self) -> None:
"""Flush any buffered data."""
pass
Methods:
accepts(event)→ bool: Returns True if the handler processes this eventhandle(event)→ None: Processes the eventflush()→ None: Flushes the buffered dataclose()→ None: Releases resources. The protocol lists this method. If the handler has it, the manager calls it on reset and on a forced re-initialize
ProgressRenderer
The console handler that a run installs. It is a subclass of ConsoleEventHandler. It shows
workflow, step and action events as a progress stream, grouped by step. All
other events use the formatting below.
from agent_actions.logging.core.handlers import ProgressRenderer
Takes the same parameters as ConsoleEventHandler.
ConsoleEventHandler
Writes events to the console (stderr). When Rich is available, it uses Rich formatting.
from agent_actions.logging.core.events import EventLevel
from agent_actions.logging.core.handlers import ConsoleEventHandler
handler = ConsoleEventHandler(
min_level=EventLevel.INFO,
show_timestamp=True,
categories={"workflow", "action", "batch"},
)
Parameters:
min_level(EventLevel): The minimum event level to show. Defaults toEventLevel.INFOshow_timestamp(bool): Includes the timestamp in the output. Defaults to Trueformatter(Optional[Callable]): A custom formatter function. It takes an event and returns a stringconsole(Optional[Any]): The Rich console to write to. Defaults to a Rich console on stderrcategories(Optional[Set[str]]): The event categories to show (None = all). WARN and ERROR events show for all categoriesshow_diagnostics(bool): Shows events marked diagnostic. Defaults to False, which drops them at all levels
JSONFileHandler
Writes events to a JSON file in NDJSON format.
from agent_actions.logging.core.events import EventLevel
from agent_actions.logging.core.handlers import JSONFileHandler
from pathlib import Path
handler = JSONFileHandler(
file_path=Path("logs/events.json"),
min_level=EventLevel.DEBUG,
buffer_size=10,
)
Parameters:
file_path(str | Path): The path of the output file. The handler creates the parent directoriesmin_level(EventLevel): The minimum event level to log. Defaults toEventLevel.DEBUGbuffer_size(int): The number of events to buffer before a write. Defaults to 10max_debug_bytes(Optional[int]): When the file is larger than this number of bytes, the handler stops writing DEBUG events. Defaults to None (no limit)include_all_fields(bool): True writes the full dictionary of each event. False writes onlyevent_type,level,messageandtimestamp. Defaults to True
Output Format: NDJSON (one JSON object on each line)
RunResultsCollector
Collects the execution results of the workflow into run_results.json.
from agent_actions.logging.events.handlers import RunResultsCollector
collector = RunResultsCollector(
output_dir="/path/to/agent_io",
workflow_name="my_workflow",
)
Parameters:
output_dir(Optional[str | Path]): The directory to write run_results.json toworkflow_name(str): The name of the workflow that runs
Output: {output_dir}/logs/run_results.json
Methods:
accepts(event): Returns True for events in the workflow and action categories, and forRecordEmptyOutputEventandResultCollectionCompleteEventhandle(event): Processes the event and updates the internal stateflush(): Writes run_results.json to disk
Configuration
LoggingConfig
The settings for the logging system.
from agent_actions.logging.config import LoggingConfig
config = LoggingConfig(default_level="INFO")
LoggerFactory.initialize(config=config)
Fields:
default_level(str): The default log level ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL").from_environment()reads it fromAGENT_ACTIONS_LOG_LEVEL.AGENT_ACTIONS_DEBUG=1forces"DEBUG"module_levels(dict): Level overrides for each logger, applied at init. The keys are Python logger names (for example,"httpx","my_module"). The values are level strings. Use this field to enable again a logger that the framework clamps by default. You can also use it to silence a logger that still writes too many messages.file_handler(FileHandlerSettings):max_bytesandbackup_countset the size and the rotation of the run log. See File Handler below
Third-party logger suppression
LoggerFactory.initialize() clamps a curated set of SDK / HTTP loggers to WARNING on every init.
Thus the CLI shows mainly the output of the framework. The curated set is:
httpx, httpcore, urllib3, openai, anthropic, ollama, groq,
cohere, google_genai, googleapiclient, pypdf
To get verbose output again from one of these loggers, pass module_levels when you construct the config.
You can also use module_levels to silence a logger that is not in the curated list:
from agent_actions.logging.config import LoggingConfig
from agent_actions.logging.factory import LoggerFactory
config = LoggingConfig(
default_level="INFO",
module_levels={
"httpx": "INFO", # see HTTP request lines from httpx again
"pypdf": "ERROR", # silence PDF parser warnings further
},
)
LoggerFactory.initialize(config=config)
Overrides on agent_actions and on all of its children are refused, with a
warning on stderr. The framework root must stay at DEBUG, so that every event gets to
events.json. To set the level that the CLI shows, use default_level.
From the CLI, set the same values under logging.module_levels in
agent_actions.yml. At boot, the CLI builds its config with
LoggingConfig.from_environment(LoggingConfig.from_project_config(project_config)).
Thus the project block is the base. A set AGENT_ACTIONS_* variable
overrides only its own key. module_levels has no environment form. See
Configuration.
FileHandlerSettings
LoggingConfig.file_handler is a FileHandlerSettings with two fields.
LoggerFactory reads the two fields:
max_bytes(logging.file.max_bytes/AGENT_ACTIONS_LOG_MAX_BYTES) sets the limit on the DEBUG rows written to each run file.backup_count(logging.file.backup_count/AGENT_ACTIONS_LOG_RETAIN_RUNS) sets the number of earlier runs to keep.
Only the output_dir passed to LoggerFactory.initialize() decides if a run-log file
handler is registered, and where it writes. The file is always events.json at DEBUG.
All other logging.file.* project keys configure nothing. The
AGENT_ACTIONS_NO_LOG_FILE, AGENT_ACTIONS_LOG_FILE, AGENT_ACTIONS_LOG_DIR, AGENT_ACTIONS_FILE_LOG_LEVEL
and AGENT_ACTIONS_LOG_FORMAT env vars also configure nothing. If one of these is set, the CLI reports
it on stderr at boot and ignores it.
Constants
EventLevel
The event severity levels.
from agent_actions.logging.core.events import EventLevel
EventLevel.DEBUG # Detailed diagnostic information
EventLevel.INFO # General informational messages
EventLevel.WARN # Warning messages
EventLevel.ERROR # Error messages
EventCategories
The event category strings for filters. event.category holds one of these values.
from agent_actions.logging.events.types import EventCategories
EventCategories.WORKFLOW # "workflow" Workflow lifecycle events
EventCategories.ACTION # "action" Action execution events
EventCategories.BATCH # "batch" Batch processing events
EventCategories.LLM # "llm" LLM interaction events
EventCategories.VALIDATION # "validation" Validation events
EventCategories.CACHE # "cache" Cache events
EventCategories.TEMPLATE # "template" Template rendering events
EventCategories.DATA # "data" Data loading and parsing events
EventCategories.GUARD # "guard" Guard evaluation events
EventCategories.RECOVERY # "recovery" Recovery and retry events
EventCategories.CONFIGURATION # "configuration" Configuration loading events
EventCategories.INITIALIZATION # "initialization" Initialization events
EventCategories.PLUGIN # "plugin" Plugin and UDF discovery events
EventCategories.DATA_PROCESSING # "data_processing" Data processing events
EventCategories.FILE_IO # "file_io" File I/O events
EventCategories.SCHEMA # "schema" Schema operation events
EventCategories.TRANSFORMATION # "transformation" Data transformation events
Examples
Basic Workflow Logging
from agent_actions.logging.factory import LoggerFactory
from agent_actions.logging.core.manager import fire_event
from agent_actions.logging.events import (
WorkflowStartEvent,
ActionStartEvent,
ActionCompleteEvent,
WorkflowCompleteEvent,
)
# Initialize
LoggerFactory.initialize(
output_dir="my_workflow/agent_io",
workflow_name="my_workflow",
)
# Workflow start
fire_event(WorkflowStartEvent(
workflow_name="my_workflow",
action_count=3,
))
# Action 1
fire_event(ActionStartEvent(
action_name="extract",
action_index=0,
total_actions=3,
))
# ... do work ...
fire_event(ActionCompleteEvent(
action_name="extract",
action_index=0,
total_actions=3,
execution_time=5.2,
))
# Workflow complete
fire_event(WorkflowCompleteEvent(
workflow_name="my_workflow",
elapsed_time=15.6,
actions_completed=1,
))
# Flush
LoggerFactory.flush()
Custom Event Handler
from agent_actions.logging.core.manager import get_manager
from agent_actions.logging.core.events import BaseEvent
class MetricsHandler:
def __init__(self):
self.metrics = []
def accepts(self, event: BaseEvent) -> bool:
return event.category in ("workflow", "action")
def handle(self, event: BaseEvent) -> None:
if event.event_type == "ActionCompleteEvent":
self.metrics.append({
"action": event.data.get("action_name"),
"duration": event.data.get("execution_time"),
"tokens": event.data.get("tokens", {}),
})
def flush(self) -> None:
import json
with open("metrics.json", "w") as f:
json.dump(self.metrics, f, indent=2)
# Register
handler = MetricsHandler()
manager = get_manager()
manager.register(handler)
Context Scoping
from agent_actions.logging.core.manager import get_manager, fire_event
from agent_actions.logging.events import ActionStartEvent
manager = get_manager()
# Set global context
manager.set_context(workflow_name="main")
# All events carry workflow_name="main" in event.meta.extra
fire_event(ActionStartEvent(action_name="extract"))
# Override for nested context
with manager.context(workflow_name="upstream"):
fire_event(ActionStartEvent(action_name="fetch"))
# Event carries workflow_name="upstream"
# Back to workflow_name="main"
fire_event(ActionStartEvent(action_name="transform"))
See Also
- Logging Architecture - System design and flow