AgentStream
Object-centric interface for Splunk AO log streams. This class provides an intuitive way to work with Splunk AO log streams, offering methods for managing log streams and their associated metrics. ExamplesCreate a new log stream and persist it
agent_stream = AgentStream(name=“Production Logs”, project_name=“My AI Project”).create()Get an existing log stream
agent_stream = AgentStream.get(name=“Production Logs”, project_name=“My AI Project”)AgentStreams can also be created through Project instances
from splunk_ao.project import Project project = Project.get(name=“My AI Project”) agent_stream = project.create_agent_stream(name=“Production Logs”)Enable evaluators on the agent stream
from splunk_ao.schema.metrics import SplunkAOEvaluators local_evaluators = agent_stream.set_metrics([ SplunkAOEvaluators.correctness, SplunkAOEvaluators.completeness, “context_relevance” ])Refresh agent stream state from API
agent_stream.refresh()context
Your logging code here
response = openai_client.chat.completions.create(…)create
export_records
record_type: The type of records to export (SPAN, TRACE, or SESSION).filters: A list of filters to apply to the export.sort: A sort clause to order the exported records.export_format: The desired format for the exported data.column_ids: A list of column IDs to include in the export.redact: Redact sensitive data from the response.
get
name(str): The log stream name.project_id(Optional[str]): The project ID. If neither project_id nor project_name is provided, falls back to SPLUNK_AO_PROJECT_ID or SPLUNK_AO_PROJECT environment variables.project_name(Optional[str]): The project name. If neither project_id nor project_name is provided, falls back to SPLUNK_AO_PROJECT environment variable.
get_metrics
get_sessions
filters: A list of filters to apply to the query.sort: A sort clause to order the query results.limit: The maximum number of records to return.starting_token: The token for the next page of results.
get_spans
filters: A list of filters to apply to the query.sort: A sort clause to order the query results.limit: The maximum number of records to return.starting_token: The token for the next page of results.
get_traces
filters: A list of filters to apply to the query.sort: A sort clause to order the query results.limit: The maximum number of records to return.starting_token: The token for the next page of results.
list
starting_token (from
next_starting_token on a prior response) to fetch subsequent pages.
Arguments
project_id(Optional[str]): The project ID. If neither project_id nor project_name is provided, falls back to SPLUNK_AO_PROJECT_ID or SPLUNK_AO_PROJECT environment variables.project_name(Optional[str]): The project name. If neither project_id nor project_name is provided, falls back to SPLUNK_AO_PROJECT environment variable.limit(Union[Unset, int]): Maximum number of log streams to return per page. Defaults to 100.starting_token(Union[Unset, int]): Pagination token to start from. Defaults to 0 (first page).
project
query
record_type: The type of records to query (SPAN, TRACE, or SESSION).filters: A list of filters to apply to the query.sort: A sort clause to order the query results.limit: The maximum number of records to return.starting_token: The token for the next page of results.
refresh
session_columns
Access a specific column
model_column = columns[“model”]Filter using columns
sessions = agent_stream.get_sessions( filters=[columns[“model”].equals(“gpt-4o-mini”)], sort=columns[“created_at”].descending() )set_metrics
metrics parameter
name is retained for API compatibility.
Arguments
metrics: List of evaluators to set. Supports:- SplunkAOEvaluators enum values (e.g., SplunkAOEvaluators.correctness)
- Metric objects (including from Metric.get(id=”…”))
- LocalMetricConfig objects for custom scoring functions
- String names of built-in evaluators