All functions and classes exposed in the top layer of the SDK
import agentops
for the Python SDK. The AgentOps SDK is designed for easy integration with your agent applications, offering both simple auto-instrumentation and more detailed manual tracing capabilities.
init()
api_key
(str, optional): API Key for AgentOps services. If not provided, the key will be read from the AGENTOPS_API_KEY
environment variable.endpoint
(str, optional): The endpoint for the AgentOps service. If not provided, will be read from the AGENTOPS_API_ENDPOINT
environment variable. Defaults to ‘https://api.agentops.ai’.app_url
(str, optional): The dashboard URL for the AgentOps app. If not provided, will be read from the AGENTOPS_APP_URL
environment variable. Defaults to ‘https://app.agentops.ai’.max_wait_time
(int, optional): The maximum time to wait in milliseconds before flushing the queue. Defaults to 5,000 (5 seconds).max_queue_size
(int, optional): The maximum size of the event queue. Defaults to 512.default_tags
(List[str], optional): Default tags for the sessions that can be used for grouping or sorting later (e.g. [“GPT-4”]).tags
(List[str], optional): [Deprecated] Use default_tags
instead. Will be removed in v4.0.instrument_llm_calls
(bool, optional): Whether to instrument LLM calls automatically. Defaults to True.auto_start_session
(bool, optional): Whether to start a session automatically when the client is created. Set to False if running in a Jupyter Notebook. Defaults to True.auto_init
(bool, optional): Whether to automatically initialize the client on import. Defaults to True.skip_auto_end_session
(bool, optional): Don’t automatically end session based on your framework’s decision-making. Defaults to False.env_data_opt_out
(bool, optional): Whether to opt out of collecting environment data. Defaults to False.log_level
(str, int, optional): The log level to use for the client. Defaults to ‘INFO’.fail_safe
(bool, optional): Whether to suppress errors and continue execution when possible. Defaults to False.exporter_endpoint
(str, optional): Endpoint for the exporter. If not provided, will be read from the AGENTOPS_EXPORTER_ENDPOINT
environment variable. Defaults to ‘https://otlp.agentops.ai/v1/traces’.export_flush_interval
(int, optional): Time interval in milliseconds between automatic exports of telemetry data. Defaults to 1000.trace_name
(str, optional): Custom name for the automatically created trace. If not provided, a default name will be used.auto_start_session=True
, returns the created Session object. Otherwise, returns None.configure()
init()
.
Parameters:
api_key
(str, optional): API Key for AgentOps services.endpoint
(str, optional): The endpoint for the AgentOps service.app_url
(str, optional): The dashboard URL for the AgentOps app.max_wait_time
(int, optional): Maximum time to wait in milliseconds before flushing the queue.max_queue_size
(int, optional): Maximum size of the event queue.default_tags
(List[str], optional): Default tags for the sessions.instrument_llm_calls
(bool, optional): Whether to instrument LLM calls.auto_start_session
(bool, optional): Whether to start a session automatically.auto_init
(bool, optional): Whether to automatically initialize the client on import.skip_auto_end_session
(bool, optional): Don’t automatically end session.env_data_opt_out
(bool, optional): Whether to opt out of collecting environment data.log_level
(str, int, optional): The log level to use for the client.fail_safe
(bool, optional): Whether to suppress errors and continue execution.exporter
(object, optional): Custom span exporter for OpenTelemetry trace data.processor
(object, optional): Custom span processor for OpenTelemetry trace data.exporter_endpoint
(str, optional): Endpoint for the exporter.export_flush_interval
(int, optional): Time interval in milliseconds between automatic exports of telemetry data.trace_name
(str, optional): Custom name for traces.get_client()
start_trace()
trace_name
(str, optional): Name for the trace. If not provided, a default name will be used.tags
(Union[Dict[str, Any], List[str]], optional): Optional tags to attach to the trace, useful for filtering in the dashboard. Can be a list of strings or a dict of key-value pairs.end_trace()
trace
(TraceContext, optional): The specific trace to end. If not provided, all active traces will be ended.end_state
(str, optional): The end state for the trace(s). You can use any descriptive string that makes sense for your application (e.g., “Success”, “Indeterminate”, “Error”, “Timeout”, etc.).update_trace_metadata()
metadata
(Dict[str, Any]): Dictionary of key-value pairs to set as trace metadata. Values must be strings, numbers, booleans, or lists of these types. Lists are automatically converted to JSON string representation.prefix
(str, optional): Prefix for metadata attributes. Defaults to “trace.metadata”. Ignored for semantic convention attributes.bool
: True if metadata was successfully updated, False otherwise.@trace
decorator is the recommended approach for creating custom traces, especially in multi-threaded environments. These decorators are imported from agentops.sdk.decorators
.
@trace
: Creates a trace span for grouping related operations@agent
: Creates an agent span for tracking agent operations@operation
/ @task
: Creates operation/task spans for tracking specific operations (these are aliases)@workflow
: Creates workflow spans for organizing related operations@tool
: Creates tool spans for tracking tool usage and cost in agent operations. Supports cost parameter for tracking tool usage costs.start_session()
: Deprecated. Legacy function for starting sessions. Use @trace
decorator or start_trace()
instead.end_session()
: Deprecated. Legacy function for ending sessions. Use end_trace()
instead.record(event)
: Deprecated. Legacy function to record an event. Replaced by decorator-based tracing.track_agent()
: Deprecated. Legacy decorator for marking agents. Replaced by the @agent
decorator.track_tool()
: Deprecated. Legacy decorator for marking tools. Replaced by the @tool
decorator.ToolEvent()
, ErrorEvent()
, ActionEvent()
, LLMEvent()
: Deprecated. Legacy event types. Replaced by automatic instrumentation and decorators.