fix(dashscope): preserve message outputs without tool calls#185
Open
sipercai wants to merge 1 commit intoalibaba:mainfrom
Open
fix(dashscope): preserve message outputs without tool calls#185sipercai wants to merge 1 commit intoalibaba:mainfrom
sipercai wants to merge 1 commit intoalibaba:mainfrom
Conversation
db4895d to
40e3711
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes DashScope message-format response parsing so assistant text output is preserved when the response omits the optional tool_calls field.
Changes:
- Add a safe field accessor to avoid
KeyErrorfrom DashScope’s dict-like response objects and use it throughout generation parsing. - Add a VCR-based regression test (and cassette) covering
result_format="message"responses withouttool_calls. - Update DashScope instrumentation changelog and adjust dependency / tooling configs.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation-loongsuite/loongsuite-instrumentation-dashscope/src/opentelemetry/instrumentation/dashscope/utils/generation.py | Introduces _safe_get and applies it across response parsing to preserve message output without tool_calls. |
| instrumentation-loongsuite/loongsuite-instrumentation-dashscope/tests/test_generation.py | Adds a regression test validating gen_ai.output.messages is emitted for message-format responses without tool_calls. |
| instrumentation-loongsuite/loongsuite-instrumentation-dashscope/tests/cassettes/test_generation_call_message_result_without_tool_calls_content_capture.yaml | Adds recorded HTTP interaction for the new regression test. |
| instrumentation-loongsuite/loongsuite-instrumentation-dashscope/pyproject.toml | Removes version constraints for opentelemetry-util-genai. |
| instrumentation-loongsuite/loongsuite-instrumentation-dashscope/CHANGELOG.md | Adds an Unreleased “Fixed” entry documenting the parsing fix. |
| .pre-commit-config.yaml | Excludes _template/ from the rstcheck hook. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "opentelemetry-instrumentation >= 0.58b0", | ||
| "opentelemetry-semantic-conventions >= 0.58b0", | ||
| "opentelemetry-util-genai > 0.2b0", | ||
| "opentelemetry-util-genai", |
Collaborator
Author
There was a problem hiding this comment.
This package depends on the latest opentelemetry-util-genai implementation maintained in the LoongSuite repo, so we intentionally avoid pinning or version-constraining this dependency.
40e3711 to
34fd69e
Compare
34fd69e to
b85e025
Compare
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 fixes DashScope message-format response parsing when the assistant returns
plain text without a
tool_callsfield.DashScope response entities are dict-like objects whose attribute access can raise
KeyErrorfor missing optional fields. The previous parser usedgetattr(message, "tool_calls", None), so aresult_format="message"text responsewithout
tool_callscould discard the already parsedmessage.contentand omitgen_ai.output.messages.This change adds safe field access for DashScope response objects, preserves
assistant text output in this response shape, adds a VCR regression cassette, and
updates the DashScope changelog.
Fixes # (N/A)
Type of change
How Has This Been Tested?
tox -e precommitOTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-dashscope-latest -- instrumentation-loongsuite/loongsuite-instrumentation-dashscope/tests/test_generation.py::test_generation_call_message_result_without_tool_calls_content_capture -qDoes This PR Require a Core Repo Change?
Checklist: