Skip to content

Python: Fix Cosmos memory provider calling renamed add_cosmos toolkit API - #7635

Open
Atharva Vichare (atty57) wants to merge 3 commits into
microsoft:mainfrom
atty57:atty57-7633
Open

Python: Fix Cosmos memory provider calling renamed add_cosmos toolkit API#7635
Atharva Vichare (atty57) wants to merge 3 commits into
microsoft:mainfrom
atty57:atty57-7633

Conversation

@atty57

Copy link
Copy Markdown
Contributor

Fixes #7633

Motivation and Context

The Agent Memory Toolkit renamed AsyncCosmosMemoryClient.add_cosmos to upsert_memory. The signature is otherwise identical (user_id, thread_id, role, content, plus the same optional kwargs).

agent-framework-azure-cosmos-memory declares azure-cosmos-agent-memory>=0.2.0b3 with no upper bound, so a resolved install can expose either name. CosmosMemoryContextProvider.after_run() calls add_cosmos unconditionally, and its write path is wrapped in a try/except that 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, preferring upsert_memory and falling back to add_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-memory floor is past the rename, the getattr collapses to a direct upsert_memory call.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible

Existing after_run tests 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-memory is green: fmt, lint, pyright, mypy/pyrefly/ty/zuban, and 44 tests at 100% coverage.

… 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

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.

Pull request overview

Adds compatibility with renamed Cosmos memory toolkit APIs while preserving older-version support.

Changes:

  • Prefer upsert_memory, falling back to add_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>
@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-cosmos-memory/agent_framework_azure_cosmos_memory
   _context_provider.py1380100% 
TOTAL45768423390% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9297 36 💤 0 ❌ 0 🔥 2m 13s ⏱️

Updated TODO comment to include author and clarify context , to resolve linting error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Cosmos memory provider still calls add_cosmos after toolkit API rename

3 participants