deepagents-cli 0.0.6__tar.gz → 0.0.7__tar.gz
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.
Potentially problematic release.
This version of deepagents-cli might be problematic. Click here for more details.
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/PKG-INFO +2 -2
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/agent.py +1 -1
- deepagents_cli-0.0.7/deepagents_cli/agent_memory.py +222 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/config.py +1 -1
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/token_utils.py +1 -1
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli.egg-info/PKG-INFO +2 -2
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli.egg-info/SOURCES.txt +1 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli.egg-info/requires.txt +1 -1
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/pyproject.toml +2 -2
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/README.md +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/__init__.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/__main__.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/cli.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/commands.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/default_agent_prompt.md +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/execution.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/file_ops.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/input.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/main.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/py.typed +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/tools.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli/ui.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli.egg-info/dependency_links.txt +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli.egg-info/entry_points.txt +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/deepagents_cli.egg-info/top_level.txt +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/setup.cfg +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/tests/test_file_ops.py +0 -0
- {deepagents_cli-0.0.6 → deepagents_cli-0.0.7}/tests/test_placeholder.py +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: deepagents-cli
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Deepagents CLI
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: <4.0,>=3.11
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
|
-
Requires-Dist: deepagents==0.2.
|
|
8
|
+
Requires-Dist: deepagents==0.2.4
|
|
9
9
|
Requires-Dist: requests
|
|
10
10
|
Requires-Dist: rich>=13.0.0
|
|
11
11
|
Requires-Dist: prompt-toolkit>=3.0.52
|
|
@@ -7,11 +7,11 @@ from pathlib import Path
|
|
|
7
7
|
from deepagents import create_deep_agent
|
|
8
8
|
from deepagents.backends import CompositeBackend
|
|
9
9
|
from deepagents.backends.filesystem import FilesystemBackend
|
|
10
|
-
from deepagents.middleware.agent_memory import AgentMemoryMiddleware
|
|
11
10
|
from deepagents.middleware.resumable_shell import ResumableShellToolMiddleware
|
|
12
11
|
from langchain.agents.middleware import HostExecutionPolicy
|
|
13
12
|
from langgraph.checkpoint.memory import InMemorySaver
|
|
14
13
|
|
|
14
|
+
from .agent_memory import AgentMemoryMiddleware
|
|
15
15
|
from .config import COLORS, config, console, get_default_coding_instructions
|
|
16
16
|
|
|
17
17
|
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"""Middleware for loading agent-specific long-term memory into the system prompt."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Awaitable, Callable
|
|
4
|
+
from typing import TYPE_CHECKING, Any
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from langgraph.runtime import Runtime
|
|
8
|
+
|
|
9
|
+
from langchain.agents.middleware.types import (
|
|
10
|
+
AgentMiddleware,
|
|
11
|
+
AgentState,
|
|
12
|
+
ModelRequest,
|
|
13
|
+
ModelResponse,
|
|
14
|
+
)
|
|
15
|
+
from typing_extensions import NotRequired, TypedDict
|
|
16
|
+
|
|
17
|
+
from deepagents.backends.protocol import BackendProtocol
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AgentMemoryState(AgentState):
|
|
21
|
+
"""State for the agent memory middleware."""
|
|
22
|
+
|
|
23
|
+
agent_memory: NotRequired[str | None]
|
|
24
|
+
"""Long-term memory content for the agent."""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
AGENT_MEMORY_FILE_PATH = "/agent.md"
|
|
28
|
+
|
|
29
|
+
# Long-term Memory Documentation
|
|
30
|
+
LONGTERM_MEMORY_SYSTEM_PROMPT = """
|
|
31
|
+
|
|
32
|
+
## Long-term Memory
|
|
33
|
+
|
|
34
|
+
You have access to a long-term memory system using the {memory_path} path prefix.
|
|
35
|
+
Files stored in {memory_path} persist across sessions and conversations.
|
|
36
|
+
|
|
37
|
+
Your system prompt is loaded from {memory_path}agent.md at startup. You can update your own instructions by editing this file.
|
|
38
|
+
|
|
39
|
+
**When to CHECK/READ memories (CRITICAL - do this FIRST):**
|
|
40
|
+
- **At the start of ANY new session**: Run `ls {memory_path}` to see what you know
|
|
41
|
+
- **BEFORE answering questions**: If asked "what do you know about X?" or "how do I do Y?", check `ls {memory_path}` for relevant files FIRST
|
|
42
|
+
- **When user asks you to do something**: Check if you have guides, examples, or patterns in {memory_path} before proceeding
|
|
43
|
+
- **When user references past work or conversations**: Search {memory_path} for related content
|
|
44
|
+
- **If you're unsure**: Check your memories rather than guessing or using only general knowledge
|
|
45
|
+
|
|
46
|
+
**Memory-first response pattern:**
|
|
47
|
+
1. User asks a question → Run `ls {memory_path}` to check for relevant files
|
|
48
|
+
2. If relevant files exist → Read them with `read_file {memory_path}[filename]`
|
|
49
|
+
3. Base your answer on saved knowledge (from memories) supplemented by general knowledge
|
|
50
|
+
4. If no relevant memories exist → Use general knowledge, then consider if this is worth saving
|
|
51
|
+
|
|
52
|
+
**When to update memories:**
|
|
53
|
+
- **IMMEDIATELY when the user describes your role or how you should behave** (e.g., "you are a web researcher", "you are an expert in X")
|
|
54
|
+
- **IMMEDIATELY when the user gives feedback on your work** - Before continuing, update memories to capture what was wrong and how to do it better
|
|
55
|
+
- When the user explicitly asks you to remember something
|
|
56
|
+
- When patterns or preferences emerge (coding styles, conventions, workflows)
|
|
57
|
+
- After significant work where context would help in future sessions
|
|
58
|
+
|
|
59
|
+
**Learning from feedback:**
|
|
60
|
+
- When user says something is better/worse, capture WHY and encode it as a pattern
|
|
61
|
+
- Each correction is a chance to improve permanently - don't just fix the immediate issue, update your instructions
|
|
62
|
+
- When user says "you should remember X" or "be careful about Y", treat this as HIGH PRIORITY - update memories IMMEDIATELY
|
|
63
|
+
- Look for the underlying principle behind corrections, not just the specific mistake
|
|
64
|
+
- If it's something you "should have remembered", identify where that instruction should live permanently
|
|
65
|
+
|
|
66
|
+
**What to store where:**
|
|
67
|
+
- **{memory_path}agent.md**: Update this to modify your core instructions and behavioral patterns
|
|
68
|
+
- **Other {memory_path} files**: Use for project-specific context, reference information, or structured notes
|
|
69
|
+
- If you create additional memory files, add references to them in {memory_path}agent.md so you remember to consult them
|
|
70
|
+
|
|
71
|
+
The portion of your system prompt that comes from {memory_path}agent.md is marked with `<agent_memory>` tags so you can identify what instructions come from your persistent memory.
|
|
72
|
+
|
|
73
|
+
Example: `ls {memory_path}` to see what memories you have
|
|
74
|
+
Example: `read_file '{memory_path}deep-agents-guide.md'` to recall saved knowledge
|
|
75
|
+
Example: `edit_file('{memory_path}agent.md', ...)` to update your instructions
|
|
76
|
+
Example: `write_file('{memory_path}project_context.md', ...)` for project-specific notes, then reference it in agent.md
|
|
77
|
+
|
|
78
|
+
Remember: To interact with the longterm filesystem, you must prefix the filename with the {memory_path} path."""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
DEFAULT_MEMORY_SNIPPET = """<agent_memory>
|
|
82
|
+
{agent_memory}
|
|
83
|
+
</agent_memory>
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
class AgentMemoryMiddleware(AgentMiddleware):
|
|
87
|
+
"""Middleware for loading agent-specific long-term memory.
|
|
88
|
+
|
|
89
|
+
This middleware loads the agent's long-term memory from a file (agent.md)
|
|
90
|
+
and injects it into the system prompt. The memory is loaded once at the
|
|
91
|
+
start of the conversation and stored in state.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
backend: Backend to use for loading the agent memory file.
|
|
95
|
+
system_prompt_template: Optional custom template for how to inject
|
|
96
|
+
the agent memory into the system prompt. Use {agent_memory} as
|
|
97
|
+
a placeholder. Defaults to a simple section header.
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
```python
|
|
101
|
+
from deepagents.middleware.agent_memory import AgentMemoryMiddleware
|
|
102
|
+
from deepagents.memory.backends import FilesystemBackend
|
|
103
|
+
from pathlib import Path
|
|
104
|
+
|
|
105
|
+
# Set up backend pointing to agent's directory
|
|
106
|
+
agent_dir = Path.home() / ".deepagents" / "my-agent"
|
|
107
|
+
backend = FilesystemBackend(root_dir=agent_dir)
|
|
108
|
+
|
|
109
|
+
# Create middleware
|
|
110
|
+
middleware = AgentMemoryMiddleware(backend=backend)
|
|
111
|
+
```
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
state_schema = AgentMemoryState
|
|
115
|
+
|
|
116
|
+
def __init__(
|
|
117
|
+
self,
|
|
118
|
+
*,
|
|
119
|
+
backend: BackendProtocol,
|
|
120
|
+
memory_path: str,
|
|
121
|
+
system_prompt_template: str | None = None,
|
|
122
|
+
) -> None:
|
|
123
|
+
"""Initialize the agent memory middleware.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
backend: Backend to use for loading the agent memory file.
|
|
127
|
+
system_prompt_template: Optional custom template for injecting
|
|
128
|
+
agent memory into system prompt.
|
|
129
|
+
"""
|
|
130
|
+
self.backend = backend
|
|
131
|
+
self.memory_path = memory_path
|
|
132
|
+
self.system_prompt_template = system_prompt_template or DEFAULT_MEMORY_SNIPPET
|
|
133
|
+
|
|
134
|
+
def before_agent(
|
|
135
|
+
self,
|
|
136
|
+
state: AgentMemoryState,
|
|
137
|
+
runtime,
|
|
138
|
+
) -> AgentMemoryState:
|
|
139
|
+
"""Load agent memory from file before agent execution.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
state: Current agent state.
|
|
143
|
+
handler: Handler function to call after loading memory.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
Updated state with agent_memory populated.
|
|
147
|
+
"""
|
|
148
|
+
# Only load memory if it hasn't been loaded yet
|
|
149
|
+
if "agent_memory" not in state or state.get("agent_memory") is None:
|
|
150
|
+
file_data = self.backend.read(AGENT_MEMORY_FILE_PATH)
|
|
151
|
+
return {"agent_memory": file_data}
|
|
152
|
+
|
|
153
|
+
async def abefore_agent(
|
|
154
|
+
self,
|
|
155
|
+
state: AgentMemoryState,
|
|
156
|
+
runtime,
|
|
157
|
+
) -> AgentMemoryState:
|
|
158
|
+
"""(async) Load agent memory from file before agent execution.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
state: Current agent state.
|
|
162
|
+
handler: Handler function to call after loading memory.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
Updated state with agent_memory populated.
|
|
166
|
+
"""
|
|
167
|
+
# Only load memory if it hasn't been loaded yet
|
|
168
|
+
if "agent_memory" not in state or state.get("agent_memory") is None:
|
|
169
|
+
file_data = self.backend.read(AGENT_MEMORY_FILE_PATH)
|
|
170
|
+
return {"agent_memory": file_data}
|
|
171
|
+
|
|
172
|
+
def wrap_model_call(
|
|
173
|
+
self,
|
|
174
|
+
request: ModelRequest,
|
|
175
|
+
handler: Callable[[ModelRequest], ModelResponse],
|
|
176
|
+
) -> ModelResponse:
|
|
177
|
+
"""Inject agent memory into the system prompt.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
request: The model request being processed.
|
|
181
|
+
handler: The handler function to call with the modified request.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
The model response from the handler.
|
|
185
|
+
"""
|
|
186
|
+
# Get agent memory from state
|
|
187
|
+
agent_memory = request.state.get("agent_memory", "")
|
|
188
|
+
|
|
189
|
+
memory_section = self.system_prompt_template.format(agent_memory=agent_memory)
|
|
190
|
+
if request.system_prompt:
|
|
191
|
+
request.system_prompt = memory_section + "\n\n" + request.system_prompt
|
|
192
|
+
else:
|
|
193
|
+
request.system_prompt = memory_section
|
|
194
|
+
request.system_prompt = request.system_prompt + "\n\n" + LONGTERM_MEMORY_SYSTEM_PROMPT.format(memory_path=self.memory_path)
|
|
195
|
+
|
|
196
|
+
return handler(request)
|
|
197
|
+
|
|
198
|
+
async def awrap_model_call(
|
|
199
|
+
self,
|
|
200
|
+
request: ModelRequest,
|
|
201
|
+
handler: Callable[[ModelRequest], Awaitable[ModelResponse]],
|
|
202
|
+
) -> ModelResponse:
|
|
203
|
+
"""(async) Inject agent memory into the system prompt.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
request: The model request being processed.
|
|
207
|
+
handler: The handler function to call with the modified request.
|
|
208
|
+
|
|
209
|
+
Returns:
|
|
210
|
+
The model response from the handler.
|
|
211
|
+
"""
|
|
212
|
+
# Get agent memory from state
|
|
213
|
+
agent_memory = request.state.get("agent_memory", "")
|
|
214
|
+
|
|
215
|
+
memory_section = self.system_prompt_template.format(agent_memory=agent_memory)
|
|
216
|
+
if request.system_prompt:
|
|
217
|
+
request.system_prompt = memory_section + "\n\n" + request.system_prompt
|
|
218
|
+
else:
|
|
219
|
+
request.system_prompt = memory_section
|
|
220
|
+
request.system_prompt = request.system_prompt + "\n\n" + LONGTERM_MEMORY_SYSTEM_PROMPT.format(memory_path=self.memory_path)
|
|
221
|
+
|
|
222
|
+
return await handler(request)
|
|
@@ -94,7 +94,7 @@ def get_default_coding_instructions() -> str:
|
|
|
94
94
|
These are the immutable base instructions that cannot be modified by the agent.
|
|
95
95
|
Long-term memory (agent.md) is handled separately by the middleware.
|
|
96
96
|
"""
|
|
97
|
-
default_prompt_path = Path(__file__).parent
|
|
97
|
+
default_prompt_path = Path(__file__).parent / "default_agent_prompt.md"
|
|
98
98
|
return default_prompt_path.read_text()
|
|
99
99
|
|
|
100
100
|
|
|
@@ -58,6 +58,6 @@ def calculate_baseline_tokens(model, agent_dir: Path, system_prompt: str) -> int
|
|
|
58
58
|
def get_memory_system_prompt() -> str:
|
|
59
59
|
"""Get the long-term memory system prompt text."""
|
|
60
60
|
# Import from agent_memory middleware
|
|
61
|
-
from
|
|
61
|
+
from .agent_memory import LONGTERM_MEMORY_SYSTEM_PROMPT
|
|
62
62
|
|
|
63
63
|
return LONGTERM_MEMORY_SYSTEM_PROMPT.format(memory_path="/memories/")
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: deepagents-cli
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Deepagents CLI
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: <4.0,>=3.11
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
|
-
Requires-Dist: deepagents==0.2.
|
|
8
|
+
Requires-Dist: deepagents==0.2.4
|
|
9
9
|
Requires-Dist: requests
|
|
10
10
|
Requires-Dist: rich>=13.0.0
|
|
11
11
|
Requires-Dist: prompt-toolkit>=3.0.52
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "deepagents-cli"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.7"
|
|
4
4
|
description = "Deepagents CLI"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = { text = "MIT" }
|
|
7
7
|
requires-python = ">=3.11,<4.0"
|
|
8
8
|
dependencies = [
|
|
9
|
-
"deepagents==0.2.
|
|
9
|
+
"deepagents==0.2.4",
|
|
10
10
|
"requests",
|
|
11
11
|
"rich>=13.0.0",
|
|
12
12
|
"prompt-toolkit>=3.0.52",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|