MCPcopy Create free account
hub / github.com/MiniMax-AI/Mini-Agent / ReadTool

Class ReadTool

mini_agent/tools/file_tools.py:63–152  ·  view source on GitHub ↗

Read file content.

Source from the content-addressed store, hash-verified

61
62
63class ReadTool(Tool):
64 """Read file content."""
65
66 def __init__(self, workspace_dir: str = "."):
67 """Initialize ReadTool with workspace directory.
68
69 Args:
70 workspace_dir: Base directory for resolving relative paths
71 """
72 self.workspace_dir = Path(workspace_dir).absolute()
73
74 @property
75 def name(self) -> str:
76 return "read_file"
77
78 @property
79 def description(self) -> str:
80 return (
81 "Read file contents from the filesystem. Output always includes line numbers "
82 "in format 'LINE_NUMBER|LINE_CONTENT' (1-indexed). Supports reading partial content "
83 "by specifying line offset and limit for large files. "
84 "You can call this tool multiple times in parallel to read different files simultaneously."
85 )
86
87 @property
88 def parameters(self) -> dict[str, Any]:
89 return {
90 "type": "object",
91 "properties": {
92 "path": {
93 "type": "string",
94 "description": "Absolute or relative path to the file",
95 },
96 "offset": {
97 "type": "integer",
98 "description": "Starting line number (1-indexed). Use for large files to read from specific line",
99 },
100 "limit": {
101 "type": "integer",
102 "description": "Number of lines to read. Use with offset for large files to read in chunks",
103 },
104 },
105 "required": ["path"],
106 }
107
108 async def execute(self, path: str, offset: int | None = None, limit: int | None = None) -> ToolResult:
109 """Execute read file."""
110 try:
111 file_path = Path(path)
112 # Resolve relative paths relative to workspace_dir
113 if not file_path.is_absolute():
114 file_path = self.workspace_dir / file_path
115
116 if not file_path.exists():
117 return ToolResult(
118 success=False,
119 content="",
120 error=f"File not found: {path}",

Callers 12

add_workspace_toolsFunction · 0.90
test_read_toolFunction · 0.90
test_agent_simple_taskFunction · 0.90
test_agent_bash_taskFunction · 0.90
test_basic_agent_usageFunction · 0.90
demo_agent_with_notesFunction · 0.90
demo_read_toolFunction · 0.90
demo_full_agentFunction · 0.90
demo_interactive_modeFunction · 0.90
demo_file_creationFunction · 0.90
demo_bash_taskFunction · 0.90

Calls

no outgoing calls

Tested by 5

test_read_toolFunction · 0.72
test_agent_simple_taskFunction · 0.72
test_agent_bash_taskFunction · 0.72
test_basic_agent_usageFunction · 0.72