cowork-dash 0.1.6__py3-none-any.whl → 0.1.8__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,23 +1,23 @@
1
1
  import os
2
- import uuid
2
+
3
3
  from deepagents import create_deep_agent
4
- from langgraph.checkpoint.memory import InMemorySaver
5
4
  from deepagents.backends import FilesystemBackend
5
+ from langgraph.checkpoint.memory import InMemorySaver
6
6
 
7
7
  from cowork_dash.tools import (
8
8
  add_to_canvas,
9
+ bash,
10
+ clear_notebook_canvas_items,
9
11
  create_cell,
10
- insert_cell,
11
- modify_cell,
12
12
  delete_cell,
13
- execute_cell,
14
13
  execute_all_cells,
14
+ execute_cell,
15
+ get_notebook_canvas_items,
15
16
  get_script,
16
17
  get_variables,
18
+ insert_cell,
19
+ modify_cell,
17
20
  reset_notebook,
18
- get_notebook_canvas_items,
19
- clear_notebook_canvas_items,
20
- bash,
21
21
  )
22
22
 
23
23
  SYSTEM_PROMPT = """You are a helpful AI assistant with access to a filesystem workspace and a Python code execution environment.
@@ -97,25 +97,66 @@ The workspace is your sandbox - feel free to create files, organize content, and
97
97
  workspace_root = os.getenv("DEEPAGENT_WORKSPACE_ROOT", os.getcwd())
98
98
  backend = FilesystemBackend(root_dir=workspace_root, virtual_mode=True)
99
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
+ ]
116
+
117
+ # Global agent for physical filesystem mode
118
+ # This uses FilesystemBackend which writes to disk
100
119
  agent = create_deep_agent(
101
120
  system_prompt=SYSTEM_PROMPT,
102
121
  name="Cowork Dash",
103
122
  backend=backend,
104
- tools=[
105
- add_to_canvas,
106
- bash,
107
- create_cell,
108
- insert_cell,
109
- modify_cell,
110
- delete_cell,
111
- execute_cell,
112
- execute_all_cells,
113
- get_script,
114
- get_variables,
115
- reset_notebook,
116
- get_notebook_canvas_items,
117
- clear_notebook_canvas_items,
118
- ],
123
+ tools=AGENT_TOOLS,
119
124
  interrupt_on=dict(bash=True),
120
125
  checkpointer=InMemorySaver()
121
- )
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
+ )