-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcustom_tool.py
More file actions
36 lines (27 loc) · 1.33 KB
/
Copy pathcustom_tool.py
File metadata and controls
36 lines (27 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import annotations
from pydantic import BaseModel, Field
from agentforge_harness.tools.base import Tool, ToolInvocation, ToolKind, ToolResult
class CountLinesParams(BaseModel):
path: str = Field(..., description="Path to a text file inside the workspace.")
class CountLinesTool(Tool):
name = "count_lines"
description = "Count lines in a text file and return a structured observation."
kind = ToolKind.READ
schema = CountLinesParams
async def execute(self, invocation: ToolInvocation) -> ToolResult:
params = CountLinesParams(**invocation.params)
path = (invocation.cwd / params.path).resolve()
if not path.is_file():
return ToolResult.error_result(
f"File not found: {params.path}",
summary="Could not count lines",
recovery_hint="Use list_dir or glob to find the correct file, then retry.",
)
line_count = len(path.read_text(encoding="utf-8").splitlines())
return ToolResult.success_result(
f"{params.path}: {line_count} line(s)",
summary=f"Counted {line_count} line(s) in {params.path}",
artifacts=[str(path)],
next_actions=["Use read_file if the exact contents are needed."],
metadata={"path": str(path), "lines": line_count},
)