Event, EventStatus, and Execution

Overview

This module provides a specialized Event class, which extends the Element base with a structured Execution state. It also introduces EventStatus, an enumeration that clarifies the state (pending, processing, completed, or failed) of an ongoing or finished event.

EventStatus

class lionagi.protocols.generic.event.EventStatus(str, Enum)

Represents the lifecycle states for an action or task execution. Each event can transition from PENDING to PROCESSING, and finally to either COMPLETED or FAILED.

Members

  • PENDING : str Initial state before execution starts.

  • PROCESSING : str Indicates that the event is currently in progress.

  • COMPLETED : str The event action completed successfully.

  • FAILED : str The event action encountered an error or otherwise failed.

Example

from lionagi.protocols.generic.event import EventStatus

print(EventStatus.PENDING)  # "pending"
print(EventStatus.COMPLETED.value)  # "completed"

Execution

class lionagi.protocols.generic.event.Execution

Tracks the runtime details of an event, including status, duration, response, and any error messages. Designed to store partial or final results and the overall outcome of an event’s execution.

Attributes

statusEventStatus

The current status of the event’s execution.

durationfloat | None

Time in seconds that the event took to execute (if known).

responseAny

The result or output of the execution. Could be data or a message.

errorstr | None

Holds an error message if the execution failed.

Methods

__init__(duration: float | None = None, response: Any = None, status: EventStatus = EventStatus.PENDING, error: str | None = None)

Initializes an Execution instance with optional duration, response, status (defaults to EventStatus.PENDING), and error message.

Parameters

durationfloat | None

Number of seconds the execution took. If unknown, leave as None.

responseAny

The result or output of the execution, if any.

statusEventStatus

Current status of the execution. Defaults to PENDING.

errorstr | None

Optional error message if the execution has failed.

__str__() str

Returns a string representation of the execution, indicating the current status, duration, response, and error fields.

Example

from lionagi.protocols.generic.event import Execution, EventStatus

exe = Execution(
    duration=3.5,
    response={"result": 42},
    status=EventStatus.COMPLETED,
    error=None
)
print(exe)  # e.g. "Execution(status=completed, duration=3.5, response={'result': 42}, error=None)"

Event

File Location

Source File: lionagi/protocols/generic/event.py

Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com> SPDX-License-Identifier: Apache-2.0