Skip to content

Commit 7defe36

Browse files
committed
x
1 parent fdeab91 commit 7defe36

File tree

1 file changed

+104
-83
lines changed

1 file changed

+104
-83
lines changed

agent_with_runloop_backend.ipynb

Lines changed: 104 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,57 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 1,
23+
"execution_count": 2,
2424
"id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
2525
"metadata": {},
2626
"outputs": [],
2727
"source": [
2828
"import os\n",
2929
"from runloop_api_client import Runloop\n",
3030
"from deepagents.graph import create_deep_agent\n",
31-
"from deepagents.integrations.runloop import RunloopProvider"
31+
"from deepagents.integrations.runloop import RunloopBackend"
3232
]
3333
},
3434
{
35-
"cell_type": "markdown",
36-
"id": "d4e5f6a7-b8c9-0123-def1-234567890123",
35+
"cell_type": "code",
36+
"execution_count": 3,
37+
"id": "22f0b297-52c9-45b0-a96d-95063f08ae4a",
3738
"metadata": {},
39+
"outputs": [
40+
{
41+
"name": "stdout",
42+
"output_type": "stream",
43+
"text": [
44+
"dbx_31Wy37EKz7tur7WyBxD0L\n"
45+
]
46+
}
47+
],
3848
"source": [
39-
"## Option 1: Using RunloopProvider (Recommended)\n",
49+
"import os\n",
50+
"\n",
51+
"from runloop_api_client import Runloop\n",
4052
"\n",
41-
"The `RunloopProvider` will automatically create a devbox when the agent is initialized."
53+
"client = Runloop(\n",
54+
" bearer_token=os.environ.get(\"RUNLOOP_API_KEY\"), # This is the default and can be omitted\n",
55+
")\n",
56+
"\n",
57+
"devbox_view = client.devboxes.create()\n",
58+
"print(devbox_view.id)"
4259
]
4360
},
4461
{
4562
"cell_type": "code",
46-
"execution_count": 2,
63+
"execution_count": 4,
64+
"id": "40135f20-a1ad-45f9-9475-79669d4e05c5",
65+
"metadata": {},
66+
"outputs": [],
67+
"source": [
68+
"backend = RunloopBackend(devbox_id=devbox_view.id, client=client)"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 5,
4774
"id": "e5f6a7b8-c9d0-1234-ef12-345678901234",
4875
"metadata": {},
4976
"outputs": [
@@ -56,25 +83,6 @@
5683
}
5784
],
5885
"source": [
59-
"# Create the Runloop provider with optional devbox creation parameters\n",
60-
"provider = RunloopProvider(\n",
61-
" api_key=os.environ.get(\"RUNLOOP_API_KEY\"),\n",
62-
" create_params={\n",
63-
" # Optional: Add code mounts, environment variables, etc.\n",
64-
" # \"code_mounts\": [\n",
65-
" # {\n",
66-
" # \"repo_name\": \"your-repo\",\n",
67-
" # \"repo_owner\": \"your-username\",\n",
68-
" # \"token\": os.environ.get(\"GITHUB_TOKEN\"),\n",
69-
" # }\n",
70-
" # ],\n",
71-
" # \"environment_variables\": {\"MY_VAR\": \"value\"},\n",
72-
" }\n",
73-
")\n",
74-
"\n",
75-
"# The None Here doesn't make much sense\n",
76-
"backend = provider.backend_factory(None)\n",
77-
"\n",
7886
"# Create the deep agent with the Runloop backend\n",
7987
"agent = create_deep_agent(\n",
8088
" backend=backend,\n",
@@ -86,26 +94,24 @@
8694
},
8795
{
8896
"cell_type": "code",
89-
"execution_count": 4,
97+
"execution_count": 6,
9098
"id": "d799bce6-4a67-40ce-858e-7ab32ddcb688",
9199
"metadata": {},
92100
"outputs": [
93101
{
94102
"data": {
95103
"text/plain": [
96-
"{'messages': [HumanMessage(content='could you list the files you have access to (not using the shell)', additional_kwargs={}, response_metadata={}, id='229d5971-55b2-44d2-9533-84a661ea4da4'),\n",
97-
" AIMessage(content=[{'text': \"I'll list the files in the root directory for you.\", 'type': 'text'}, {'id': 'toolu_01Ugvitaew9uS1ozKmrQari3', 'input': {'path': '/'}, 'name': 'ls', 'type': 'tool_use'}], additional_kwargs={}, response_metadata={'id': 'msg_013MoxLmzkUc6SVWxUeAD7aa', 'model': 'claude-sonnet-4-5-20250929', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 5776}, 'cache_creation_input_tokens': 5776, 'cache_read_input_tokens': 0, 'input_tokens': 3, 'output_tokens': 64, 'server_tool_use': None, 'service_tier': 'standard'}, 'model_name': 'claude-sonnet-4-5-20250929', 'model_provider': 'anthropic'}, id='lc_run--9b436cd0-b482-4211-ad71-6774481babed-0', tool_calls=[{'name': 'ls', 'args': {'path': '/'}, 'id': 'toolu_01Ugvitaew9uS1ozKmrQari3', 'type': 'tool_call'}], usage_metadata={'input_tokens': 5779, 'output_tokens': 64, 'total_tokens': 5843, 'input_token_details': {'cache_read': 0, 'cache_creation': 5776, 'ephemeral_5m_input_tokens': 5776, 'ephemeral_1h_input_tokens': 0}}),\n",
98-
" ToolMessage(content='[\"/bin\", \"/boot/\", \"/dev/\", \"/etc/\", \"/home/\", \"/lib\", \"/lost+found/\", \"/media/\", \"/mnt/\", \"/opt/\", \"/proc/\", \"/root/\", \"/run/\", \"/runloop/\", \"/sbin\", \"/srv/\", \"/sys/\", \"/tmp/\", \"/usr/\", \"/var/\"]', name='ls', id='dec83681-a9e7-4412-8e27-da46619bbc19', tool_call_id='toolu_01Ugvitaew9uS1ozKmrQari3'),\n",
99-
" AIMessage(content=[{'text': 'Let me check some common directories where user files might be located:', 'type': 'text'}, {'id': 'toolu_01JLshf23tBFBRGSJibeJcRP', 'input': {'path': '/home'}, 'name': 'ls', 'type': 'tool_use'}, {'id': 'toolu_01EPLqGgmjJTGKfJ8BkEYDoK', 'input': {'path': '/root'}, 'name': 'ls', 'type': 'tool_use'}, {'id': 'toolu_01X5zRT1fZizz4RWgif6ehdX', 'input': {'path': '/tmp'}, 'name': 'ls', 'type': 'tool_use'}], additional_kwargs={}, response_metadata={'id': 'msg_01HbqxTvYvpSSVjSgtyXB2k9', 'model': 'claude-sonnet-4-5-20250929', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 155}, 'cache_creation_input_tokens': 155, 'cache_read_input_tokens': 5776, 'input_tokens': 6, 'output_tokens': 136, 'server_tool_use': None, 'service_tier': 'standard'}, 'model_name': 'claude-sonnet-4-5-20250929', 'model_provider': 'anthropic'}, id='lc_run--5d5afda0-2250-4591-a313-74accddf2647-0', tool_calls=[{'name': 'ls', 'args': {'path': '/home'}, 'id': 'toolu_01JLshf23tBFBRGSJibeJcRP', 'type': 'tool_call'}, {'name': 'ls', 'args': {'path': '/root'}, 'id': 'toolu_01EPLqGgmjJTGKfJ8BkEYDoK', 'type': 'tool_call'}, {'name': 'ls', 'args': {'path': '/tmp'}, 'id': 'toolu_01X5zRT1fZizz4RWgif6ehdX', 'type': 'tool_call'}], usage_metadata={'input_tokens': 5937, 'output_tokens': 136, 'total_tokens': 6073, 'input_token_details': {'cache_read': 5776, 'cache_creation': 155, 'ephemeral_5m_input_tokens': 155, 'ephemeral_1h_input_tokens': 0}}),\n",
100-
" ToolMessage(content='[\"/home/user/\"]', name='ls', id='409b9122-14b9-4e4c-ab4b-6573ee69a954', tool_call_id='toolu_01JLshf23tBFBRGSJibeJcRP'),\n",
101-
" ToolMessage(content=[], name='ls', id='1b8ec4fb-6907-4a45-b8b6-33a1454ecd32', tool_call_id='toolu_01EPLqGgmjJTGKfJ8BkEYDoK'),\n",
102-
" ToolMessage(content='[\"/tmp/node-compile-cache/\", \"/tmp/v8-compile-cache-0/\"]', name='ls', id='3c83e0f2-e20b-48aa-b610-4c8d37cf74fb', tool_call_id='toolu_01X5zRT1fZizz4RWgif6ehdX'),\n",
103-
" AIMessage(content=[{'id': 'toolu_01CtGHxb64aJC83rGVQ49dM5', 'input': {'path': '/home/user'}, 'name': 'ls', 'type': 'tool_use'}], additional_kwargs={}, response_metadata={'id': 'msg_01Rzfmz3Az8FoAUsynorkCZq', 'model': 'claude-sonnet-4-5-20250929', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 252}, 'cache_creation_input_tokens': 252, 'cache_read_input_tokens': 5931, 'input_tokens': 7, 'output_tokens': 54, 'server_tool_use': None, 'service_tier': 'standard'}, 'model_name': 'claude-sonnet-4-5-20250929', 'model_provider': 'anthropic'}, id='lc_run--05826f64-cfe8-48e9-8d81-2b7b257e2844-0', tool_calls=[{'name': 'ls', 'args': {'path': '/home/user'}, 'id': 'toolu_01CtGHxb64aJC83rGVQ49dM5', 'type': 'tool_call'}], usage_metadata={'input_tokens': 6190, 'output_tokens': 54, 'total_tokens': 6244, 'input_token_details': {'cache_read': 5931, 'cache_creation': 252, 'ephemeral_5m_input_tokens': 252, 'ephemeral_1h_input_tokens': 0}}),\n",
104-
" ToolMessage(content='[\"/home/user/.bash_logout\", \"/home/user/.bashrc\", \"/home/user/.profile\", \"/home/user/.ssh/\", \"/home/user/.sudo_as_admin_successful\"]', name='ls', id='63915218-d062-49c3-8fec-3e6db446792b', tool_call_id='toolu_01CtGHxb64aJC83rGVQ49dM5'),\n",
105-
" AIMessage(content=\"Based on my exploration, here's what I found:\\n\\n**Root directory (/):** Contains standard Linux system directories like `/bin`, `/etc`, `/home`, `/usr`, `/var`, etc.\\n\\n**User home directory (/home/user/):** Contains:\\n- `.bash_logout`\\n- `.bashrc`\\n- `.profile`\\n- `.ssh/` (directory)\\n- `.sudo_as_admin_successful`\\n\\n**Other directories:**\\n- `/root/` - Empty or no accessible files\\n- `/tmp/` - Contains some Node.js compilation cache directories\\n\\nThe filesystem appears to be a relatively clean Linux environment with standard configuration files. There don't appear to be any project files or user documents currently present. Would you like me to explore any specific directory further or help you create some files?\", additional_kwargs={}, response_metadata={'id': 'msg_01NsE8SH6gjKfZN5FkoPkm7M', 'model': 'claude-sonnet-4-5-20250929', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 112}, 'cache_creation_input_tokens': 112, 'cache_read_input_tokens': 6183, 'input_tokens': 6, 'output_tokens': 176, 'server_tool_use': None, 'service_tier': 'standard'}, 'model_name': 'claude-sonnet-4-5-20250929', 'model_provider': 'anthropic'}, id='lc_run--a5de9966-5074-43fe-bf12-1bb82567649a-0', usage_metadata={'input_tokens': 6301, 'output_tokens': 176, 'total_tokens': 6477, 'input_token_details': {'cache_read': 6183, 'cache_creation': 112, 'ephemeral_5m_input_tokens': 112, 'ephemeral_1h_input_tokens': 0}})]}"
104+
"{'messages': [HumanMessage(content='could you list the files you have access to (not using the shell)', additional_kwargs={}, response_metadata={}, id='af9024cc-2f43-4189-adb4-df4002ba16e8'),\n",
105+
" AIMessage(content=[{'text': \"I'll list the files in the root directory for you using the `ls` tool.\", 'type': 'text'}, {'id': 'toolu_01F5JG2vEa3MfUkkVJDECfar', 'input': {'path': '/'}, 'name': 'ls', 'type': 'tool_use'}], additional_kwargs={}, response_metadata={'id': 'msg_01AJgwWnMfcuFRsowUgKymfd', 'model': 'claude-sonnet-4-5-20250929', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 6021}, 'cache_creation_input_tokens': 6021, 'cache_read_input_tokens': 0, 'input_tokens': 3, 'output_tokens': 70, 'server_tool_use': None, 'service_tier': 'standard'}, 'model_name': 'claude-sonnet-4-5-20250929', 'model_provider': 'anthropic'}, id='lc_run--40e0b169-0f0e-4454-8d27-54ad0af8202b-0', tool_calls=[{'name': 'ls', 'args': {'path': '/'}, 'id': 'toolu_01F5JG2vEa3MfUkkVJDECfar', 'type': 'tool_call'}], usage_metadata={'input_tokens': 6024, 'output_tokens': 70, 'total_tokens': 6094, 'input_token_details': {'cache_read': 0, 'cache_creation': 6021, 'ephemeral_5m_input_tokens': 6021, 'ephemeral_1h_input_tokens': 0}}),\n",
106+
" ToolMessage(content='[\"/bin\", \"/boot/\", \"/dev/\", \"/etc/\", \"/home/\", \"/lib\", \"/lost+found/\", \"/media/\", \"/mnt/\", \"/opt/\", \"/proc/\", \"/root/\", \"/run/\", \"/runloop/\", \"/sbin\", \"/srv/\", \"/sys/\", \"/tmp/\", \"/usr/\", \"/var/\"]', name='ls', id='0e7977b3-29be-4c7f-9732-99df7717a52a', tool_call_id='toolu_01F5JG2vEa3MfUkkVJDECfar'),\n",
107+
" AIMessage(content=[{'text': \"These are the top-level directories. Would you like me to explore a specific directory? Common places where user files might be located include:\\n- `/home/` - typically contains user home directories\\n- `/root/` - root user's home directory\\n- `/tmp/` - temporary files\\n\\nLet me check the home directory to see if there are any user files:\", 'type': 'text'}, {'id': 'toolu_01VbsrkDwfDCqwDAx8wxcvwv', 'input': {'path': '/home'}, 'name': 'ls', 'type': 'tool_use'}], additional_kwargs={}, response_metadata={'id': 'msg_014z33y8Tjf3JUTDygCPZ1ow', 'model': 'claude-sonnet-4-5-20250929', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 161}, 'cache_creation_input_tokens': 161, 'cache_read_input_tokens': 6021, 'input_tokens': 6, 'output_tokens': 130, 'server_tool_use': None, 'service_tier': 'standard'}, 'model_name': 'claude-sonnet-4-5-20250929', 'model_provider': 'anthropic'}, id='lc_run--37884afe-18dd-49c4-8b42-4c1b3352f354-0', tool_calls=[{'name': 'ls', 'args': {'path': '/home'}, 'id': 'toolu_01VbsrkDwfDCqwDAx8wxcvwv', 'type': 'tool_call'}], usage_metadata={'input_tokens': 6188, 'output_tokens': 130, 'total_tokens': 6318, 'input_token_details': {'cache_read': 6021, 'cache_creation': 161, 'ephemeral_5m_input_tokens': 161, 'ephemeral_1h_input_tokens': 0}}),\n",
108+
" ToolMessage(content='[\"/home/user/\"]', name='ls', id='9c9ce343-4d71-43c1-81e1-4e6ffb713bb9', tool_call_id='toolu_01VbsrkDwfDCqwDAx8wxcvwv'),\n",
109+
" AIMessage(content=[{'id': 'toolu_01YYB5BrUsHCERQENFEchwDH', 'input': {'path': '/home/user'}, 'name': 'ls', 'type': 'tool_use'}], additional_kwargs={}, response_metadata={'id': 'msg_01MEYsD2CkCVZnfMAchsoWyG', 'model': 'claude-sonnet-4-5-20250929', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 148}, 'cache_creation_input_tokens': 148, 'cache_read_input_tokens': 6182, 'input_tokens': 6, 'output_tokens': 54, 'server_tool_use': None, 'service_tier': 'standard'}, 'model_name': 'claude-sonnet-4-5-20250929', 'model_provider': 'anthropic'}, id='lc_run--31594999-5a24-4bc8-92bd-7710ff24833e-0', tool_calls=[{'name': 'ls', 'args': {'path': '/home/user'}, 'id': 'toolu_01YYB5BrUsHCERQENFEchwDH', 'type': 'tool_call'}], usage_metadata={'input_tokens': 6336, 'output_tokens': 54, 'total_tokens': 6390, 'input_token_details': {'cache_read': 6182, 'cache_creation': 148, 'ephemeral_5m_input_tokens': 148, 'ephemeral_1h_input_tokens': 0}}),\n",
110+
" ToolMessage(content='[\"/home/user/.bash_logout\", \"/home/user/.bashrc\", \"/home/user/.profile\", \"/home/user/.ssh/\", \"/home/user/.sudo_as_admin_successful\"]', name='ls', id='989c232e-847d-4bf5-b83a-d5f6170453dd', tool_call_id='toolu_01YYB5BrUsHCERQENFEchwDH'),\n",
111+
" AIMessage(content='The `/home/user` directory contains mostly configuration files. Would you like me to explore any other directories or search for specific types of files?', additional_kwargs={}, response_metadata={'id': 'msg_01GBSvugbTUcF13j4s7veT3n', 'model': 'claude-sonnet-4-5-20250929', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 111}, 'cache_creation_input_tokens': 111, 'cache_read_input_tokens': 6330, 'input_tokens': 6, 'output_tokens': 32, 'server_tool_use': None, 'service_tier': 'standard'}, 'model_name': 'claude-sonnet-4-5-20250929', 'model_provider': 'anthropic'}, id='lc_run--f8ac1432-1219-4afc-869b-63b3b9df7093-0', usage_metadata={'input_tokens': 6447, 'output_tokens': 32, 'total_tokens': 6479, 'input_token_details': {'cache_read': 6330, 'cache_creation': 111, 'ephemeral_5m_input_tokens': 111, 'ephemeral_1h_input_tokens': 0}})]}"
106112
]
107113
},
108-
"execution_count": 4,
114+
"execution_count": 6,
109115
"metadata": {},
110116
"output_type": "execute_result"
111117
}
@@ -121,6 +127,66 @@
121127
")"
122128
]
123129
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": 8,
133+
"id": "77c3cee4-fb80-4488-adfc-2044c33afbaa",
134+
"metadata": {},
135+
"outputs": [
136+
{
137+
"name": "stdout",
138+
"output_type": "stream",
139+
"text": [
140+
"[{'type': 'text', 'text': \"Perfect! I've created the file `foo.md` in `/home/user/` with a short 3 sentence poem about nature. The poem describes the morning sun, a gentle breeze, and nature's peaceful symphony.\"}]\n"
141+
]
142+
}
143+
],
144+
"source": [
145+
"import uuid\n",
146+
"\n",
147+
"config = {\n",
148+
" \"configurable\": {\n",
149+
" \"thread_id\": str(uuid.uuid4())\n",
150+
" }\n",
151+
"}\n",
152+
"\n",
153+
"# Example: Ask the agent to create a file\n",
154+
"result = agent.invoke({\n",
155+
" \"messages\": [{\n",
156+
" \"role\": \"user\",\n",
157+
" \"content\": \"create a file called foo.md with a short 3 sentence poem'\"\n",
158+
" }]\n",
159+
"}, config=config)\n",
160+
"\n",
161+
"# Print the agent's response\n",
162+
"print(result[\"messages\"][-1].content_blocks)"
163+
]
164+
},
165+
{
166+
"cell_type": "code",
167+
"execution_count": 13,
168+
"id": "c6d439fe-1aa8-45a4-a534-b62e8a2e6498",
169+
"metadata": {},
170+
"outputs": [
171+
{
172+
"name": "stdout",
173+
"output_type": "stream",
174+
"text": [
175+
"total 4.0K\n",
176+
"4.0K -rw-r--r-- 1 user user 152 Nov 6 17:58 foo.md\n",
177+
"\n",
178+
"The morning sun breaks through the trees.\n",
179+
"A gentle breeze whispers secrets to the leaves.\n",
180+
"Nature's symphony plays on, bringing peace to all who listen.\n",
181+
"\n"
182+
]
183+
}
184+
],
185+
"source": [
186+
"print(backend.execute('ls -lsh').output)\n",
187+
"print(backend.execute('cat foo.md').output)"
188+
]
189+
},
124190
{
125191
"cell_type": "markdown",
126192
"id": "c9d0e1f2-a3b4-5678-3456-789012345678",
@@ -171,51 +237,6 @@
171237
"\n",
172238
"print(\"Agent created with GitHub repository mounted!\")"
173239
]
174-
},
175-
{
176-
"cell_type": "markdown",
177-
"id": "e1f2a3b4-c5d6-7890-5678-901234567890",
178-
"metadata": {},
179-
"source": [
180-
"## Running the agent\n",
181-
"\n",
182-
"Now you can interact with your agent and it will operate on files in the Runloop devbox."
183-
]
184-
},
185-
{
186-
"cell_type": "code",
187-
"execution_count": 4,
188-
"id": "ad5cc8dd-3710-4bc0-93b5-b06cb21fe18a",
189-
"metadata": {},
190-
"outputs": [],
191-
"source": [
192-
"import uuid"
193-
]
194-
},
195-
{
196-
"cell_type": "code",
197-
"execution_count": null,
198-
"id": "af66ae08-bb44-4a1e-9f97-ca43a589185a",
199-
"metadata": {},
200-
"outputs": [],
201-
"source": [
202-
"config = {\n",
203-
" \"configurable\": {\n",
204-
" \"thread_id\": str(uuid.uuid4())\n",
205-
" }\n",
206-
"}\n",
207-
"\n",
208-
"# Example: Ask the agent to create a file\n",
209-
"result = agent.invoke({\n",
210-
" \"messages\": [{\n",
211-
" \"role\": \"user\",\n",
212-
" \"content\": \"list the mounted git repo'\"\n",
213-
" }]\n",
214-
"}, config=config)\n",
215-
"\n",
216-
"# Print the agent's response\n",
217-
"print(result[\"messages\"][-1].content_blocks)"
218-
]
219240
}
220241
],
221242
"metadata": {

0 commit comments

Comments
 (0)