agentscope.toolRead
class Read(ToolBase)
agentscope/tool/_builtin/_read.py:82–576读取工具。位于 agentscope.tool 包,继承自 ToolBase。核心成员包括 check_permissions、match_rule、generate_suggestions、call、description。
The read tool. Declared in agentscope.tool. Extends ToolBase.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(max_line_characters: int = 2000, model_input_types: list[str] | None = None, middlewares: List[ToolMiddlew… | 初始化 `Read` 实例。 Initialize the read tool. |
属性摘要Property Summary
| 属性Property | 说明Description |
|---|---|
description | 读取 `description` 属性。 The description presented to the agent, with the image and PDF bullets rendered from the model's accepted input types. |
属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
name | str | 名称字段。 | 'Read' |
input_schema | dict[str, Any] | 输入模式字段。 | _ReadParams.model_json_schema() |
is_mcp | bool | 是 MCP字段。 | False |
is_read_only | bool | `is_read_only` 字段。 | True |
is_concurrency_safe | bool | `is_concurrency_safe` 字段。 | True |
is_external_tool | bool | 是外部工具字段。 | False |
is_state_injected | bool | `is_state_injected` 字段。 | True |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
async def check_permissions(tool_input: dict[str, Any], context: PermissionContext) -> PermissionDecisionasync | 检查权限。 Check permissions for file reading. |
async def match_rule(rule_content: str | None, tool_input: dict[str, Any]) -> boolasync | 执行 `match_rule` 方法。 Check if a permission rule matches the file path. |
async def generate_suggestions(tool_input: dict[str, Any]) -> List[PermissionRule]async | 设置该参数。 Generate suggested permission rules for the file path. |
async def call(file_path: str, offset: int = 1, limit: int = 2000, pages: str | None = None, _agent_state: AgentState |…async | 向智能体发送输入并返回最终回复。 Read a file and return content as appropriate block types. |
构造器详情Constructor Detail
Read
def __init__(max_line_characters: int = 2000, model_input_types: list[str] | None = None, middlewares: List[ToolMiddlewareBase] | None = None, backend: BackendBase | None = None) -> None
初始化 Read 实例。
Initialize the read tool.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
max_line_characters默认default 2000 | int | 最大 line characters(类型 `int`)。The maximum number of characters to include for each line when reading files. Lines longer than this will be truncated with a "[truncated]" suffix. This prevents overwhelming the agent with excessively long lines while still providing useful content. |
model_input_types默认default None | list[str] | None | 模型输入类型(类型 `list[str] | None`)。The media types the downstream model accepts as input, aligned with the model card's `input_types` field so it can be passed through directly, e.g. `Read(model_input_types=model_card.input_types)`. Glob patterns like `"image/*"` are accepted. Files whose media type is listed are returned as `DataBlock` for the model to consume natively; otherwise images return an error and PDFs fall back to local text extraction. Defaults to `image/png`, `image/jpeg`, `image/gif` and `image/webp`. |
middlewares默认default None | List[ToolMiddlewareBase] | None | 中间件列表(类型 `List[ToolMiddlewareBase] | None`)。Tool middlewares wrapping the tool execution. |
backend默认default None | BackendBase | None | backend(类型 `BackendBase | None`)。The sandbox backend to use for file I/O. When `None`, a :class:`LocalBackend` is created. |
agentscope/tool/_builtin/_read.py:131–174属性详情Attribute Detail
name
str = 'Read'名称字段。声明为 str。
The name field.
agentscope/tool/_builtin/_read.py:85input_schema
dict[str, Any] = _ReadParams.model_json_schema()输入模式字段。声明为 dict[str, Any]。
The input schema field.
agentscope/tool/_builtin/_read.py:123is_mcp
bool = False是 MCP字段。声明为 bool。
The is mcp field.
agentscope/tool/_builtin/_read.py:125is_read_only
bool = Trueis_read_only 字段。声明为 bool。
The is read only field.
agentscope/tool/_builtin/_read.py:126is_concurrency_safe
bool = Trueis_concurrency_safe 字段。声明为 bool。
The is concurrency safe field.
agentscope/tool/_builtin/_read.py:127is_external_tool
bool = False是外部工具字段。声明为 bool。
The is external tool field.
agentscope/tool/_builtin/_read.py:128is_state_injected
bool = Trueis_state_injected 字段。声明为 bool。
The is state injected field.
agentscope/tool/_builtin/_read.py:129属性详情Property Detail
description
def description() -> str
读取 description 属性。
The description presented to the agent, with the image and PDF bullets rendered from the model's accepted input types.
agentscope/tool/_builtin/_read.py:99–121方法详情Method Detail
check_permissions
async def check_permissions(tool_input: dict[str, Any], context: PermissionContext) -> PermissionDecision
检查权限。
Read is a read-only tool.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
tool_input | dict[str, Any] | 工具输入(类型 `dict[str, Any]`)。The tool input. |
context | PermissionContext | 上下文(类型 `PermissionContext`)。The context. |
agentscope/tool/_builtin/_read.py:176–190match_rule
async def match_rule(rule_content: str | None, tool_input: dict[str, Any]) -> bool
执行 match_rule 方法。
Matches rule_content as a glob pattern against the "file_path" parameter using fnmatch.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rule_content | str | None | 规则内容(类型 `str | None`)。Glob pattern to match against the file path (e.g., "src/**"), or None to match all invocations |
tool_input | dict[str, Any] | 工具输入(类型 `dict[str, Any]`)。The tool input data containing "file_path" key |
agentscope/tool/_builtin/_read.py:192–221generate_suggestions
async def generate_suggestions(tool_input: dict[str, Any]) -> List[PermissionRule]
设置该参数。
Suggests a glob pattern covering the parent directory of the file, allowing the user to grant permission for the entire directory at once.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
tool_input | dict[str, Any] | 工具输入(类型 `dict[str, Any]`)。The tool input data containing "file_path" key |
agentscope/tool/_builtin/_read.py:223–257call
async def call(file_path: str, offset: int = 1, limit: int = 2000, pages: str | None = None, _agent_state: AgentState | None = None) -> ToolChunk
向智能体发送输入并返回最终回复。
Dispatches to format-specific readers based on file extension: - PDF: text extraction via RAG parser - Image: base64-encoded DataBlock - Other: line-numbered text (TextBlock)
| 名称Name | 类型Type | 说明Description |
|---|---|---|
file_path | str | 文件路径(类型 `str`)。The file path. |
offset默认default 1 | int | 偏移量(类型 `int`)。The offset. |
limit默认default 2000 | int | 数量上限(类型 `int`)。The limit. |
pages默认default None | str | None | 分页(类型 `str | None`)。The pages. |
_agent_state默认default None | AgentState | None | 智能体状态(类型 `AgentState | None`)。The agent state. |
agentscope/tool/_builtin/_read.py:259–333