66from datetime import datetime
77from typing import TYPE_CHECKING , Any , Optional
88
9- from agent_memory_toolkit .logging import get_logger
10-
119from agent_memory_toolkit ._base import _BaseMemoryClient
1210from agent_memory_toolkit ._utils import (
1311 _build_container_kwargs ,
2018 _resolve_full_text_language ,
2119 _validate_connection ,
2220)
21+ from agent_memory_toolkit .aio .auto_trigger import maybe_trigger_steps
2322from agent_memory_toolkit .aio .chat import AsyncChatClient
2423from agent_memory_toolkit .aio .embeddings import AsyncEmbeddingsClient
2524from agent_memory_toolkit .aio .processors import AsyncInProcessProcessor , AsyncMemoryProcessor
26- from agent_memory_toolkit .aio .auto_trigger import maybe_trigger_steps
2725from agent_memory_toolkit .aio .services .pipeline import AsyncPipelineService
2826from agent_memory_toolkit .aio .store import AsyncMemoryStore
2927from agent_memory_toolkit .exceptions import CosmosNotConnectedError , CosmosOperationError
28+ from agent_memory_toolkit .logging import get_logger
3029from agent_memory_toolkit .thresholds import DEFAULT_TTL_BY_TYPE
3130
3231if TYPE_CHECKING : # pragma: no cover - typing-only import
@@ -174,7 +173,12 @@ async def connect_cosmos(
174173 self ._cosmos_container = container or self ._cosmos_container
175174 if turns_container is not None :
176175 self ._cosmos_turns_container = turns_container
177- _validate_connection (self ._cosmos_endpoint , self ._cosmos_credential , self ._cosmos_database , self ._cosmos_container )
176+ _validate_connection (
177+ self ._cosmos_endpoint ,
178+ self ._cosmos_credential ,
179+ self ._cosmos_database ,
180+ self ._cosmos_container ,
181+ )
178182 try :
179183 from azure .cosmos .aio import CosmosClient
180184
@@ -234,7 +238,12 @@ async def create_memory_store(
234238 throughput_mode = self ._cosmos_throughput_mode ,
235239 autoscale_max_ru = autoscale_max_ru if autoscale_max_ru is not None else self ._cosmos_autoscale_max_ru ,
236240 )
237- _validate_connection (self ._cosmos_endpoint , self ._cosmos_credential , self ._cosmos_database , self ._cosmos_container )
241+ _validate_connection (
242+ self ._cosmos_endpoint ,
243+ self ._cosmos_credential ,
244+ self ._cosmos_database ,
245+ self ._cosmos_container ,
246+ )
238247 try :
239248 from azure .cosmos import PartitionKey , ThroughputProperties
240249 from azure .cosmos .aio import CosmosClient
@@ -266,10 +275,18 @@ async def create_memory_store(
266275 )
267276 )
268277 await db .create_container_if_not_exists (
269- ** _build_container_kwargs (container_id = self ._cosmos_counter_container , partition_key = partition_key , offer_throughput = offer )
278+ ** _build_container_kwargs (
279+ container_id = self ._cosmos_counter_container ,
280+ partition_key = partition_key ,
281+ offer_throughput = offer ,
282+ )
270283 )
271284 await db .create_container_if_not_exists (
272- ** _build_container_kwargs (container_id = self ._cosmos_lease_container , partition_key = PartitionKey (path = "/id" ), offer_throughput = offer )
285+ ** _build_container_kwargs (
286+ container_id = self ._cosmos_lease_container ,
287+ partition_key = PartitionKey (path = "/id" ),
288+ offer_throughput = offer ,
289+ )
273290 )
274291 self ._cosmos_client = client
275292 if self ._cosmos_turns_container :
@@ -335,7 +352,8 @@ def _require_pipeline(self) -> None:
335352 if self ._pipeline is None :
336353 if self ._pipeline_init_error is not None :
337354 raise CosmosNotConnectedError (
338- f"Processing pipeline failed to initialize ({ type (self ._pipeline_init_error ).__name__ } : { self ._pipeline_init_error } )."
355+ f"Processing pipeline failed to initialize "
356+ f"({ type (self ._pipeline_init_error ).__name__ } : { self ._pipeline_init_error } )."
339357 ) from self ._pipeline_init_error
340358 raise CosmosNotConnectedError ("Processing pipeline requires Cosmos DB connection." )
341359
@@ -381,7 +399,12 @@ def _get_counter_container(self) -> Any:
381399 except Exception as exc : # pragma: no cover - defensive
382400 if not self ._warned_counter_unreachable :
383401 self ._warned_counter_unreachable = True
384- logger .warning ("Counter container %s/%s unreachable: %s" , self ._cosmos_database , self ._cosmos_counter_container , exc )
402+ logger .warning (
403+ "Counter container %s/%s unreachable: %s" ,
404+ self ._cosmos_database ,
405+ self ._cosmos_counter_container ,
406+ exc ,
407+ )
385408 return None
386409
387410 async def _maybe_auto_trigger (self , turn_counts : dict [tuple [str , str ], int ]) -> None :
@@ -462,7 +485,6 @@ def _containers_for_query(self, memory_types: Optional[list[str]] = None) -> lis
462485 return [self ._turns_container_client ]
463486 return [self ._container_client ]
464487
465-
466488 async def add_cosmos (
467489 self ,
468490 user_id : str ,
@@ -477,7 +499,19 @@ async def add_cosmos(
477499 embedding : Optional [list [float ]] = None ,
478500 embed : Optional [bool ] = None ,
479501 ) -> str :
480- return await self ._get_store ().add (user_id , role , content , memory_type , metadata , thread_id , tags , ttl , salience , embedding , embed )
502+ return await self ._get_store ().add (
503+ user_id ,
504+ role ,
505+ content ,
506+ memory_type ,
507+ metadata ,
508+ thread_id ,
509+ tags ,
510+ ttl ,
511+ salience ,
512+ embedding ,
513+ embed ,
514+ )
481515
482516 async def push_to_cosmos (self , batch_size : int = 25 ) -> None :
483517 """Insert all local memories into Cosmos DB and schedule processing."""
@@ -639,7 +673,13 @@ async def get_procedural_memories(
639673 min_salience : Optional [float ] = None ,
640674 include_superseded : bool = False ,
641675 ) -> list [dict [str , Any ]]:
642- return await self ._get_store ().get_procedural_memories (user_id , priority , category , min_salience , include_superseded )
676+ return await self ._get_store ().get_procedural_memories (
677+ user_id ,
678+ priority ,
679+ category ,
680+ min_salience ,
681+ include_superseded ,
682+ )
643683
644684 async def search_episodic_memories (
645685 self ,
@@ -725,4 +765,3 @@ async def _summary_exists(self, *, user_id: str, thread_id: str) -> bool:
725765 except Exception :
726766 return False
727767 return bool (results )
728-
0 commit comments