Python: Fix Cosmos memory provider calling renamed add_cosmos toolkit API - #7635
Open
Atharva Vichare (atty57) wants to merge 3 commits into
Open
Python: Fix Cosmos memory provider calling renamed add_cosmos toolkit API#7635Atharva Vichare (atty57) wants to merge 3 commits into
Atharva Vichare (atty57) wants to merge 3 commits into
Conversation
… API The Agent Memory Toolkit renamed AsyncCosmosMemoryClient.add_cosmos to upsert_memory with an identical signature. The provider declares azure-cosmos-agent-memory>=0.2.0b3 with no upper bound, so a resolved install can expose either name. after_run swallows write errors and only logs a warning, so on a post-rename toolkit the agent turn still looks successful while long-term memory silently stops receiving turns. Resolve the write method once per after_run, preferring upsert_memory and falling back to add_cosmos, so both ends of the declared range keep working. Same treatment for the emulator test's direct seed call. Fixes microsoft#7633
Atharva Vichare (atty57)
deployed
to
github-app-auth
August 12, 2026 19:31 — with
GitHub Actions
Active
Atharva Vichare (atty57)
deployed
to
github-app-auth
August 12, 2026 19:31 — with
GitHub Actions
Active
Atharva Vichare (atty57)
deployed
to
github-app-auth
August 12, 2026 19:31 — with
GitHub Actions
Active
Atharva Vichare (atty57)
deployed
to
github-app-auth
August 12, 2026 19:31 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
Pull request overview
Adds compatibility with renamed Cosmos memory toolkit APIs while preserving older-version support.
Changes:
- Prefer
upsert_memory, falling back toadd_cosmos. - Update unit and emulator tests for both API versions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
_context_provider.py |
Adds compatible turn-write resolution. |
test_context_provider.py |
Tests new and legacy APIs. |
test_emulator.py |
Makes emulator seeding version-compatible. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Atharva Vichare (atty57)
deployed
to
github-app-auth
August 12, 2026 19:35 — with
GitHub Actions
Active
Evan Mattson (moonbox3)
approved these changes
Aug 13, 2026
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Updated TODO comment to include author and clarify context , to resolve linting error
Atharva Vichare (atty57)
deployed
to
github-app-auth
August 13, 2026 01:31 — with
GitHub Actions
Active
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.
Fixes #7633
Motivation and Context
The Agent Memory Toolkit renamed
AsyncCosmosMemoryClient.add_cosmostoupsert_memory. The signature is otherwise identical (user_id,thread_id,role,content, plus the same optional kwargs).agent-framework-azure-cosmos-memorydeclaresazure-cosmos-agent-memory>=0.2.0b3with no upper bound, so a resolved install can expose either name.CosmosMemoryContextProvider.after_run()callsadd_cosmosunconditionally, and its write path is wrapped in atry/exceptthat only logs a warning — so on a post-rename toolkit the agent turn still reports success while long-term memory silently stops receiving turns. That silent failure mode is what makes this worth fixing ahead of the release rather than after.Description
Resolve the write method once per
after_run, preferringupsert_memoryand falling back toadd_cosmos, so both ends of the currently declared dependency range keep working. No dependency pin is needed and no public API changes.The emulator test's direct seed call gets the same treatment, since it would otherwise break against a newer toolkit.
The fallback is marked with a comment pointing at the cleanup: once the declared
azure-cosmos-agent-memoryfloor is past the rename, thegetattrcollapses to a directupsert_memorycall.Contribution Checklist
Existing
after_runtests were updated to the new method name, and a new test (test_falls_back_to_add_cosmos_on_older_toolkit) covers the pre-rename client so neither direction can silently regress.uv run poe check -P azure-cosmos-memoryis green: fmt, lint, pyright, mypy/pyrefly/ty/zuban, and 44 tests at 100% coverage.