Skip to content

Commit 894d839

Browse files
Aayush KatariaCopilot
authored andcommitted
lint: fix ruff E501/F841 violations and apply ruff format
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1a6fc08 commit 894d839

46 files changed

Lines changed: 278 additions & 216 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ venv/
3535

3636
# macOS
3737
.DS_Store
38+
39+
# JetBrains IDEs
40+
.idea/
41+
42+
# Local scratch notes
43+
Agent Memory Toolkit.txt
44+
Cosmos AI Memory Service.txt

agent_memory_toolkit/_base/base_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ def _require_cosmos(self) -> None:
208208
raise CosmosNotConnectedError()
209209

210210
def _warn_on_embedding_dim_mismatch(self, container: Any = None) -> None:
211-
"""Log a warning when the configured embedding dim differs from the container policy.
212-
"""
211+
"""Log a warning when the configured embedding dim differs from the container policy."""
213212
container = container if container is not None else self._container_client
214213
if container is None or self._embedding_dimensions is None:
215214
return

agent_memory_toolkit/_counters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828

2929
from __future__ import annotations
3030

31-
from agent_memory_toolkit.logging import get_logger
3231
from datetime import datetime, timezone
3332
from typing import Any, Optional
3433

3534
from azure.core import MatchConditions
3635
from azure.cosmos.exceptions import CosmosHttpResponseError, CosmosResourceNotFoundError
3736

37+
from agent_memory_toolkit.logging import get_logger
38+
3839
logger = get_logger(__name__)
3940

4041
USER_COUNTER_THREAD_ID = "__counters__"

agent_memory_toolkit/_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
from ._query_builder import _QueryBuilder
1717
from .exceptions import ConfigurationError, ValidationError
18-
from .thresholds import DEFAULT_TTL_BY_TYPE as DEFAULT_TTL_BY_TYPE, default_ttl_for
18+
from .thresholds import DEFAULT_TTL_BY_TYPE as DEFAULT_TTL_BY_TYPE
19+
from .thresholds import default_ttl_for
1920

2021
VALID_ROLES = {"agent", "user", "tool", "system"}
2122
VALID_TYPES = {"turn", "summary", "fact", "user_summary", "procedural", "episodic"}
@@ -58,6 +59,7 @@ def new_user_summary_id() -> str:
5859
"""Return a fresh ``user_summary_*`` id."""
5960
return new_id("user_summary")
6061

62+
6163
_WHITESPACE_RE = re.compile(r"\s+")
6264

6365

agent_memory_toolkit/aio/auto_trigger.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
import asyncio
99
import inspect
10-
from agent_memory_toolkit.logging import get_logger
1110
from collections.abc import Callable
1211
from typing import Any
1312

1413
from agent_memory_toolkit import _counters
1514
from agent_memory_toolkit import thresholds as default_thresholds
1615
from agent_memory_toolkit.aio.processors import AsyncInProcessProcessor
1716
from agent_memory_toolkit.auto_trigger import _threshold_int, _threshold_value
17+
from agent_memory_toolkit.logging import get_logger
1818

1919
logger = get_logger(__name__)
2020

@@ -135,10 +135,25 @@ async def _fire_thread_steps(
135135
)
136136
)
137137
calls = (
138-
(fire_extract, "process_extract_memories", processor.process_extract_memories, {"user_id": user_id, "thread_id": thread_id}),
138+
(
139+
fire_extract,
140+
"process_extract_memories",
141+
processor.process_extract_memories,
142+
{"user_id": user_id, "thread_id": thread_id},
143+
),
139144
(fire_dedup, "process_reconcile", processor.process_reconcile, {"user_id": user_id}),
140-
(fire_procedural, "synthesize_procedural", processor.synthesize_procedural, {"user_id": user_id}),
141-
(fire_summary, "process_thread_summary", processor.process_thread_summary, {"user_id": user_id, "thread_id": thread_id}),
145+
(
146+
fire_procedural,
147+
"synthesize_procedural",
148+
processor.synthesize_procedural,
149+
{"user_id": user_id},
150+
),
151+
(
152+
fire_summary,
153+
"process_thread_summary",
154+
processor.process_thread_summary,
155+
{"user_id": user_id, "thread_id": thread_id},
156+
),
142157
)
143158
for enabled, label, method, kwargs in calls:
144159
if not enabled:

agent_memory_toolkit/aio/chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from __future__ import annotations
1010

1111
import asyncio
12-
from agent_memory_toolkit.logging import get_logger
1312
from typing import Any
1413

1514
from agent_memory_toolkit.chat import (
@@ -19,7 +18,8 @@
1918
resolve_api_version,
2019
unsupported_param,
2120
)
22-
from agent_memory_toolkit.exceptions import ConfigurationError, LLMError
21+
from agent_memory_toolkit.exceptions import ConfigurationError
22+
from agent_memory_toolkit.logging import get_logger
2323

2424
logger = get_logger(__name__)
2525

agent_memory_toolkit/aio/cosmos_memory_client.py

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from datetime import datetime
77
from typing import TYPE_CHECKING, Any, Optional
88

9-
from agent_memory_toolkit.logging import get_logger
10-
119
from agent_memory_toolkit._base import _BaseMemoryClient
1210
from agent_memory_toolkit._utils import (
1311
_build_container_kwargs,
@@ -20,13 +18,14 @@
2018
_resolve_full_text_language,
2119
_validate_connection,
2220
)
21+
from agent_memory_toolkit.aio.auto_trigger import maybe_trigger_steps
2322
from agent_memory_toolkit.aio.chat import AsyncChatClient
2423
from agent_memory_toolkit.aio.embeddings import AsyncEmbeddingsClient
2524
from agent_memory_toolkit.aio.processors import AsyncInProcessProcessor, AsyncMemoryProcessor
26-
from agent_memory_toolkit.aio.auto_trigger import maybe_trigger_steps
2725
from agent_memory_toolkit.aio.services.pipeline import AsyncPipelineService
2826
from agent_memory_toolkit.aio.store import AsyncMemoryStore
2927
from agent_memory_toolkit.exceptions import CosmosNotConnectedError, CosmosOperationError
28+
from agent_memory_toolkit.logging import get_logger
3029
from agent_memory_toolkit.thresholds import DEFAULT_TTL_BY_TYPE
3130

3231
if 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-

agent_memory_toolkit/aio/embeddings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from __future__ import annotations
99

1010
import asyncio
11-
from agent_memory_toolkit.chat import resolve_api_version
12-
from agent_memory_toolkit.logging import get_logger
1311
from typing import Any
1412

13+
from agent_memory_toolkit.chat import resolve_api_version
1514
from agent_memory_toolkit.exceptions import ConfigurationError
15+
from agent_memory_toolkit.logging import get_logger
1616

1717
logger = get_logger(__name__)
1818

agent_memory_toolkit/aio/processors/durable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from __future__ import annotations
44

5-
from agent_memory_toolkit.logging import get_logger
65
from typing import Any, Optional
76

7+
from agent_memory_toolkit.logging import get_logger
88
from agent_memory_toolkit.processors.base import (
99
ProcessThreadResult,
1010
UserSummaryResult,

agent_memory_toolkit/aio/processors/inprocess.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,3 @@ async def close(self) -> None:
147147

148148

149149
__all__ = ["AsyncInProcessProcessor"]
150-

0 commit comments

Comments
 (0)