Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

Commit e54eaf9

Browse files
committed
Fix formatting
1 parent 4be056b commit e54eaf9

File tree

7 files changed

+35
-37
lines changed

7 files changed

+35
-37
lines changed

examples/asyncpg-memory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import asyncio
2+
13
import controlflow as cf
24
from controlflow.memory.async_memory import AsyncMemory
3-
45
from controlflow.memory.providers.postgres import AsyncPostgresMemory
5-
import asyncio
6-
76

87
provider = AsyncPostgresMemory(
98
database_url="postgresql+psycopg://postgres:postgres@localhost:5432/database",
@@ -33,7 +32,6 @@ async def remember_pet():
3332
)
3433

3534

36-
3735
# Create a flow to recall the user's favorite color
3836
@cf.flow
3937
async def recall_pet():
@@ -42,6 +40,7 @@ async def recall_pet():
4240
agents=[agent],
4341
)
4442

43+
4544
async def main():
4645
print("First flow:")
4746
await remember_pet()
@@ -51,5 +50,6 @@ async def main():
5150
print(result)
5251
return result
5352

53+
5454
if __name__ == "__main__":
5555
asyncio.run(main())

src/controlflow/defaults.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import controlflow.utilities
77
import controlflow.utilities.logging
88
from controlflow.llm.models import BaseChatModel
9-
from controlflow.memory.memory import MemoryProvider, get_memory_provider
109
from controlflow.memory.async_memory import AsyncMemoryProvider, get_memory_provider
10+
from controlflow.memory.memory import MemoryProvider, get_memory_provider
1111
from controlflow.utilities.general import ControlFlowModel
1212

1313
from .agents import Agent
@@ -40,7 +40,9 @@ class Defaults(ControlFlowModel):
4040
model: Optional[Any]
4141
history: History
4242
agent: Agent
43-
memory_provider: Optional[Union[MemoryProvider, str]] | Optional[Union[AsyncMemoryProvider, str]]
43+
memory_provider: (
44+
Optional[Union[MemoryProvider, str]] | Optional[Union[AsyncMemoryProvider, str]]
45+
)
4446

4547
# add more defaults here
4648
def __repr__(self) -> str:

src/controlflow/memory/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .memory import Memory
2-
from .async_memory import AsyncMemory
2+
from .async_memory import AsyncMemory

src/controlflow/memory/async_memory.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def validate_key(cls, v: str) -> str:
9696
)
9797
return sanitized
9898

99-
10099
async def _configure_provider(self):
101100
await self.provider.configure(self.key)
102101
return self
@@ -133,7 +132,6 @@ def get_tools(self) -> List[Tool]:
133132
def get_memory_provider(provider: str) -> AsyncMemoryProvider:
134133
logger.debug(f"Loading memory provider: {provider}")
135134

136-
137135
# --- async postgres ---
138136

139137
if provider.startswith("async-postgres"):

src/controlflow/memory/providers/postgres.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import uuid
22
from typing import Callable, Dict, Optional
33

4+
# async pg
5+
import anyio
46
import sqlalchemy
57
from pgvector.sqlalchemy import Vector
68
from pydantic import Field
79
from sqlalchemy import Column, String, select, text
810
from sqlalchemy.dialects.postgresql import ARRAY
911
from sqlalchemy.exc import ProgrammingError
10-
from sqlalchemy.orm import Session, declarative_base, sessionmaker
11-
from sqlalchemy_utils import create_database, database_exists
12-
13-
#async pg
14-
import anyio
1512
from sqlalchemy.ext.asyncio import (
16-
create_async_engine,
1713
AsyncEngine,
1814
AsyncSession,
1915
async_sessionmaker,
16+
create_async_engine,
2017
)
18+
from sqlalchemy.orm import Session, declarative_base, sessionmaker
19+
from sqlalchemy_utils import create_database, database_exists
2120

2221
import controlflow
23-
from controlflow.memory.memory import MemoryProvider
2422
from controlflow.memory.async_memory import AsyncMemoryProvider
23+
from controlflow.memory.memory import MemoryProvider
24+
2525
try:
2626
# For embeddings, we can use langchain_openai or any other library:
2727
from langchain_openai import OpenAIEmbeddings
@@ -125,7 +125,7 @@ def configure(self, memory_key: str) -> None:
125125
pool_timeout=self.pool_timeout,
126126
pool_recycle=self.pool_recycle,
127127
pool_pre_ping=self.pool_pre_ping,
128-
)
128+
)
129129

130130
# 2) If DB doesn't exist, create it!
131131
if not database_exists(engine.url):
@@ -239,7 +239,6 @@ def search(self, memory_key: str, query: str, n: int = 20) -> Dict[str, str]:
239239
return {row.id: row.text for row in results}
240240

241241

