Skip to content

[Python] Add a dedicated Cosmos memory provider User-Agent token - #9223

Merged
westey (westey-m) merged 2 commits into
microsoft:mainfrom
TheovanKraay:fix/python-cosmos-memory-user-agent
Oct 9, 2026
Merged

westey (westey-m) merged 2 commits into
microsoft:mainfrom
TheovanKraay:fix/python-cosmos-memory-user-agent

Conversation

@TheovanKraay

@TheovanKraay Theo van Kraay (TheovanKraay) commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

CosmosMemoryContextProvider creates Agent Memory Toolkit clients without a provider-specific User-Agent. Cosmos requests therefore cannot distinguish this integration from direct toolkit usage.

Add the explicit agent-framework-azure-cosmos-memory/<provider-package-version> token to provider-created clients, alongside agent-framework-python/<core-version>. The toolkit retains its own azsdk-python-cosmos-agent-memory/<toolkit-version> token. Attribution can match the dedicated provider token rather than infer usage from generic Agent Framework traffic or customer-level overlap.

Description & Review Guide

  • What are the major changes? Compose a dedicated provider token using the package's existing __version__, pass it with the framework User-Agent to both provider-owned client constructors, assert the exact token in both credential-path tests, and document the behavior.
  • What is the impact of these changes? Provider-created Cosmos requests carry a distinct provider identity. Caller-supplied memory_client instances retain their existing User-Agent configuration. This does not retroactively identify older traffic or instrument injected clients.
  • What do you want reviewers to focus on? The explicit package identity/version, retention of the framework/toolkit identifiers, and preservation of caller-owned clients.

Package unit tests: 53 passed, 12 integration tests deselected. Ruff lint/format and package Pyright passed (0 errors, 0 warnings). A no-network check using the real toolkit and Cosmos SDK User-Agent policy confirmed that the provider header contains all three identifiers and the direct-toolkit header lacks the provider token. Live-service integration tests and the full monorepo suite were not run.

Related Issue

N/A - trivial change: adds a dedicated User-Agent token to two existing provider-owned client constructors, with focused tests and documentation. No public API changes.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: implementation, tests, documentation, and PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) - a workflow keeps the label and title prefix in sync automatically.

Pass the Agent Framework user agent to provider-created Agent Memory Toolkit clients so Cosmos requests identify both integrations. Cover both credential paths and preserve caller-injected clients.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 19:58
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Oct 8, 2026
@github-actions github-actions Bot changed the title [Python] Identify Cosmos memory provider requests with Agent Framework user agent Python: [Python] Identify Cosmos memory provider requests with Agent Framework user agent Oct 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation matches the toolkit API, covers both credential paths, and preserves caller-owned client behavior.

0 open findings

What changed in this PR

Adds Agent Framework identification to provider-created Cosmos memory clients while leaving caller-provided clients unchanged.

Changes:

  • Passes get_user_agent() through both credential paths.
  • Adds focused constructor tests for user-agent propagation and injected-client behavior.
File Description
_context_provider.py Adds the Agent Framework user agent to provider-owned clients.
test_context_provider.py Verifies both construction paths and injected-client behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Identify provider-created clients with agent-framework-azure-cosmos-memory and the provider package version, retaining framework and toolkit tokens. Assert the explicit identity in both credential paths and document injected-client behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheovanKraay Theo van Kraay (TheovanKraay) changed the title Python: [Python] Identify Cosmos memory provider requests with Agent Framework user agent [Python] Add a dedicated Cosmos memory provider User-Agent token Oct 8, 2026
@agent-framework-automation agent-framework-automation Bot added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Oct 8, 2026
@westey-m
westey (westey-m) added this pull request to the merge queue Oct 9, 2026
Merged via the queue into microsoft:main with commit 723d8ca Oct 9, 2026
48 of 49 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — e204d330 Deployed Oct 8, 2026 by TheovanKraay via add_label #24833
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants