Skip to content

Commit 4fc4687

Browse files
committed
fix: Address CI failures and documentation issues
- Add return type annotations to all factory functions (-> Any) - Fix mypy import handling for optional langchain_core dependency - Add explicit str() conversions to avoid no-any-return errors - Add langchain-integration.md to mkdocs nav configuration - Fix broken link to example file (use GitHub URL instead of relative path) All mypy checks now pass and documentation builds successfully.
1 parent 38f71e9 commit 4fc4687

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

agent-memory-client/agent_memory_client/integrations/langchain.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
LANGCHAIN_AVAILABLE = True
5252
except ImportError:
5353
LANGCHAIN_AVAILABLE = False
54-
StructuredTool = None # type: ignore
54+
StructuredTool = None # type: ignore[misc,assignment]
5555

5656

5757
def _check_langchain_available() -> None:
@@ -215,7 +215,7 @@ def get_memory_tools(
215215
# These create the actual async functions that LangChain will call
216216

217217

218-
def _create_search_memory_func(client: MemoryAPIClient):
218+
def _create_search_memory_func(client: MemoryAPIClient) -> Any:
219219
"""Create search_memory function."""
220220

221221
async def search_memory(
@@ -237,7 +237,7 @@ async def search_memory(
237237
min_relevance=min_relevance,
238238
user_id=user_id,
239239
)
240-
return result.get("summary", str(result))
240+
return str(result.get("summary", str(result)))
241241

242242
return search_memory
243243

@@ -247,7 +247,7 @@ def _create_get_working_memory_func(
247247
session_id: str,
248248
namespace: str | None,
249249
user_id: str | None,
250-
):
250+
) -> Any:
251251
"""Create get_or_create_working_memory function."""
252252

253253
async def get_or_create_working_memory() -> str:
@@ -257,7 +257,7 @@ async def get_or_create_working_memory() -> str:
257257
namespace=namespace,
258258
user_id=user_id,
259259
)
260-
return result.get("summary", str(result))
260+
return str(result.get("summary", str(result)))
261261

262262
return get_or_create_working_memory
263263

@@ -267,7 +267,7 @@ def _create_add_memory_func(
267267
session_id: str,
268268
namespace: str | None,
269269
user_id: str | None,
270-
):
270+
) -> Any:
271271
"""Create add_memory_to_working_memory function."""
272272

273273
async def add_memory_to_working_memory(
@@ -286,7 +286,7 @@ async def add_memory_to_working_memory(
286286
namespace=namespace,
287287
user_id=user_id,
288288
)
289-
return result.get("summary", str(result))
289+
return str(result.get("summary", str(result)))
290290

291291
return add_memory_to_working_memory
292292

@@ -296,7 +296,7 @@ def _create_update_memory_data_func(
296296
session_id: str,
297297
namespace: str | None,
298298
user_id: str | None,
299-
):
299+
) -> Any:
300300
"""Create update_working_memory_data function."""
301301

302302
async def update_working_memory_data(
@@ -311,12 +311,12 @@ async def update_working_memory_data(
311311
namespace=namespace,
312312
user_id=user_id,
313313
)
314-
return result.get("summary", str(result))
314+
return str(result.get("summary", str(result)))
315315

316316
return update_working_memory_data
317317

318318

319-
def _create_get_long_term_memory_func(client: MemoryAPIClient):
319+
def _create_get_long_term_memory_func(client: MemoryAPIClient) -> Any:
320320
"""Create get_long_term_memory function."""
321321

322322
async def get_long_term_memory(memory_id: str) -> str:
@@ -327,7 +327,7 @@ async def get_long_term_memory(memory_id: str) -> str:
327327
session_id="", # Not needed for long-term memory retrieval
328328
)
329329
if result["success"]:
330-
return result["formatted_response"]
330+
return str(result["formatted_response"])
331331
else:
332332
return f"Error: {result.get('error', 'Unknown error')}"
333333

@@ -338,7 +338,7 @@ def _create_create_long_term_memory_func(
338338
client: MemoryAPIClient,
339339
namespace: str | None,
340340
user_id: str | None,
341-
):
341+
) -> Any:
342342
"""Create create_long_term_memory function."""
343343

344344
async def create_long_term_memory(memories: list[dict[str, Any]]) -> str:
@@ -351,14 +351,14 @@ async def create_long_term_memory(memories: list[dict[str, Any]]) -> str:
351351
user_id=user_id,
352352
)
353353
if result["success"]:
354-
return result["formatted_response"]
354+
return str(result["formatted_response"])
355355
else:
356356
return f"Error: {result.get('error', 'Unknown error')}"
357357

358358
return create_long_term_memory
359359

360360

361-
def _create_edit_long_term_memory_func(client: MemoryAPIClient):
361+
def _create_edit_long_term_memory_func(client: MemoryAPIClient) -> Any:
362362
"""Create edit_long_term_memory function."""
363363

364364
async def edit_long_term_memory(
@@ -389,14 +389,14 @@ async def edit_long_term_memory(
389389
session_id="", # Not needed for long-term memory editing
390390
)
391391
if result["success"]:
392-
return result["formatted_response"]
392+
return str(result["formatted_response"])
393393
else:
394394
return f"Error: {result.get('error', 'Unknown error')}"
395395

396396
return edit_long_term_memory
397397

398398

399-
def _create_delete_long_term_memories_func(client: MemoryAPIClient):
399+
def _create_delete_long_term_memories_func(client: MemoryAPIClient) -> Any:
400400
"""Create delete_long_term_memories function."""
401401

402402
async def delete_long_term_memories(memory_ids: list[str]) -> str:
@@ -407,14 +407,14 @@ async def delete_long_term_memories(memory_ids: list[str]) -> str:
407407
session_id="", # Not needed for long-term memory deletion
408408
)
409409
if result["success"]:
410-
return result["formatted_response"]
410+
return str(result["formatted_response"])
411411
else:
412412
return f"Error: {result.get('error', 'Unknown error')}"
413413

414414
return delete_long_term_memories
415415

416416

417-
def _create_get_current_datetime_func(client: MemoryAPIClient):
417+
def _create_get_current_datetime_func(client: MemoryAPIClient) -> Any:
418418
"""Create get_current_datetime function."""
419419

420420
async def get_current_datetime() -> str:
@@ -425,7 +425,7 @@ async def get_current_datetime() -> str:
425425
session_id="", # Not needed for datetime
426426
)
427427
if result["success"]:
428-
return result["formatted_response"]
428+
return str(result["formatted_response"])
429429
else:
430430
return f"Error: {result.get('error', 'Unknown error')}"
431431

docs/langchain-integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,4 @@ except ValueError as e:
338338
- [Memory Integration Patterns](memory-integration-patterns.md) - Overview of different integration approaches
339339
- [Python SDK](python-sdk.md) - Direct SDK usage without LangChain
340340
- [Agent Examples](agent-examples.md) - More agent implementation examples
341-
- [LangChain Integration Example](../examples/langchain_integration_example.py) - Complete working example
341+
- [LangChain Integration Example](https://github.com/redis/agent-memory-server/blob/main/examples/langchain_integration_example.py) - Complete working example

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ nav:
8888

8989
- Python SDK:
9090
- SDK Documentation: python-sdk.md
91+
- LangChain Integration: langchain-integration.md
9192
- Configuration: configuration.md
9293

9394
- Examples:

0 commit comments

Comments
 (0)