Session
Properties
Sessions possess the following attributes:- ID: A unique identifier for the session.
- Project ID: Identifies the project associated with the session, determined by the API Key used.
- Starting Timestamp: Marks the beginning of the session.
- Ending Timestamp: Indicates when the session concludes.
- End State: Signifies the success or failure of the session.
- End State Reason: Explains why the session ended, whether due to an error or a user-triggered interrupt (SIGINT).
- Tags: Tags allow for the categorization and later retrieval of sessions.
- Host Environment: Automatically gathers basic information about the system on which the session ran.
- Video: If applicable, an optional video recording of the session.
Methods
end_session
Params
- end_state (str, enum): Success|Failure|Indeterminate
- end_state_reason (optional, str): additional notes on end state
record
Params
- event (Event): The Event to record as part of the session
get_analytics
Returns (dict): A dictionary containing various analytics metrics for the session.
Starting a Session
When you callagentops.init()
, a session is automatically started.
Calling agentops.init(auto_start_session=False)
will initialize the AgentOps SDK but not start a session.
To start a session later, call agentops.start_session()
(reference)
Both agentops.init()
and agentops.start_session()
work as a factory pattern and return a Session
object. The above methods can all be called on this session object.
Ending a Session
If a process ends without any call to agentops, it will show in the dashboard asIndeterminate
.
To end with a state, call either agentops.end_session(...)
(reference) if only one session is in use. Otherwise use session.end_session(...)
.
Inherited Sessions
When working with multiple agents running in different processes, it’s possible to initialize AgentOps or start a session with an existing session_id.agentops.init(inherited_session_id=<id>)
agentops.start_session(inherited_session_id=<id>)
You can retrieve the current session_id
by assigning the returned value from init()
or start_session()
.
Session Data Export
AgentOps provides REST endpoints to export your session data and statistics. These endpoints allow you to retrieve detailed information about your sessions programmatically.Authentication
All data export requests require a single header:X-Agentops-Api-Key
: Your AgentOps API key
Available Endpoints
Get Session Statistics
- Event counts
- Duration
- Costs
- Token usage
- Other session metrics
Export Complete Session Data
- Session metadata
- Statistics
- All recorded events:
- Actions
- LLM calls
- Tool usage
- Errors
Example Usage
Session Analytics
You can retrieve the analytics for a session by callingsession.get_analytics()
.
The example below shows how to record events and retrieve analytics.
The AgentOps SDK Client
More info for the curious Under the hood,agentops.init()
creates a Client
object with various configuration options. Whenever you start a new session, these configuration options will automatically
be applied. You can also apply different configuration options when you start a new session by passing in a
Config object.