agentops icon indicating copy to clipboard operation
agentops copied to clipboard

Refactor Session class and add independent get_analytics method

Open dragutin-oreski opened this issue 1 year ago • 0 comments

📥 Pull Request

Background I need to access analytics directly, not only through the logs. I created a workaround for myself to get the analytics stats, but I figured that others could benefit from it as well. So, I added a function that can return the session analytics back to the user.

📘 Description Refactored the Session class to improve code modularity and maintainability. Specifically: • Introduced a get_analytics method to allow independent retrieval of session analytics (e.g., token cost, LLM calls, tool usage, etc.). • Moved token cost and duration formatting into separate methods for better code reuse. • Ensured that the analytics function can be used independently of the session lifecycle.

🧪 Testing • Tested the get_analytics method by running sessions and validating the returned statistics, including correct duration formatting and token cost calculation. • Verified that the session behaves as expected when ending, ensuring no regression in the current end_session logic. • Ensured thread management and queue flushing still work as intended in the refactored code.

dragutin-oreski avatar Oct 02 '24 14:10 dragutin-oreski