Event Class

The Event class is an abstract base class for events that will be recorded. It should not be instantiated directly.

ParameterTypeDefaultExampleDescription
paramsdictNone{"param1": "value1"}Additional parameters for the event
returnsstrNone“Success”Return value of the event
init_timestampstrA timestamp of instantiation“2023-03-15T18:59:13Z”The time when the Event was initiated
end_timestampstrA timestamp of instantiation“2023-03-15T19:00:13Z”The time when the Event was completed
agent_idUUIDUUID of the triggering agent123e4567-e89b-12d3-a456-426614174000The unique identifier of the agent that triggered the event
idUUIDA new UUID123e4567-e89b-12d3-a456-426614170000The unique identifier of the event

ActionEvent

The ActionEvent is a generic event for recording events that do not fit into the bounds of a more specific Event type.

ParameterTypeDefaultExampleDescription
action_typestrNone“Click”Type of the action
logsstrNone“Executed action successfully”Logs generated during the action event
screenshotstrNone“/path/to/screenshot.png”Path to screenshot captured during the action event

An action event can be used the same way as other events but also with the record_function decorator.

from agentops import record_function

@record_function()
def some_action(params):
    return "some response"

This decorator will record an ActionEvent with the params and returns of the function as well as execution time.

LLMEvent

The LLMEvent class is for recording calls to LLMs. AgentOps auto-instruments calls to the most popular LLMs e.g. GPT, Claude, Gemini, etc.

In most cases, LLMEvent should not be used by the developer. These are created automatically.

ParameterTypeDefaultExampleDescription
thread_idUUIDNone123e4567-e89b-12d3-a456-426614174000Thread ID of the event
promptstr or ListNone“What’s the weather today?”The prompt for the event
prompt_tokensintNone5Number of tokens in the prompt
completionstr or objectNone“It’s sunny and warm.”The completion of the event
completion_tokensintNone4Number of tokens in completion
modelModels or strNoneModels.MODEL_NAME or “model_name”The model used for the event

ToolEvent

The ToolEvent class is for recording calls to tools e.g. searchWeb, fetchFromDB.

ParameterTypeDefaultExampleDescription
namestrNone“Parsing Tool”Name of the tool
logsstr or dictNone“Tool executed successfully” or {"status": "success"}Logs from the tool execution

The tool event should be created previous to running the tool in order to track the execution time.

from agentops import ToolEvent, record
def scrape_website(url: str):
    tool_event = ToolEvent(name='scrape_website', params={'url':url}) # the start timestamp is set when the obj is created
    result = integration.scrape_website(data) # perform tool logic
    tool_event.returns = result # set result
    record(tool_event)

ErrorEvent

Error events can be used alone or in reference to another event. The can reference errors that the LLM made or errors in execution, up to the developer.

ParameterTypeDefaultExampleDescription
trigger_eventEventNoneEvent instanceThe Event that triggered the ErrorEvent
error_typestrNone“Runtime Error”Type of the error
codestrNone“ERR001”Code of the error
detailsstrNone“Null pointer exception”Detailed description of the error
logsstrNone“Error occurred at line 10”Logs related to the error
timestampstrA timestamp when the ErrorEvent was instantiated“2023-03-15T18:59:13Z”Timestamp when the ErrorEvent was created
from agentops import ToolEvent, record, ErrorEvent
def scrape_website(url: str):
    tool_event = ToolEvent(name='scrape_website', params={'url':url}) # the start timestamp is set when the obj is created
    try:
        result = integration.scrape_website(data) # perform tool logic
        tool_event.returns = result
    except Error as e:
        record(ErrorEvent(message=e, trigger_event=tool_event))
    record(tool_event)