fix: add LiteLLM Responses API attribute extraction for ResponseAPIResponse format#1412
Closed
icohangar-ops wants to merge 1 commit into
Closed
fix: add LiteLLM Responses API attribute extraction for ResponseAPIResponse format#1412icohangar-ops wants to merge 1 commit into
icohangar-ops wants to merge 1 commit into
Conversation
Adds the missing @record_function decorator to the legacy module with a proper deprecation warning. The decorator creates a trace span using the new v4 instrumentation system. Fixes #1076
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for the LiteLLM Responses API response format (
ResponsesAPIResponse) to the AgentOps instrumentation layer.Problem
When using
litellm.responses()(LiteLLM's/v1/responsesendpoint), the returned objects have a different structure thanModelResponse(chat completions). Specifically:outputinstead ofchoicesusagewithinput_tokens/output_tokensinstead ofprompt_tokens/completion_tokens/total_tokenschoices[].messagestructureLiteLLM's own OpenTelemetry integration (which
success_callback = ["agentops"]uses) assumes chat completion format and silently fails to extract attributes fromResponsesAPIResponseobjects.Changes
New LiteLLM Responses API wrapper (
agentops/instrumentation/providers/litellm/wrappers/responses.py):is_responses_api_response(): Detect if a response object is aResponsesAPIResponsehandle_litellm_responses_attributes(): Extract OTel span attributes fromResponsesAPIResponseobjects, normalizingoutput-> completions andinput_tokens/output_tokens-> token countsUpdated canary test: Added documentation noting the
ResponsesAPIResponseformat differencesRelated
Closes #1079 -- adds building block for LiteLLM Responses API tracking support.
Notes
The actual fix for LiteLLM's
success_callback = ["agentops"]path needs changes in LiteLLM'sopentelemetry.py(_handle_success,set_attributes,_record_metrics) to handleResponsesAPIResponseobjects. This PR adds the AgentOps-side attribute extraction helpers that LiteLLM's callback can use when processing Responses API responses.