Skip to content

Add cadence_thresholds passthrough to clients#29

Merged
aayush3011 merged 4 commits into
AzureCosmosDB:mainfrom
TheovanKraay:feature/client-cadence-thresholds
Jul 8, 2026
Merged

Add cadence_thresholds passthrough to clients#29
aayush3011 merged 4 commits into
AzureCosmosDB:mainfrom
TheovanKraay:feature/client-cadence-thresholds

Conversation

@TheovanKraay

Copy link
Copy Markdown
Contributor

Summary

Adds a cadence_thresholds constructor argument to CosmosMemoryClient and
AsyncCosmosMemoryClient so consumers can set per-turn processing cadence
(fact extraction, dedup, thread/user summary frequency) in-process, instead
of only through environment variables.

Motivation

Today the only way to configure cadence is via environment variables, because the
auto-trigger reads thresholds from os.environ. That's fine for operators, but
it's a problem for library consumers.

The Agent Framework Cosmos memory provider
wraps this client, and to expose cadence configuration it currently has to mutate
os.environ at runtime. Reviewers (rightly) pushed back on that: it's a
process-global side effect, not scoped to the client instance, and surprising in a
library. This change gives consumers a clean, instance-scoped way to pass the
values directly.

Change

The auto-trigger already accepted an optional thresholds override (a mapping keyed
by the same names as the env vars); the clients simply weren't forwarding one. This
PR:

  • Adds cadence_thresholds: Mapping[str, int] | None = None to both clients.
  • Forwards it to maybe_trigger_steps(..., thresholds=self._cadence_thresholds) in
    _maybe_auto_trigger.
client = AsyncCosmosMemoryClient(
    ...,
    cadence_thresholds={
        "FACT_EXTRACTION_EVERY_N": 1,
        "DEDUP_EVERY_N": 5,
        "THREAD_SUMMARY_EVERY_N": 10,
        "USER_SUMMARY_EVERY_N": 20,
    },
)

Consumers can now set per-turn processing cadence (fact extraction, dedup, thread/user summary frequency) in-process via a cadence_thresholds mapping on CosmosMemoryClient and AsyncCosmosMemoryClient, instead of only through os.environ. The auto-trigger already accepted a thresholds override; the clients now forward it. None preserves the env-only behavior and missing keys fall back to env/defaults, so this is backward compatible.
Copilot AI review requested due to automatic review settings July 7, 2026 20:16

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

This PR adds an instance-scoped way to configure the cadence/threshold behavior of the Cosmos memory auto-trigger by introducing a cadence_thresholds constructor argument on both the sync and async Cosmos memory clients, avoiding process-global os.environ mutation for library consumers.

Changes:

  • Added cadence_thresholds: Mapping[str, int] | None to CosmosMemoryClient and AsyncCosmosMemoryClient constructors and stored it on the instance.
  • Forwarded the stored thresholds override into maybe_trigger_steps(..., thresholds=self._cadence_thresholds) from _maybe_auto_trigger.
  • Added unit tests to validate forwarding behavior (including default None) and updated the changelog.

Reviewed changes

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

Show a summary per file
File Description
azure/cosmos/agent_memory/cosmos_memory_client.py Adds cadence_thresholds parameter and forwards it into the sync auto-trigger call.
azure/cosmos/agent_memory/aio/cosmos_memory_client.py Adds cadence_thresholds parameter and forwards it into the async auto-trigger call.
tests/unit/test_cosmos_memory_client.py Adds sync client unit tests verifying thresholds passthrough behavior.
tests/unit/aio/test_auto_trigger.py Adds async client unit tests verifying thresholds passthrough behavior.
CHANGELOG.md Documents the new in-process cadence configuration capability under Unreleased.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/unit/test_cosmos_memory_client.py Outdated
Comment thread tests/unit/aio/test_auto_trigger.py Outdated
Comment thread tests/unit/test_cosmos_memory_client.py Outdated
Comment thread tests/unit/aio/test_auto_trigger.py Outdated

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

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

Comment thread azure/cosmos/agent_memory/cosmos_memory_client.py Outdated
Comment thread azure/cosmos/agent_memory/aio/cosmos_memory_client.py Outdated

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread azure/cosmos/agent_memory/services/_pipeline_helpers.py
Comment thread azure/cosmos/agent_memory/cosmos_memory_client.py
Comment thread azure/cosmos/agent_memory/aio/cosmos_memory_client.py
@aayush3011 aayush3011 merged commit 3b502c7 into AzureCosmosDB:main Jul 8, 2026
7 checks passed
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