Skip to content

Add Create User-Agent Header Utility#83

Merged
JesuTerraz merged 7 commits intomainfrom
users/jterrazas/add-user-agent-header
Dec 5, 2025
Merged

Add Create User-Agent Header Utility#83
JesuTerraz merged 7 commits intomainfrom
users/jterrazas/add-user-agent-header

Conversation

@JesuTerraz
Copy link
Contributor

No description provided.

@JesuTerraz JesuTerraz requested a review from a team as a code owner December 4, 2025 19:25
Copilot AI review requested due to automatic review settings December 4, 2025 19:25
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 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 the Utility class with version caching
  • Implemented comprehensive unit tests covering default and orchestrator-specific scenarios
  • Added necessary imports (platform module and importlib.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_version which 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 to None. 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 when get_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

@JesuTerraz JesuTerraz changed the title Add User-Agent Header Add Create User-Agent Header Utility Dec 4, 2025
Copilot AI review requested due to automatic review settings December 4, 2025 21:28
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

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

Copilot AI review requested due to automatic review settings December 4, 2025 22:01
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

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

@JesuTerraz JesuTerraz merged commit 8946789 into main Dec 5, 2025
8 checks passed
@JesuTerraz JesuTerraz deleted the users/jterrazas/add-user-agent-header branch December 5, 2025 23:06
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.

3 participants