Skip to content

Commit 686d683

Browse files
authored
Merge pull request #72 from nforro/tools
Change argument type from `tuple` to `list` in the `view` tool
2 parents c66c300 + 05836d8 commit 686d683

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

beeai/agents/tests/unit/test_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ async def test_view(tmp_path):
191191
)
192192
result = output.result
193193
assert result == content
194-
output = await tool.run(input=ViewToolInput(path=test_file, view_range=(2, -1))).middleware(
194+
output = await tool.run(input=ViewToolInput(path=test_file, view_range=[2, -1])).middleware(
195195
GlobalTrajectoryMiddleware(pretty=True)
196196
)
197197
result = output.result
@@ -204,7 +204,7 @@ async def test_view(tmp_path):
204204
"""
205205
)[1:]
206206
)
207-
output = await tool.run(input=ViewToolInput(path=test_file, view_range=(1, 2))).middleware(
207+
output = await tool.run(input=ViewToolInput(path=test_file, view_range=[1, 2])).middleware(
208208
GlobalTrajectoryMiddleware(pretty=True)
209209
)
210210
result = output.result

beeai/agents/tools/text.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
from pathlib import Path
33

4-
from pydantic import BaseModel, Field
4+
from pydantic import BaseModel, Field, field_validator
55

66
from beeai_framework.context import RunContext
77
from beeai_framework.emitter import Emitter
@@ -39,15 +39,22 @@ async def _run(
3939

4040
class ViewToolInput(BaseModel):
4141
path: Path = Field(description="Absolute path to a file or directory to view")
42-
view_range: tuple[int, int] | None = Field(
42+
view_range: list[int] | None = Field(
4343
description="""
44-
Tuple of two integers specifying the start and end line numbers to view.
44+
List of two integers specifying the start and end line numbers to view.
4545
Line numbers are 1-indexed, and -1 for the end line means read to the end of the file.
4646
This argument only applies when viewing files, not directories.
4747
""",
4848
default=None,
4949
)
5050

51+
@field_validator("view_range", mode="after")
52+
@classmethod
53+
def validate_view_range(cls, view_range: list[int] | None) -> list[int] | None:
54+
if view_range is not None and len(view_range) != 2:
55+
raise ValueError("`view_range` must be a list of two integers")
56+
return view_range
57+
5158

5259
class ViewTool(Tool[ViewToolInput, ToolRunOptions, StringToolOutput]):
5360
name = "view"

0 commit comments

Comments
 (0)