cortexdb-agno 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cortexdb_agno/__init__.py +13 -0
- cortexdb_agno/memory.py +113 -0
- cortexdb_agno/tools.py +97 -0
- cortexdb_agno-0.1.0.dist-info/METADATA +47 -0
- cortexdb_agno-0.1.0.dist-info/RECORD +6 -0
- cortexdb_agno-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""CortexDB integration for Agno.
|
|
2
|
+
|
|
3
|
+
Provides a memory backend and agent tools that allow Agno agents
|
|
4
|
+
to use CortexDB as their long-term memory system.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from cortexdb_agno.memory import CortexDBMemory
|
|
8
|
+
from cortexdb_agno.tools import CortexDBTools
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"CortexDBMemory",
|
|
12
|
+
"CortexDBTools",
|
|
13
|
+
]
|
cortexdb_agno/memory.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Agno memory backend powered by CortexDB.
|
|
2
|
+
|
|
3
|
+
Provides a memory implementation compatible with Agno's memory system,
|
|
4
|
+
backed by CortexDB's long-term memory. This enables Agno agents to
|
|
5
|
+
persist and recall knowledge across sessions and conversations.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any, Optional
|
|
11
|
+
|
|
12
|
+
from cortexdb import Cortex
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CortexDBMemory:
|
|
16
|
+
"""Agno memory backend that stores and retrieves context via CortexDB.
|
|
17
|
+
|
|
18
|
+
Implements Agno's ``Memory`` interface backed by CortexDB's semantic
|
|
19
|
+
storage. This enables agents to share knowledge across sessions,
|
|
20
|
+
remember outcomes from previous runs, and build up persistent
|
|
21
|
+
context over time.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
client: An initialized CortexDB client instance.
|
|
25
|
+
scope: The hierarchical scope path for memory isolation.
|
|
26
|
+
|
|
27
|
+
Example::
|
|
28
|
+
|
|
29
|
+
from cortexdb import Cortex
|
|
30
|
+
from cortexdb_agno import CortexDBMemory
|
|
31
|
+
|
|
32
|
+
client = Cortex("http://localhost:3141")
|
|
33
|
+
memory = CortexDBMemory(client=client, scope="user:default")
|
|
34
|
+
|
|
35
|
+
# Store a memory
|
|
36
|
+
memory.add("The deployment window is 2-4am UTC on Tuesdays.")
|
|
37
|
+
|
|
38
|
+
# Search memories
|
|
39
|
+
results = memory.search("deployment schedule")
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
client: Cortex,
|
|
45
|
+
scope: str = "user:default",
|
|
46
|
+
) -> None:
|
|
47
|
+
"""Initialize CortexDBMemory with a CortexDB client.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
client: An initialized CortexDB client instance.
|
|
51
|
+
scope: The hierarchical scope path for memory isolation.
|
|
52
|
+
"""
|
|
53
|
+
self._client = client
|
|
54
|
+
self._scope = scope
|
|
55
|
+
|
|
56
|
+
def add(self, content: str, metadata: Optional[dict[str, Any]] = None) -> dict[str, Any]:
|
|
57
|
+
"""Store a memory in CortexDB.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
content: The text content to store.
|
|
61
|
+
metadata: Optional metadata to associate with the memory.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
The experience response dict from CortexDB.
|
|
65
|
+
"""
|
|
66
|
+
return self._client.experience(self._scope, text=content)
|
|
67
|
+
|
|
68
|
+
def search(self, query: str) -> dict[str, Any]:
|
|
69
|
+
"""Search for relevant memories in CortexDB.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
query: The search query string.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
A dict with a ``context`` key holding the recalled context block.
|
|
76
|
+
"""
|
|
77
|
+
result = self._client.recall(self._scope, query=query)
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
"context": result.get("context_block", "") if result else "",
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
def clear(self) -> dict[str, Any]:
|
|
84
|
+
"""Clear all memories for the current scope.
|
|
85
|
+
|
|
86
|
+
Issues a forget command to CortexDB to remove all stored memories.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
The forget response dict from CortexDB.
|
|
90
|
+
"""
|
|
91
|
+
return self._client.forget(
|
|
92
|
+
self._scope,
|
|
93
|
+
confirm_all=True,
|
|
94
|
+
cascade="redact_events",
|
|
95
|
+
reason="Agno memory clear requested",
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def get_context(self, query: str) -> str:
|
|
99
|
+
"""Retrieve formatted context for an agent prompt.
|
|
100
|
+
|
|
101
|
+
Convenience method that fetches relevant memories and formats them
|
|
102
|
+
as a single context string suitable for injection into an agent's
|
|
103
|
+
system prompt or message history.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
query: The query to find relevant context for.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
A formatted string of relevant memories.
|
|
110
|
+
"""
|
|
111
|
+
result = self._client.recall(self._scope, query=query)
|
|
112
|
+
|
|
113
|
+
return result.get("context_block", "") if result else ""
|
cortexdb_agno/tools.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Agno tools for interacting with CortexDB.
|
|
2
|
+
|
|
3
|
+
Provides a toolkit of tools that Agno agents can use to store, search,
|
|
4
|
+
and forget memories in CortexDB's long-term memory system.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from agno.tools import Toolkit
|
|
12
|
+
|
|
13
|
+
from cortexdb import Cortex
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CortexDBTools(Toolkit):
|
|
17
|
+
"""Toolkit that creates Agno-compatible tools for CortexDB operations.
|
|
18
|
+
|
|
19
|
+
Provides search, store, and forget tools that can be passed directly
|
|
20
|
+
to an Agno ``Agent``.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
client: An initialized CortexDB client instance.
|
|
24
|
+
scope: The hierarchical scope path for memory isolation.
|
|
25
|
+
|
|
26
|
+
Example::
|
|
27
|
+
|
|
28
|
+
from agno.agent import Agent
|
|
29
|
+
from cortexdb import Cortex
|
|
30
|
+
from cortexdb_agno import CortexDBTools
|
|
31
|
+
|
|
32
|
+
client = Cortex("https://api-v1.cortexdb.ai", actor="user:app", bearer="v4.public...")
|
|
33
|
+
toolkit = CortexDBTools(client=client, scope="user:default")
|
|
34
|
+
|
|
35
|
+
agent = Agent(
|
|
36
|
+
name="Research Assistant",
|
|
37
|
+
tools=[toolkit],
|
|
38
|
+
)
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
client: Cortex,
|
|
44
|
+
scope: str = "user:default",
|
|
45
|
+
) -> None:
|
|
46
|
+
super().__init__(name="cortexdb")
|
|
47
|
+
self._client = client
|
|
48
|
+
self._scope = scope
|
|
49
|
+
self.register(self.search_memory)
|
|
50
|
+
self.register(self.store_memory)
|
|
51
|
+
self.register(self.forget_memory)
|
|
52
|
+
|
|
53
|
+
def search_memory(self, query: str) -> str:
|
|
54
|
+
"""Search CortexDB for relevant memories and past context.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
query: A natural language query describing what to search for.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
The retrieved context string from CortexDB.
|
|
61
|
+
"""
|
|
62
|
+
result = self._client.recall(self._scope, query=query)
|
|
63
|
+
|
|
64
|
+
context = result.get("context_block", "") if result else ""
|
|
65
|
+
if not context:
|
|
66
|
+
return "No relevant memories found in CortexDB."
|
|
67
|
+
|
|
68
|
+
return context
|
|
69
|
+
|
|
70
|
+
def store_memory(self, content: str) -> str:
|
|
71
|
+
"""Store information in CortexDB's long-term memory.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
content: The information to store as a memory.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
A confirmation message.
|
|
78
|
+
"""
|
|
79
|
+
self._client.experience(self._scope, text=content)
|
|
80
|
+
return "Memory stored successfully in CortexDB."
|
|
81
|
+
|
|
82
|
+
def forget_memory(self, reason: str) -> str:
|
|
83
|
+
"""Forget all memories in this scope from CortexDB.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
reason: The reason for forgetting these memories.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
A confirmation message.
|
|
90
|
+
"""
|
|
91
|
+
self._client.forget(
|
|
92
|
+
self._scope,
|
|
93
|
+
confirm_all=True,
|
|
94
|
+
cascade="redact_events",
|
|
95
|
+
reason=reason,
|
|
96
|
+
)
|
|
97
|
+
return f"Memories in scope '{self._scope}' have been forgotten."
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cortexdb-agno
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Agno integration for CortexDB — long-term memory for AI systems
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: agno>=1.0
|
|
8
|
+
Requires-Dist: cortexdbai>=0.1.0
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
|
|
11
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# cortexdb-agno
|
|
15
|
+
|
|
16
|
+
Agno integration for CortexDB long-term memory.
|
|
17
|
+
|
|
18
|
+
> **LLM provider note (audit BLK-2):** the canonical example uses
|
|
19
|
+
> `from agno.models.openai import OpenAIChat`. CortexDB itself is
|
|
20
|
+
> LLM-agnostic — Agno picks the model. Swap providers with one line:
|
|
21
|
+
>
|
|
22
|
+
> ```python
|
|
23
|
+
> # OpenAI (default in the docs)
|
|
24
|
+
> from agno.models.openai import OpenAIChat
|
|
25
|
+
> model = OpenAIChat(id="gpt-4o")
|
|
26
|
+
>
|
|
27
|
+
> # Anthropic
|
|
28
|
+
> from agno.models.anthropic import Claude
|
|
29
|
+
> model = Claude(id="claude-sonnet-4-6")
|
|
30
|
+
>
|
|
31
|
+
> # Google
|
|
32
|
+
> from agno.models.google import Gemini
|
|
33
|
+
> model = Gemini(id="gemini-1.5-pro")
|
|
34
|
+
> ```
|
|
35
|
+
>
|
|
36
|
+
> Nothing in `cortexdb-agno` reads `OPENAI_API_KEY`.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install cortexdb-agno
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API base URL
|
|
45
|
+
|
|
46
|
+
Defaults to `https://api-v1.cortexdb.ai` (audit FRI-8). Override with
|
|
47
|
+
`CORTEXDB_API_URL`.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
cortexdb_agno/__init__.py,sha256=gZHmpM3LLApbwR4ahPNqa1CWNbMoEZkeJ-Jt-OPfhp8,320
|
|
2
|
+
cortexdb_agno/memory.py,sha256=yWHxDKfD5FpFyTU2KtknO7u5TyBB-TsGORqOfVryMb8,3598
|
|
3
|
+
cortexdb_agno/tools.py,sha256=cIr724gb8OV9SGKpy6pStktk2A-JS6nxGns5mWFJH08,2868
|
|
4
|
+
cortexdb_agno-0.1.0.dist-info/METADATA,sha256=HY9qYQw7gYFbT-mUfalJOnww8ulwXoaKXMqHyoEmbx0,1206
|
|
5
|
+
cortexdb_agno-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
6
|
+
cortexdb_agno-0.1.0.dist-info/RECORD,,
|