cowork-dash 0.1.5__py3-none-any.whl → 0.1.7__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.
cowork_dash/agent.py CHANGED
@@ -1,22 +1,23 @@
1
- import uuid
1
+ import os
2
+
2
3
  from deepagents import create_deep_agent
3
- from langgraph.checkpoint.memory import InMemorySaver
4
4
  from deepagents.backends import FilesystemBackend
5
+ from langgraph.checkpoint.memory import InMemorySaver
5
6
 
6
7
  from cowork_dash.tools import (
7
8
  add_to_canvas,
9
+ bash,
10
+ clear_notebook_canvas_items,
8
11
  create_cell,
9
- insert_cell,
10
- modify_cell,
11
12
  delete_cell,
12
- execute_cell,
13
13
  execute_all_cells,
14
+ execute_cell,
15
+ get_notebook_canvas_items,
14
16
  get_script,
15
17
  get_variables,
18
+ insert_cell,
19
+ modify_cell,
16
20
  reset_notebook,
17
- get_notebook_canvas_items,
18
- clear_notebook_canvas_items,
19
- bash,
20
21
  )
21
22
 
22
23
  SYSTEM_PROMPT = """You are a helpful AI assistant with access to a filesystem workspace and a Python code execution environment.
@@ -92,27 +93,70 @@ Work iteratively like a human using Jupyter:
92
93
 
93
94
  The workspace is your sandbox - feel free to create files, organize content, and help users manage their projects."""
94
95
 
95
- backend = FilesystemBackend(root_dir=str("/"), virtual_mode=True)
96
+ # Get workspace root from environment variable or default to current directory
97
+ workspace_root = os.getenv("DEEPAGENT_WORKSPACE_ROOT", os.getcwd())
98
+ backend = FilesystemBackend(root_dir=workspace_root, virtual_mode=True)
99
+
100
+ # Default tools list used by both global and session agents
101
+ AGENT_TOOLS = [
102
+ add_to_canvas,
103
+ bash,
104
+ create_cell,
105
+ insert_cell,
106
+ modify_cell,
107
+ delete_cell,
108
+ execute_cell,
109
+ execute_all_cells,
110
+ get_script,
111
+ get_variables,
112
+ reset_notebook,
113
+ get_notebook_canvas_items,
114
+ clear_notebook_canvas_items,
115
+ ]
96
116
 
117
+ # Global agent for physical filesystem mode
118
+ # This uses FilesystemBackend which writes to disk
97
119
  agent = create_deep_agent(
98
120
  system_prompt=SYSTEM_PROMPT,
99
121
  name="Cowork Dash",
100
122
  backend=backend,
101
- tools=[
102
- add_to_canvas,
103
- bash,
104
- create_cell,
105
- insert_cell,
106
- modify_cell,
107
- delete_cell,
108
- execute_cell,
109
- execute_all_cells,
110
- get_script,
111
- get_variables,
112
- reset_notebook,
113
- get_notebook_canvas_items,
114
- clear_notebook_canvas_items,
115
- ],
123
+ tools=AGENT_TOOLS,
116
124
  interrupt_on=dict(bash=True),
117
125
  checkpointer=InMemorySaver()
118
- )
126
+ )
127
+
128
+
129
+ def create_session_agent(session_id: str):
130
+ """Create an agent with session-specific VirtualFilesystem backend.
131
+
132
+ This factory function creates an agent that uses the VirtualFilesystem
133
+ for the given session, enabling isolated file storage between sessions.
134
+
135
+ Args:
136
+ session_id: The session ID to use for VirtualFilesystem lookup.
137
+
138
+ Returns:
139
+ A configured deep agent that uses VirtualFilesystemBackend.
140
+ """
141
+ from .backends import VirtualFilesystemBackend
142
+ from .virtual_fs import get_session_manager
143
+
144
+ # Get the VirtualFilesystem for this session
145
+ fs = get_session_manager().get_filesystem(session_id)
146
+ if fs is None:
147
+ # Session doesn't exist, create it
148
+ get_session_manager().create_session(session_id)
149
+ fs = get_session_manager().get_filesystem(session_id)
150
+
151
+ # Create backend wrapping the VirtualFilesystem
152
+ session_backend = VirtualFilesystemBackend(fs)
153
+
154
+ # Create and return the agent
155
+ return create_deep_agent(
156
+ system_prompt=SYSTEM_PROMPT,
157
+ name="Cowork Dash",
158
+ backend=session_backend,
159
+ tools=AGENT_TOOLS,
160
+ interrupt_on=dict(bash=True),
161
+ checkpointer=InMemorySaver()
162
+ )