Skip to content

Commit 2ec6fab

Browse files
committed
insert after tool: followups from Nikola's review
Signed-off-by: Tomas Tomecek <[email protected]> Assisted-by: Cursor(Claude)
1 parent 6f06c91 commit 2ec6fab

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

beeai/agents/tools/text.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from beeai_framework.emitter import Emitter
88
from beeai_framework.tools import StringToolOutput, Tool, ToolError, ToolRunOptions
99

10-
from common.validators import AbsolutePath, Range
10+
from common.validators import AbsolutePath, NonEmptyString, Range
1111

1212

1313
class CreateToolInput(BaseModel):
@@ -88,9 +88,7 @@ class InsertToolInput(BaseModel):
8888

8989
class InsertTool(Tool[InsertToolInput, ToolRunOptions, StringToolOutput]):
9090
name = "insert"
91-
description = """
92-
Inserts the specified text at a specific location in a file
93-
"""
91+
description = "Inserts the specified text at a specific location in a file."
9492
input_schema = InsertToolInput
9593

9694
def _create_emitter(self) -> Emitter:
@@ -113,15 +111,15 @@ async def _run(
113111

114112
class InsertAfterSubstringToolInput(BaseModel):
115113
file: AbsolutePath = Field(description="Absolute path to a file to edit")
116-
insert_after_substring: str = Field(description="Substring to insert the text after")
117-
new_string: str = Field(description="Text to insert")
114+
insert_after_substring: NonEmptyString = Field(description="Substring to insert the text after")
115+
new_string: NonEmptyString = Field(description="Text to insert")
118116

119117

120118
class InsertAfterSubstringTool(Tool[InsertAfterSubstringToolInput, ToolRunOptions, StringToolOutput]):
121119
name = "insert_after_substring"
122120
description = """
123-
Inserts the provided text new_string on a new line after the first
124-
occurrence of the specified substring insert_after_substring. The insertion
121+
Inserts the provided text `new_string` on a new line after the first
122+
occurrence of the specified substring `insert_after_substring`. The insertion
125123
happens only once.
126124
"""
127125
input_schema = InsertAfterSubstringToolInput
@@ -135,8 +133,6 @@ def _create_emitter(self) -> Emitter:
135133
async def _run(
136134
self, tool_input: InsertAfterSubstringToolInput, options: ToolRunOptions | None, context: RunContext
137135
) -> StringToolOutput:
138-
if not tool_input.insert_after_substring:
139-
raise ToolError("No insertion was done because the specified substring wasn't provided")
140136
try:
141137
content = await asyncio.to_thread(tool_input.file.read_text)
142138
if tool_input.insert_after_substring not in content:

0 commit comments

Comments
 (0)