Skip to content

Commit fdeb69e

Browse files
committed
More client enhancements to tool-based access
1 parent b838fca commit fdeb69e

File tree

6 files changed

+166
-31
lines changed

6 files changed

+166
-31
lines changed

TASK_MEMORY.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

agent-memory-client/agent_memory_client/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
WorkingMemoryResponse,
4141
)
4242

43-
4443
# === Tool Call Type Definitions ===
4544

4645

@@ -820,7 +819,7 @@ async def search_memory_tool(
820819
result = await client.search_memory_tool(**args)
821820
```
822821
"""
823-
from .filters import Topics, Entities, MemoryType
822+
from .filters import Entities, MemoryType, Topics
824823

825824
# Convert simple parameters to filter objects
826825
topics_filter = Topics(any=topics) if topics else None

agent_memory_server/extraction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import os
33
from typing import Any
44

5+
import ulid
56
from bertopic import BERTopic
67
from redis.asyncio.client import Redis
78
from redisvl.query.filter import Tag
89
from redisvl.query.query import FilterQuery
910
from tenacity.asyncio import AsyncRetrying
1011
from tenacity.stop import stop_after_attempt
1112
from transformers import AutoModelForTokenClassification, AutoTokenizer, pipeline
12-
import ulid
1313

1414
from agent_memory_server.config import settings
1515
from agent_memory_server.llms import (

agent_memory_server/mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import os
33
from typing import Any
44

5-
from mcp.server.fastmcp import FastMCP as _FastMCPBase
65
import ulid
6+
from mcp.server.fastmcp import FastMCP as _FastMCPBase
77

88
from agent_memory_server.api import (
99
create_long_term_memory as core_create_long_term_memory,

agent_memory_server/migrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Simplest possible migrations you could have.
33
"""
44

5-
from redis.asyncio import Redis
65
import ulid
6+
from redis.asyncio import Redis
77

88
from agent_memory_server.logging import get_logger
99
from agent_memory_server.long_term_memory import generate_memory_hash

client-tools.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Task Memory
2+
3+
**Created:** 2025-06-13 16:34:19
4+
**Branch:** feature/separate-client-codebase
5+
6+
## Requirements
7+
8+
Fix the errors generated with the command 'uv run mypy agent_memory_client'
9+
10+
## Development Notes
11+
12+
*Update this section as you work on the task. Include:*
13+
- *Progress updates*
14+
- *Key decisions made*
15+
- *Challenges encountered*
16+
- *Solutions implemented*
17+
- *Files modified*
18+
- *Testing notes*
19+
20+
### Work Log
21+
22+
- [2025-06-13 16:34:19] Task setup completed, TASK_MEMORY.md created
23+
24+
#### [2025-06-13 17:00:00] Completed mypy error fixes and namespace refactoring
25+
26+
**Issues Addressed:**
27+
1. **Fixed mypy type errors in agent_memory_client:** Added py.typed marker file to indicate type information availability
28+
2. **Continued namespace refactoring in travel_agent.py:** Enhanced user ID integration into namespaces
29+
3. **Resolved import and type annotation issues:** Fixed all type-related errors in the travel agent example
30+
31+
**Key Changes Made:**
32+
33+
1. **Added py.typed marker:** Created `agent-memory-client/agent_memory_client/py.typed` to resolve import stub issues
34+
35+
2. **Enhanced TravelAgent class with proper namespace handling:**
36+
- Added `_get_namespace(user_id)` helper method for consistent namespace generation
37+
- Refactored client management to support multiple users with per-user clients
38+
- Updated `get_client()` to maintain separate `MemoryAPIClient` instances per user
39+
- Fixed `cleanup()` method to properly close all client connections
40+
41+
3. **Fixed type annotations throughout travel_agent.py:**
42+
- Corrected `MemoryType` usage to use `MemoryTypeEnum` directly
43+
- Added proper imports for `Namespace` and `MemoryRecordResult` filter types
44+
- Updated method signatures to use correct return types (`MemoryRecordResult` vs `MemoryRecord`)
45+
- Fixed namespace parameter usage in search methods to use `Namespace(eq=namespace_string)`
46+
47+
4. **Ensured consistent namespace usage:**
48+
- All memory operations now explicitly use the `travel_agent:{user_id}` namespace pattern
49+
- Working memory operations correctly set namespace in memory objects
50+
- Long-term memory search and storage operations use proper namespace filters
51+
52+
**Files Modified:**
53+
- `agent-memory-client/agent_memory_client/py.typed` (created)
54+
- `examples/travel_agent.py` (extensively refactored)
55+
56+
**Testing:**
57+
-`uv run mypy agent-memory-client/agent_memory_client` - Success: no issues found
58+
-`uv run mypy examples/travel_agent.py` - Success: no issues found
59+
60+
**Key Decisions:**
61+
- Chose to maintain separate client instances per user for better isolation and namespace management
62+
- Used explicit `Namespace` filter objects rather than relying on default namespace configuration
63+
- Maintained backward compatibility with existing method signatures while fixing type annotations
64+
65+
#### [2025-06-13 17:20:00] Removed redundant features that memory server already handles
66+
67+
**Issues Addressed:**
68+
1. **Removed manual summarization:** Eliminated conversation summarization logic since memory server handles this automatically
69+
2. **Removed manual memory extraction:** Eliminated LLM-based memory extraction since memory server provides automatic extraction
70+
3. **Removed duplicate checking:** Eliminated manual similar memory checking since memory server handles deduplication
71+
4. **Removed manual memory retrieval and augmentation:** Simplified to rely on memory server's built-in capabilities
72+
73+
**Key Simplifications:**
74+
75+
1. **Removed summarization infrastructure:**
76+
- Deleted `MESSAGE_SUMMARIZATION_THRESHOLD` constant
77+
- Removed `_summarize_conversation()` method
78+
- Eliminated summarization logic from `_add_message_to_working_memory()`
79+
- Removed `summarizer` LLM instance
80+
81+
2. **Removed manual memory management:**
82+
- Deleted `Memory` and `Memories` Pydantic models
83+
- Removed `MemoryStrategy` enum and related strategy logic
84+
- Eliminated `_extract_memories_from_conversation()` method
85+
- Removed `_store_long_term_memory()` method
86+
- Deleted `_similar_memory_exists()` duplicate checking
87+
- Removed `_retrieve_relevant_memories()` and `_augment_query_with_memories()` methods
88+
89+
3. **Simplified class interface:**
90+
- Updated `TravelAgent.__init__()` to remove strategy parameter
91+
- Simplified `_setup_llms()` to only include main conversation LLM
92+
- Streamlined `process_user_input()` to focus on core conversation flow
93+
- Updated `_generate_response()` to work with basic user input instead of augmented queries
94+
95+
4. **Cleaned up dependencies:**
96+
- Removed unused imports: `Enum`, `BaseModel`, filter classes, memory model classes
97+
- Simplified import structure to only include essential components
98+
- Removed command-line strategy argument from main function
99+
100+
**Rationale:**
101+
- Modern memory servers typically provide automatic conversation summarization when needed
102+
- Memory extraction, deduplication, and semantic retrieval are core memory server features
103+
- Simplifying the travel agent to focus on conversation flow while delegating memory management to the server
104+
- Reduces code complexity and maintenance burden while leveraging server capabilities
105+
106+
**Files Modified:**
107+
- `examples/travel_agent.py` (significantly simplified - removed ~200 lines of redundant code)
108+
109+
**Testing:**
110+
-`uv run mypy examples/travel_agent.py` - Success: no issues found
111+
- ✅ Travel agent imports and instantiates successfully after simplification
112+
113+
**Key Decisions:**
114+
- Prioritized simplicity and delegation to memory server over manual memory management
115+
- Maintained core conversation functionality while removing redundant features
116+
- Kept namespace management and multi-user support as these are application-specific concerns
117+
118+
#### [2025-06-13 17:30:00] Simplified client management to single client with explicit namespaces
119+
120+
**Issues Addressed:**
121+
1. **Overcomplicated client management:** Multiple clients per user was unnecessarily complex and resource-intensive
122+
2. **Inefficient resource usage:** One client per user consumed more memory and connections than needed
123+
3. **Complex lifecycle management:** Managing multiple client lifecycles was error-prone
124+
125+
**Key Simplifications:**
126+
127+
1. **Replaced per-user clients with single client:**
128+
- Changed from `self._memory_clients: dict[str, MemoryAPIClient]` to `self._memory_client: MemoryAPIClient | None`
129+
- Simplified `get_client()` method to return single client instance without user parameter
130+
- Removed user-specific client initialization and storage logic
131+
132+
2. **Explicit namespace management:**
133+
- Removed `default_namespace` from client configuration
134+
- Always pass namespace explicitly using `self._get_namespace(user_id)` in all operations
135+
- Maintained namespace isolation while using shared client
136+
137+
3. **Simplified cleanup:**
138+
- Changed from iterating over multiple clients to single client cleanup
139+
- Reduced cleanup complexity and potential for resource leaks
140+
141+
**Benefits:**
142+
- **Memory efficiency:** Single client instead of multiple per-user clients
143+
- **Connection pooling:** Better HTTP connection reuse across users
144+
- **Simpler lifecycle:** One client to initialize and cleanup
145+
- **Maintained isolation:** User namespaces still properly isolated via explicit namespace parameters
146+
- **Cleaner code:** Less complexity in client management logic
147+
148+
**Files Modified:**
149+
- `examples/travel_agent.py` (simplified client management)
150+
151+
**Testing:**
152+
-`uv run mypy examples/travel_agent.py` - Success: no issues found
153+
- ✅ Single-client travel agent imports and instantiates successfully
154+
155+
**Key Decisions:**
156+
- Prioritized efficiency and simplicity over perceived per-user client isolation
157+
- Maintained namespace-based user isolation through explicit parameters
158+
- Leveraged HTTP client connection pooling for better resource utilization
159+
160+
---
161+
162+
*This file serves as your working memory for this task. Keep it updated as you progress through the implementation.*

0 commit comments

Comments
 (0)