Skip to content

Commit 1db5414

Browse files
committed
merge w main
2 parents e7b0802 + adf5038 commit 1db5414

5 files changed

Lines changed: 79 additions & 57 deletions

File tree

reference.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,14 @@ client.instance.bash(
530530
<dl>
531531
<dd>
532532

533+
**session:** `typing.Optional[int]`
534+
535+
</dd>
536+
</dl>
537+
538+
<dl>
539+
<dd>
540+
533541
**restart:** `typing.Optional[bool]`
534542

535543
</dd>
@@ -538,15 +546,15 @@ client.instance.bash(
538546
<dl>
539547
<dd>
540548

541-
**get_background_processes:** `typing.Optional[bool]`
549+
**list_sessions:** `typing.Optional[bool]`
542550

543551
</dd>
544552
</dl>
545553

546554
<dl>
547555
<dd>
548556

549-
**kill_pid:** `typing.Optional[int]`
557+
**check_session:** `typing.Optional[int]`
550558

551559
</dd>
552560
</dl>

src/scrapybara/client.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -904,17 +904,19 @@ def bash(
904904
self,
905905
*,
906906
command: Optional[str] = OMIT,
907+
session: Optional[int] = OMIT,
907908
restart: Optional[bool] = OMIT,
908-
get_background_processes: Optional[bool] = OMIT,
909-
kill_pid: Optional[int] = OMIT,
909+
list_sessions: Optional[bool] = OMIT,
910+
check_session: Optional[int] = OMIT,
910911
request_options: Optional[RequestOptions] = None,
911912
) -> Optional[Any]:
912913
return self._client.instance.bash(
913914
self.id,
914915
command=command,
916+
session=session,
915917
restart=restart,
916-
get_background_processes=get_background_processes,
917-
kill_pid=kill_pid,
918+
list_sessions=list_sessions,
919+
check_session=check_session,
918920
request_options=request_options
919921
)
920922

@@ -1426,17 +1428,19 @@ async def bash(
14261428
self,
14271429
*,
14281430
command: Optional[str] = OMIT,
1431+
session: Optional[int] = OMIT,
14291432
restart: Optional[bool] = OMIT,
1430-
get_background_processes: Optional[bool] = OMIT,
1431-
kill_pid: Optional[int] = OMIT,
1433+
list_sessions: Optional[bool] = OMIT,
1434+
check_session: Optional[int] = OMIT,
14321435
request_options: Optional[RequestOptions] = None,
14331436
) -> Optional[Any]:
14341437
return await self._client.instance.bash(
14351438
self.id,
14361439
command=command,
1440+
session=session,
14371441
restart=restart,
1438-
get_background_processes=get_background_processes,
1439-
kill_pid=kill_pid,
1442+
list_sessions=list_sessions,
1443+
check_session=check_session,
14401444
request_options=request_options
14411445
)
14421446

src/scrapybara/instance/client.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ def bash(
215215
instance_id: str,
216216
*,
217217
command: typing.Optional[str] = OMIT,
218+
session: typing.Optional[int] = OMIT,
218219
restart: typing.Optional[bool] = OMIT,
219-
get_background_processes: typing.Optional[bool] = OMIT,
220-
kill_pid: typing.Optional[int] = OMIT,
220+
list_sessions: typing.Optional[bool] = OMIT,
221+
check_session: typing.Optional[int] = OMIT,
221222
request_options: typing.Optional[RequestOptions] = None,
222223
) -> BashResponse:
223224
"""
@@ -227,11 +228,13 @@ def bash(
227228
228229
command : typing.Optional[str]
229230
231+
session : typing.Optional[int]
232+
230233
restart : typing.Optional[bool]
231234
232-
get_background_processes : typing.Optional[bool]
235+
list_sessions : typing.Optional[bool]
233236
234-
kill_pid : typing.Optional[int]
237+
check_session : typing.Optional[int]
235238
236239
request_options : typing.Optional[RequestOptions]
237240
Request-specific configuration.
@@ -257,9 +260,10 @@ def bash(
257260
method="POST",
258261
json={
259262
"command": command,
263+
"session": session,
260264
"restart": restart,
261-
"get_background_processes": get_background_processes,
262-
"kill_pid": kill_pid,
265+
"list_sessions": list_sessions,
266+
"check_session": check_session,
263267
},
264268
headers={
265269
"content-type": "application/json",
@@ -1123,9 +1127,10 @@ async def bash(
11231127
instance_id: str,
11241128
*,
11251129
command: typing.Optional[str] = OMIT,
1130+
session: typing.Optional[int] = OMIT,
11261131
restart: typing.Optional[bool] = OMIT,
1127-
get_background_processes: typing.Optional[bool] = OMIT,
1128-
kill_pid: typing.Optional[int] = OMIT,
1132+
list_sessions: typing.Optional[bool] = OMIT,
1133+
check_session: typing.Optional[int] = OMIT,
11291134
request_options: typing.Optional[RequestOptions] = None,
11301135
) -> BashResponse:
11311136
"""
@@ -1135,11 +1140,13 @@ async def bash(
11351140
11361141
command : typing.Optional[str]
11371142
1143+
session : typing.Optional[int]
1144+
11381145
restart : typing.Optional[bool]
11391146
1140-
get_background_processes : typing.Optional[bool]
1147+
list_sessions : typing.Optional[bool]
11411148
1142-
kill_pid : typing.Optional[int]
1149+
check_session : typing.Optional[int]
11431150
11441151
request_options : typing.Optional[RequestOptions]
11451152
Request-specific configuration.
@@ -1173,9 +1180,10 @@ async def main() -> None:
11731180
method="POST",
11741181
json={
11751182
"command": command,
1183+
"session": session,
11761184
"restart": restart,
1177-
"get_background_processes": get_background_processes,
1178-
"kill_pid": kill_pid,
1185+
"list_sessions": list_sessions,
1186+
"check_session": check_session,
11791187
},
11801188
headers={
11811189
"content-type": "application/json",

src/scrapybara/tools/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ class BashToolParameters(BaseModel):
165165
"""Parameters for bash command execution."""
166166

167167
command: Optional[str] = Field(description="The bash command to execute")
168+
session: Optional[int] = Field(None, description="Session ID to run the command in")
168169
restart: Optional[bool] = Field(False, description="Whether to restart the shell")
169-
get_background_processes: Optional[bool] = Field(None, description="Retrieve information (pid, status, command) about background processes")
170-
kill_pid: Optional[int] = Field(None, description="Process ID to kill")
170+
list_sessions: Optional[bool] = Field(None, description="Whether to list all bash sessions")
171+
check_session: Optional[int] = Field(None, description="Session ID to check status")
171172

172173

173174
class BashTool(Tool):
@@ -189,8 +190,9 @@ def __call__(self, **kwargs: Any) -> Any:
189190
params = BashToolParameters.model_validate(kwargs)
190191
return self._instance.bash(
191192
command=params.command,
193+
session=params.session,
192194
restart=params.restart,
193-
get_background_processes=params.get_background_processes,
194-
kill_pid=params.kill_pid
195+
list_sessions=params.list_sessions,
196+
check_session=params.check_session
195197
)
196198

tests/custom/test_client.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from scrapybara.tools import BashTool, ComputerTool, EditTool
2121

2222

23-
class YCStats(BaseModel):
24-
number_of_startups: int
25-
combined_valuation: int
23+
class ExampleSite(BaseModel):
24+
title: str
25+
has_links: bool
2626

2727

2828
def _check_api_key() -> None:
@@ -47,19 +47,19 @@ def test_ubuntu() -> None:
4747
response = client.act(
4848
model=Anthropic(),
4949
system=UBUNTU_SYSTEM_PROMPT_ANTHROPIC,
50-
prompt="Go to the YC website and get the number of funded startups and combined valuation",
50+
prompt="Go to example.com and get the page title and whether it has any links",
5151
tools=[
5252
ComputerTool(ubuntu_instance),
5353
BashTool(ubuntu_instance),
5454
EditTool(ubuntu_instance),
5555
],
56-
schema=YCStats,
56+
schema=ExampleSite,
5757
on_step=lambda step: print(step.text, step.tool_calls),
5858
)
5959
print(response.output)
6060
assert response.output is not None
61-
assert response.output.number_of_startups is not None
62-
assert response.output.combined_valuation is not None
61+
assert response.output.title is not None
62+
assert isinstance(response.output.has_links, bool)
6363
ubuntu_instance.browser.stop()
6464
ubuntu_instance.stop()
6565

@@ -81,19 +81,19 @@ def test_ubuntu_openai() -> None:
8181
response = client.act(
8282
model=OpenAI(),
8383
system=UBUNTU_SYSTEM_PROMPT_OPENAI,
84-
prompt="Go to the YC website and get the number of funded startups and combined valuation",
84+
prompt="Go to example.com and get the page title and whether it has any links",
8585
tools=[
8686
ComputerTool(ubuntu_instance),
8787
BashTool(ubuntu_instance),
8888
EditTool(ubuntu_instance),
8989
],
90-
schema=YCStats,
90+
schema=ExampleSite,
9191
on_step=lambda step: print(step.text, step.tool_calls),
9292
)
9393
print(response.output)
9494
assert response.output is not None
95-
assert response.output.number_of_startups is not None
96-
assert response.output.combined_valuation is not None
95+
assert response.output.title is not None
96+
assert isinstance(response.output.has_links, bool)
9797
ubuntu_instance.browser.stop()
9898
ubuntu_instance.stop()
9999

@@ -112,17 +112,17 @@ def test_browser() -> None:
112112
response = client.act(
113113
model=Anthropic(),
114114
system=BROWSER_SYSTEM_PROMPT_ANTHROPIC,
115-
prompt="Go to the YC website and get the number of funded startups and combined valuation",
115+
prompt="Go to example.com and get the page title and whether it has any links",
116116
tools=[
117117
ComputerTool(browser_instance),
118118
],
119-
schema=YCStats,
119+
schema=ExampleSite,
120120
on_step=lambda step: print(step.text, step.tool_calls),
121121
)
122122
print(response.output)
123123
assert response.output is not None
124-
assert response.output.number_of_startups is not None
125-
assert response.output.combined_valuation is not None
124+
assert response.output.title is not None
125+
assert isinstance(response.output.has_links, bool)
126126
browser_instance.stop()
127127

128128
@pytest.mark.skip()
@@ -140,17 +140,17 @@ def test_browser_openai() -> None:
140140
response = client.act(
141141
model=OpenAI(),
142142
system=BROWSER_SYSTEM_PROMPT_OPENAI,
143-
prompt="Go to the YC website and get the number of funded startups and combined valuation",
143+
prompt="Go to example.com and get the page title and whether it has any links",
144144
tools=[
145145
ComputerTool(browser_instance),
146146
],
147-
schema=YCStats,
147+
schema=ExampleSite,
148148
on_step=lambda step: print(step.text, step.tool_calls),
149149
)
150150
print(response.output)
151151
assert response.output is not None
152-
assert response.output.number_of_startups is not None
153-
assert response.output.combined_valuation is not None
152+
assert response.output.title is not None
153+
assert isinstance(response.output.has_links, bool)
154154
browser_instance.stop()
155155

156156

@@ -167,17 +167,17 @@ def test_windows() -> None:
167167
response = client.act(
168168
model=Anthropic(),
169169
system=WINDOWS_SYSTEM_PROMPT_ANTHROPIC,
170-
prompt="Go to the YC website and get the number of funded startups and combined valuation",
170+
prompt="Go to example.com and get the page title and whether it has any links",
171171
tools=[
172172
ComputerTool(windows_instance),
173173
],
174-
schema=YCStats,
174+
schema=ExampleSite,
175175
on_step=lambda step: print(step.text, step.tool_calls),
176176
)
177177
print(response.output)
178178
assert response.output is not None
179-
assert response.output.number_of_startups is not None
180-
assert response.output.combined_valuation is not None
179+
assert response.output.title is not None
180+
assert isinstance(response.output.has_links, bool)
181181
windows_instance.stop()
182182

183183

@@ -199,19 +199,19 @@ def test_ubuntu_thinking() -> None:
199199
response = client.act(
200200
model=Anthropic(name="claude-3-7-sonnet-20250219-thinking"),
201201
system=UBUNTU_SYSTEM_PROMPT_ANTHROPIC,
202-
prompt="Go to the YC website and get the number of funded startups and combined valuation",
202+
prompt="Go to example.com and get the page title and whether it has any links",
203203
tools=[
204204
ComputerTool(ubuntu_instance),
205205
BashTool(ubuntu_instance),
206206
EditTool(ubuntu_instance),
207207
],
208-
schema=YCStats,
208+
schema=ExampleSite,
209209
on_step=lambda step: print(step.text, step.tool_calls, step.reasoning_parts),
210210
)
211211
print(response.output)
212212
assert response.output is not None
213-
assert response.output.number_of_startups is not None
214-
assert response.output.combined_valuation is not None
213+
assert response.output.title is not None
214+
assert isinstance(response.output.has_links, bool)
215215
ubuntu_instance.browser.stop()
216216
ubuntu_instance.stop()
217217

@@ -231,17 +231,17 @@ def test_browser_thinking() -> None:
231231
response = client.act(
232232
model=Anthropic(name="claude-3-7-sonnet-20250219-thinking"),
233233
system=BROWSER_SYSTEM_PROMPT_ANTHROPIC,
234-
prompt="Go to the YC website and get the number of funded startups and combined valuation",
234+
prompt="Go to example.com and get the page title and whether it has any links",
235235
tools=[
236236
ComputerTool(browser_instance),
237237
],
238-
schema=YCStats,
238+
schema=ExampleSite,
239239
on_step=lambda step: print(step.text, step.tool_calls, step.reasoning_parts),
240240
)
241241
print(response.output)
242242
assert response.output is not None
243-
assert response.output.number_of_startups is not None
244-
assert response.output.combined_valuation is not None
243+
assert response.output.title is not None
244+
assert isinstance(response.output.has_links, bool)
245245
browser_instance.stop()
246246

247247

0 commit comments

Comments
 (0)