Skip to content

Commit 1a15507

Browse files
address review comments
1 parent 6d8875a commit 1a15507

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/agentevals/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def _walk(span: Span, op_prefix: str, acc: list[Span]) -> None:
157157

158158

159159
def _extract_user_content(first_call_llm: Span) -> genai_types.Content:
160-
"""Extract user input from the first call_llm span's llm_request tag."""
160+
"""Extract user input from the first call_llm span's attributes via shared extractor."""
161161
text = extract_user_text_from_attrs(first_call_llm.tags)
162162
if text:
163163
return genai_types.Content(
@@ -173,7 +173,7 @@ def _extract_user_content(first_call_llm: Span) -> genai_types.Content:
173173

174174

175175
def _extract_final_response(last_call_llm: Span) -> genai_types.Content:
176-
"""Extract final text response from the last call_llm span's llm_response tag."""
176+
"""Extract final text response from the last call_llm span's attributes via shared extractor."""
177177
text = extract_agent_response_from_attrs(last_call_llm.tags)
178178
if text:
179179
return genai_types.Content(

src/agentevals/genai_converter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ def _extract_user_text(llm_span: Span) -> str:
317317
text = extract_user_text_from_attrs(llm_span.tags)
318318
if text:
319319
return text
320-
raise ValueError(f"LLM span {llm_span.span_id}: no user message found in span attributes")
320+
raise ValueError(
321+
f"LLM span {llm_span.span_id}: no user message found (checked gen_ai.input.messages and ADK llm_request)"
322+
)
321323

322324

323325
def _extract_assistant_text(llm_span: Span) -> str:

tests/test_extraction.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ def test_adk_no_text_parts(self):
194194
attrs = {ADK_LLM_RESPONSE: json.dumps({"content": {"parts": [{"function_call": {"name": "tool"}}]}})}
195195
assert extract_agent_response_from_attrs(attrs) is None
196196

197+
def test_genai_prefers_last_assistant(self):
198+
attrs = {
199+
OTEL_GENAI_OUTPUT_MESSAGES: json.dumps(
200+
[
201+
{"role": "assistant", "content": "First response"},
202+
{"role": "assistant", "content": "Second response"},
203+
]
204+
)
205+
}
206+
assert extract_agent_response_from_attrs(attrs) == "Second response"
207+
197208

198209
# ---------------------------------------------------------------------------
199210
# extract_token_usage_from_attrs

0 commit comments

Comments
 (0)