Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
Task: Implement Session Endpoints for v4 API
Description
Create endpoints for querying session data from Clickhouse. These endpoints will replace the existing v2 endpoints that query session data from Supabase.
Requirements
- Implement endpoints for querying session data
- Ensure compatibility with the existing v2 endpoints
- Optimize queries for performance
- Implement filtering, sorting, and pagination
- Handle error cases
Endpoints to Implement
GET /v4/sessions: Get a list of sessionsGET /v4/sessions/{session_id}: Get a specific session by IDGET /v4/sessions/{session_id}/traces: Get traces for a specific sessionGET /v4/sessions/{session_id}/logs: Get logs for a specific sessionGET /v4/sessions/{session_id}/metrics: Get metrics for a specific sessionGET /v4/sessions/{session_id}/stats: Get statistics for a specific sessionGET /v4/sessions/search: Search for sessions based on criteria
Implementation Details
- Create a new file at
agentops/api/routes/v4/sessions.py - Use the Clickhouse client to query session data
- Implement filtering, sorting, and pagination
- Handle error cases
- Ensure compatibility with the existing v2 endpoints
Query Parameters
project_id: Filter by project IDstart_time: Filter by start timeend_time: Filter by end timetags: Filter by tagsend_state: Filter by end statelimit: Limit the number of resultsoffset: Offset for pagination
Response Format
- Return JSON responses with session data
- Include metadata for pagination
- Include links to related resources
Session Identification
- Sessions are identified by the
session_idattribute in trace resource attributes - Implement logic to extract session information from trace data
- Create views or materialized views in Clickhouse to optimize session queries
Computed Fields Migration
- Identify computed fields in v2 endpoints (e.g., session statistics)
- Implement equivalent queries in Clickhouse
- Use trace attributes and events to extract the required data
- Ensure backward compatibility with existing clients
Testing
- Create unit tests for the endpoints
- Test with real data in Clickhouse
- Test performance with large datasets
- Test error handling
Dependencies
- Clickhouse client implementation
- Authentication middleware
- Trace endpoints implementation
Estimated Time
10-12 hours