Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds User-Agent header generation functionality to the Agent365 SDK runtime. The new get_user_agent_header() method creates a standardized User-Agent string containing SDK version information, OS details, Python version, and optional orchestrator identification for HTTP requests.
Key changes:
- Added
get_user_agent_header()static method to theUtilityclass with version caching - Implemented comprehensive unit tests covering default and orchestrator-specific scenarios
- Added necessary imports (
platformmodule andimportlib.metadata.version)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py | Adds new get_user_agent_header() method with version caching logic and platform detection |
| tests/runtime/test_utility.py | Adds two test cases validating User-Agent header format with and without orchestrator parameter |
Comments suppressed due to low confidence (3)
tests/runtime/test_utility.py:146
- The tests directly manipulate the class variable
Utility._cached_versionwhich could cause test isolation issues if tests run in different orders or in parallel. Consider adding test fixtures that save and restore the original value, or add a teardown that resets it toNone. For example:
@pytest.fixture(autouse=True)
def reset_cached_version():
original = Utility._cached_version
yield
Utility._cached_version = original """Test get_user_agent_header returns expected format with default orchestrator."""
# Patch version to a known value
Utility._cached_version = "1.2.3"
result = Utility.get_user_agent_header()
os_type = platform.system()
py_version = platform.python_version()
assert result.startswith(f"Agent365SDK/1.2.3 ({os_type}; Python/{py_version}")
assert ";" not in result.split("Python/")[1] # No orchestrator
def test_get_user_agent_header_with_orchestrator():
"""Test get_user_agent_header includes orchestrator when provided."""
Utility._cached_version = "2.0.0"
orchestrator = "TestOrchestrator"
result = Utility.get_user_agent_header(orchestrator)
assert f"; {orchestrator}" in result
assert result.startswith("Agent365SDK/2.0.0 (")
tests/runtime/test_utility.py:146
- Consider adding a test case that verifies the version caching behavior works correctly (i.e., that
version()is only called once even whenget_user_agent_header()is called multiple times). This would ensure the caching optimization is working as intended.
"""Test get_user_agent_header returns expected format with default orchestrator."""
# Patch version to a known value
Utility._cached_version = "1.2.3"
result = Utility.get_user_agent_header()
os_type = platform.system()
py_version = platform.python_version()
assert result.startswith(f"Agent365SDK/1.2.3 ({os_type}; Python/{py_version}")
assert ";" not in result.split("Python/")[1] # No orchestrator
def test_get_user_agent_header_with_orchestrator():
"""Test get_user_agent_header includes orchestrator when provided."""
Utility._cached_version = "2.0.0"
orchestrator = "TestOrchestrator"
result = Utility.get_user_agent_header(orchestrator)
assert f"; {orchestrator}" in result
assert result.startswith("Agent365SDK/2.0.0 (")
tests/runtime/test_utility.py:11
- Import of 'mocker' is not used.
from microsoft_agents_a365.runtime.utility import Utility
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py
Show resolved
Hide resolved
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py
Show resolved
Hide resolved
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py
Outdated
Show resolved
Hide resolved
pontemonti
approved these changes
Dec 5, 2025
rahuldevikar761
approved these changes
Dec 5, 2025
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.
No description provided.