Skip to content

Conversation

@OhYee
Copy link
Contributor

@OhYee OhYee commented Dec 5, 2025

增加 include_usage 参数,确保探针可以正确采集 token

Thank you for creating a pull request to contribute to Serverless Devs agentrun-sdk-python code! Before you open the request please answer the following questions to help it be more easily integrated. Please check the boxes "[ ]" with "[x]" when done too.
Please select one of the PR types below to complete


Fix bugs

Bug detail

The specific manifestation of the bug or the associated issue.

Pull request tasks

  • Add test cases for the changes
  • Passed the CI test

Update docs

Reason for update

Why do you need to update your documentation?

Pull request tasks

  • Update Chinese documentation
  • Update English documentation

Add contributor

Contributed content

  • Code
  • Document

Content detail

if content_type == 'code' || content_type == 'document':
    please tell us `PR url`,like: https://github.com/Serverless-Devs/agentrun-sdk-python/pull/1
else:
    please describe your contribution in detail

Others

Reason for update

Why do you need to update your documentation?

Copilot AI review requested due to automatic review settings December 5, 2025 02:01
…I 以包含使用情况,优化测试用例

Change-Id: If568ea68a8f888784070096876f3b61535ea87d7
Signed-off-by: OhYee <oyohyee@oyohyee.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds include_usage parameter support to streaming options across multiple AI framework model adapters (Google ADK, CrewAI, LangChain, PydanticAI, and AgentScope) and the data API to ensure probes can properly collect token usage information. Additionally, a new GitHub workflow for test package releases has been added.

Key Changes:

  • Added stream_options: {"include_usage": True} to all model adapters for proper token usage collection
  • Updated data API methods (completions and responses) to set include_usage: True in stream options
  • Added test assertions to verify stream_options are correctly configured

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
agentrun/model/api/data.py Modified completions() and responses() methods to set stream_options.include_usage = True, but contains a critical bug with KeyError handling
agentrun/integration/google_adk/model_adapter.py Added stream_options={"include_usage": True} to LiteLlm initialization
agentrun/integration/crewai/model_adapter.py Added stream_options={"include_usage": True} to LLM initialization
agentrun/integration/langchain/model_adapter.py Added stream_usage=True parameter to ChatOpenAI initialization
agentrun/integration/pydantic_ai/model_adapter.py Added ModelSettings with extra_body containing stream_options, removed unused imports
agentrun/integration/agentscope/model_adapter.py Added generate_kwargs={"stream_options": {"include_usage": True}} to OpenAIChatModel
tests/unittests/integration/test_integration.py Added assertions to verify stream_options.include_usage is True in mocked completion calls
.github/workflows/release-test.yml New workflow for building and publishing test packages to PyPI with tag-based triggers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 89 to 91
if kwargs["stream_options"] is None:
kwargs["stream_options"] = {}
kwargs["stream_options"]["include_usage"] = True
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will raise a KeyError when stream_options is not present in kwargs. The condition checks if kwargs["stream_options"] is None, but this will fail if the key doesn't exist at all. Use kwargs.get("stream_options") instead or check with if "stream_options" not in kwargs or kwargs["stream_options"] is None:.

Copilot uses AI. Check for mistakes.
Change-Id: Id5caaaf81550827216a8445af904f60dd8b86142
Signed-off-by: OhYee <oyohyee@oyohyee.com>
@OhYee OhYee force-pushed the fix-add-include-usage branch from 4dd8d69 to 701bb43 Compare December 5, 2025 02:40
Copy link
Contributor

Copilot AI commented Dec 5, 2025

@OhYee I've opened a new pull request, #12, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits December 5, 2025 02:43
Co-authored-by: OhYee <13498329+OhYee@users.noreply.github.com>
[WIP] WIP Address feedback on Google ADK support
@OhYee OhYee merged commit 15e5ac7 into main Dec 5, 2025
1 check passed
@OhYee OhYee deleted the fix-add-include-usage branch December 5, 2025 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants