Skip to content

Commit 7459252

Browse files
working
1 parent be3ed2a commit 7459252

File tree

7 files changed

+22
-151
lines changed

7 files changed

+22
-151
lines changed

README.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Build your AI agents in three lines of code!
7171
* [Python](https://python.org) - Programming Language
7272
* [OpenAI](https://openai.com) - AI Model Provider
7373
* [MongoDB](https://mongodb.com) - Conversational History (optional)
74-
* [Zep Cloud](https://getzep.com) - Conversational Memory (optional)
7574
* [Pinecone](https://pinecone.io) - Knowledge Base (optional)
7675
* [AgentiPy](https://agentipy.fun) - Solana Ecosystem (optional)
7776
* [Zapier](https://zapier.com) - App Integrations (optional)
@@ -377,16 +376,6 @@ config = {
377376
}
378377
```
379378

380-
### Conversational Memory
381-
382-
```python
383-
config = {
384-
"zep": {
385-
"api_key": "your-zep-cloud-api-key",
386-
},
387-
}
388-
```
389-
390379
### Observability and Tracing
391380

392381
```python
@@ -421,16 +410,15 @@ config = {
421410
}
422411
```
423412

424-
### Knowledge Base
425-
426-
The Knowledge Base (KB) is meant to store text values and/or PDFs (extracts text) - can handle very large PDFs.
413+
### Knowledge Base & Conversational Memory
427414

428415
```python
429416
config = {
430417
"knowledge_base": {
431418
"pinecone": {
432419
"api_key": "your-pinecone-api-key",
433420
"index_name": "your-pinecone-index-name",
421+
"use_reranking": True # optional - but increases better matching - requires Pinecone Standard
434422
}
435423
},
436424
"mongo": {

docs/index.rst

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,6 @@ Conversational History - Optional
310310
},
311311
}
312312
313-
Conversational Memory - Optional
314-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
315-
316-
.. code-block:: python
317-
318-
config = {
319-
"zep": {
320-
"api_key": "your-zep-api-key",
321-
},
322-
}
323-
324313
Observability and Tracing - Optional
325314
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
326315

@@ -361,7 +350,7 @@ Gemini - Optional
361350
}
362351
363352
364-
Knowledge Base - Optional
353+
Knowledge Base & Conversational Memory - Optional
365354
~~~~~~~~~~~~~~~~~~~~~~~~~~~
366355

367356
The Knowledge Base (KB) is meant to store text values and/or small PDFs.

poetry.lock

Lines changed: 1 addition & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "solana-agent"
3-
version = "29.2.0-dev80"
3+
version = "30.0.0"
44
description = "AI Agents for Solana"
55
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
66
license = "MIT"
@@ -27,7 +27,6 @@ python = ">=3.12,<4.0"
2727
openai = "1.79.0"
2828
pydantic = ">=2"
2929
pymongo = "4.13.0"
30-
zep-cloud = "2.12.3"
3130
instructor = "1.8.2"
3231
pinecone = "6.0.2"
3332
llama-index-core = "0.12.37"

solana_agent/factories/agent_factory.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,9 @@ def create_from_config(config: Dict[str, Any]) -> QueryService:
136136
)
137137

138138
# Create repositories
139-
memory_provider = None
140-
141-
if "zep" in config and "mongo" in config:
142-
memory_provider = MemoryRepository(
143-
mongo_adapter=db_adapter, zep_api_key=config["zep"].get("api_key")
144-
)
145-
146-
if "mongo" in config and "zep" not in config:
147-
memory_provider = MemoryRepository(mongo_adapter=db_adapter)
148-
149-
if "zep" in config and "mongo" not in config:
150-
if "api_key" not in config["zep"]:
151-
raise ValueError("Zep API key is required.")
152-
memory_provider = MemoryRepository(zep_api_key=config["zep"].get("api_key"))
139+
memory_provider = MemoryRepository(mongo_adapter=db_adapter)
153140

141+
# Create guardrails
154142
guardrail_config = config.get("guardrails", {})
155143
input_guardrails: List[InputGuardrail] = SolanaAgentFactory._create_guardrails(
156144
guardrail_config.get("input", [])

solana_agent/repositories/memory.py

Lines changed: 15 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import logging # Import logging
2-
from copy import deepcopy
32
from typing import List, Dict, Any, Optional, Tuple
43
from datetime import datetime, timezone
5-
from zep_cloud.client import AsyncZep as AsyncZepCloud
6-
from zep_cloud.types import Message
74
from solana_agent.interfaces.providers.memory import MemoryProvider
85
from solana_agent.adapters.mongodb_adapter import MongoDBAdapter
96

@@ -12,12 +9,11 @@
129

1310

1411
class MemoryRepository(MemoryProvider):
15-
"""Combined Zep and MongoDB implementation of MemoryProvider."""
12+
"""MongoDB implementation of MemoryProvider."""
1613

1714
def __init__(
1815
self,
1916
mongo_adapter: Optional[MongoDBAdapter] = None,
20-
zep_api_key: Optional[str] = None,
2117
):
2218
"""Initialize the combined memory provider."""
2319
if not mongo_adapter:
@@ -36,13 +32,8 @@ def __init__(
3632
except Exception as e:
3733
logger.error(f"Error initializing MongoDB: {e}") # Use logger.error
3834

39-
self.zep = None
40-
# Initialize Zep
41-
if zep_api_key:
42-
self.zep = AsyncZepCloud(api_key=zep_api_key)
43-
4435
async def store(self, user_id: str, messages: List[Dict[str, Any]]) -> None:
45-
"""Store messages in both Zep and MongoDB."""
36+
"""Store messages in MongoDB."""
4637
if not user_id:
4738
raise ValueError("User ID cannot be None or empty")
4839
if not messages or not isinstance(messages, list):
@@ -86,56 +77,22 @@ async def store(self, user_id: str, messages: List[Dict[str, Any]]) -> None:
8677
except Exception as e:
8778
logger.error(f"MongoDB storage error: {e}") # Use logger.error
8879

89-
# Store in Zep
90-
if not self.zep:
91-
return
92-
93-
# Convert messages to Zep format
94-
zep_messages = []
95-
for msg in messages:
96-
if "role" in msg and "content" in msg:
97-
content = self._truncate(deepcopy(msg["content"]))
98-
zep_msg = Message(
99-
role=msg["role"],
100-
content=content,
101-
role_type=msg["role"],
102-
)
103-
zep_messages.append(zep_msg)
104-
105-
# Add messages to Zep memory
106-
if zep_messages:
107-
try:
108-
await self.zep.memory.add(session_id=user_id, messages=zep_messages)
109-
except Exception:
110-
try:
111-
try:
112-
await self.zep.user.add(user_id=user_id)
113-
except Exception as e:
114-
logger.error(
115-
f"Zep user addition error: {e}"
116-
) # Use logger.error
117-
118-
try:
119-
await self.zep.memory.add_session(
120-
session_id=user_id, user_id=user_id
121-
)
122-
except Exception as e:
123-
logger.error(
124-
f"Zep session creation error: {e}"
125-
) # Use logger.error
126-
await self.zep.memory.add(session_id=user_id, messages=zep_messages)
127-
except Exception as e:
128-
logger.error(f"Zep memory addition error: {e}") # Use logger.error
129-
return
130-
13180
async def retrieve(self, user_id: str) -> str:
132-
"""Retrieve memory context from Zep only."""
81+
"""Retrieve memory context from MongoDB."""
13382
try:
13483
memories = ""
135-
if self.zep:
136-
memory = await self.zep.memory.get(session_id=user_id)
137-
if memory and memory.context:
138-
memories = memory.context
84+
if self.mongo:
85+
query = {"user_id": user_id}
86+
sort = [("timestamp", -1)]
87+
limit = 3
88+
skip = 0
89+
results = self.mongo.find(
90+
self.collection, query, sort=sort, limit=limit, skip=skip
91+
)
92+
if results:
93+
for result in results:
94+
memories += f"User: {result.get('user_message')}\n"
95+
memories += f"Assistant: {result.get('assistant_message')}\n"
13996
return memories
14097

14198
except Exception as e:
@@ -150,19 +107,6 @@ async def delete(self, user_id: str) -> None:
150107
except Exception as e:
151108
logger.error(f"MongoDB deletion error: {e}") # Use logger.error
152109

153-
if not self.zep:
154-
return
155-
156-
try:
157-
await self.zep.memory.delete(session_id=user_id)
158-
except Exception as e:
159-
logger.error(f"Zep memory deletion error: {e}") # Use logger.error
160-
161-
try:
162-
await self.zep.user.delete(user_id=user_id)
163-
except Exception as e:
164-
logger.error(f"Zep user deletion error: {e}") # Use logger.error
165-
166110
def find(
167111
self,
168112
collection: str,
@@ -186,22 +130,3 @@ def count_documents(self, collection: str, query: Dict) -> int:
186130
if not self.mongo:
187131
return 0
188132
return self.mongo.count_documents(collection, query)
189-
190-
def _truncate(self, text: str, limit: int = 2500) -> str:
191-
"""Truncate text to be within limits."""
192-
if text is None:
193-
raise AttributeError("Cannot truncate None text")
194-
195-
if not text:
196-
return ""
197-
198-
if len(text) <= limit:
199-
return text
200-
201-
# Try to truncate at last period before limit
202-
last_period = text.rfind(".", 0, limit)
203-
if last_period > 0:
204-
return text[: last_period + 1]
205-
206-
# If no period found, truncate at limit and add ellipsis
207-
return text[: limit - 3] + "..."

solana_agent/services/graph_memory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ async def search(
7878
# Only return nodes that match user_id
7979
nodes = []
8080
for nid in node_ids:
81-
print(f"Node ID: {nid}")
8281
node = await self.graph.get_node(nid)
8382
if node and node.get("user_id") == user_id:
8483
nodes.append(node)

0 commit comments

Comments
 (0)