242-
243242
class AsyncPostgresMemory(AsyncMemoryProvider):
244243
"""
245244
An async MemoryProvider storing text + embeddings in PostgreSQL
@@ -249,7 +248,7 @@ class AsyncPostgresMemory(AsyncMemoryProvider):
249248
database_url: str = Field(
250249
default="postgresql+asyncpg://user:password@localhost:5432/your_database",
251250
description="Async Postgres URL with the asyncpg driver, e.g. "
252-
"'postgresql+asyncpg://user:pass@host:5432/dbname'."
251+
"'postgresql+asyncpg://user:pass@host:5432/dbname'.",
253252
)
254253

255254
table_name: str = Field(
@@ -261,34 +260,30 @@ class AsyncPostgresMemory(AsyncMemoryProvider):
261260

262261
embedding_dimension: int = Field(
263262
default=1536,
264-
description="Dimension of the embedding vectors. Must match your model output size."
263+
description="Dimension of the embedding vectors. Must match your model output size.",
265264
)
266265

267266
embedding_fn: Callable = Field(
268267
default_factory=lambda: OpenAIEmbeddings(model="text-embedding-ada-002"),
269-
description="Function that turns a string into a numeric vector."
268+
description="Function that turns a string into a numeric vector.",
270269
)
271270

272271
# -- Pool / Engine settings (SQLAlchemy will do the pooling)
273272
pool_size: int = Field(
274-
5,
275-
description="Number of permanent connections in the async pool."
273+
5, description="Number of permanent connections in the async pool."
276274
)
277275
max_overflow: int = Field(
278-
10,
279-
description="Number of 'overflow' connections if the pool is full."
276+
10, description="Number of 'overflow' connections if the pool is full."
280277
)
281278
pool_timeout: int = Field(
282-
30,
283-
description="Seconds to wait for a connection before raising an error."
279+
30, description="Seconds to wait for a connection before raising an error."
284280
)
285281
pool_recycle: int = Field(
286282
1800,
287-
description="Recycle connections after N seconds to avoid stale connections."
283+
description="Recycle connections after N seconds to avoid stale connections.",
288284
)
289285
pool_pre_ping: bool = Field(
290-
True,
291-
description="Check connection health before using from the pool."
286+
True, description="Check connection health before using from the pool."
292287
)
293288

294289
# We'll store an async engine + session factory:
@@ -299,7 +294,7 @@ class AsyncPostgresMemory(AsyncMemoryProvider):
299294
_table_class_cache: Dict[str, Base] = {}
300295

301296
_configured: bool = False
302-
297+
303298
async def configure(self, memory_key: str) -> None:
304299
"""
305300
1) Create an async engine.
@@ -347,12 +342,16 @@ async def configure(self, memory_key: str) -> None:
347342
# (2) Actually create it (async):
348343
def _sync_create(connection):
349344
"""Helper function to run table creation in sync context."""
350-
Base.metadata.create_all(connection, tables=[memory_model.__table__])
345+
Base.metadata.create_all(
346+
connection, tables=[memory_model.__table__]
347+
)
351348

352349
try:
353350
await conn.run_sync(_sync_create)
354351
except ProgrammingError as e:
355-
raise RuntimeError(f"Failed to create table '{table_name}': {e}")
352+
raise RuntimeError(
353+
f"Failed to create table '{table_name}': {e}"
354+
)
356355

357356
# 4) Now that the DB and table are ready, create a session factory
358357
self._SessionLocal = async_sessionmaker(
@@ -362,7 +361,6 @@ def _sync_create(connection):
362361

363362
self._configured = True
364363

365-
366364
def _get_table(self, memory_key: str) -> Base:
367365
"""
368366
Return or create the dynamic model class for 'memory_{key}' table.
@@ -456,4 +454,4 @@ async def search(self, memory_key: str, query: str, n: int = 20) -> Dict[str, st
456454
rows = results.all()
457455

458456
# Convert list of Row objects -> dict
459-
return {row.id: row.text for row in rows}
457+
return {row.id: row.text for row in rows}

src/controlflow/orchestration/prompt_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from controlflow.agents.agent import Agent
66
from controlflow.flows import Flow
7-
from controlflow.memory.memory import Memory
87
from controlflow.memory.async_memory import AsyncMemory
8+
from controlflow.memory.memory import Memory
99
from controlflow.tasks.task import Task
1010
from controlflow.tools.tools import Tool
1111
from controlflow.utilities.general import ControlFlowModel

src/controlflow/tasks/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import controlflow
3838
from controlflow.agents import Agent
3939
from controlflow.instructions import get_instructions
40-
from controlflow.memory.memory import Memory
4140
from controlflow.memory.async_memory import AsyncMemory
41+
from controlflow.memory.memory import Memory
4242
from controlflow.tools import Tool, tool
4343
from controlflow.tools.input import cli_input
4444
from controlflow.tools.tools import as_tools

0 commit comments

Comments
 (0)