AS AgentScopeAPI 手册 / API Reference
类class agentscope.tool

Glob

class Glob(ToolBase)
源码Source agentscope/tool/_builtin/_glob.py:45–365

Glob,让智能体以受控方式调用外部能力。位于 agentscope.tool 包,继承自 ToolBase。核心成员包括 check_permissions、match_rule、generate_suggestions、call。

The glob tool for fast file pattern matching. Declared in agentscope.tool. Extends ToolBase.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(backend: BackendBase | None = None, glob_helper_path: str | None = None, middlewares: List[ToolMiddlewareB…
初始化 `Glob` 实例。
Initialize the glob tool.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
namestr
名称字段。
'Glob'
descriptionstr
`description` 字段。
'Fast file pattern matching tool that works with\nany codebase size.\n\nSupports glob patterns like "**/*.js" or "src/**/*.ts" and returns\nmatching file paths sorted by modification time (newest first).\n\nUse this tool when you need to find files by pattern across the\ncodebase.\n\nUse head_limit to cap the number of results returned.'
input_schemadict[str, Any]
输入模式字段。
{'type': 'object', 'properties': {'pattern': {'type': 'string', 'description': "The glob pattern to match against (e.g., '**/*.py', 'src/**/*.ts')"}, 'path': {'type': 'string', 'description': 'The base directory to search from (defaults to current working directory)'}, 'head_limit': {'type': 'integer', 'minimum': 0, 'description': 'Limit output to first N paths. Defaults to 250 when unspecified. Pass 0 for unlimited.'}, 'offset': {'type': 'integer', 'minimum': 0, 'default': 0, 'description': 'Number of matching files to skip before returning results'}}, 'required': ['pattern']}
is_mcpbool
是 MCP字段。
False
is_read_onlybool
`is_read_only` 字段。
True
is_concurrency_safebool
`is_concurrency_safe` 字段。
True
is_external_toolbool
是外部工具字段。
False
is_state_injectedbool
`is_state_injected` 字段。
False

方法摘要Method Summary

方法Method说明Description
async def check_permissions(tool_input: dict[str, Any], context: PermissionContext) -> PermissionDecisionasync
检查权限。
Check permissions for glob pattern matching.
async def match_rule(rule_content: str | None, tool_input: dict[str, Any]) -> boolasync
执行 `match_rule` 方法。
Check if a permission rule matches the glob pattern or path.
async def generate_suggestions(tool_input: dict[str, Any]) -> List[PermissionRule]async
设置该参数。
Generate suggested permission rules for the glob search.
async def call(pattern: str, path: str | None = None, head_limit: int | None = None, offset: int = 0) -> ToolChunkasync
向智能体发送输入并返回最终回复。
Execute the glob pattern matching and return the results.

构造器详情Constructor Detail

Glob

def __init__(backend: BackendBase | None = None, glob_helper_path: str | None = None, middlewares: List[ToolMiddlewareBase] | None = None) -> None

初始化 Glob 实例。

Initialize the glob tool.

参数Parameters
名称Name类型Type说明Description
backend默认default NoneBackendBase | Nonebackend(类型 `BackendBase | None`)。The sandbox backend to use. When `None`, a :class:`LocalBackend` is created automatically.
glob_helper_path默认default Nonestr | Noneglob helper 路径(类型 `str | None`)。Filesystem path (inside the backend's environment) to the `_glob_helper.py` script. When `None`, the path is resolved from the installed package resources (suitable for :class:`LocalBackend`). Remote backends (Docker, E2B) should pass the path where the script was deployed during workspace initialization.
middlewares默认default NoneList[ToolMiddlewareBase] | None中间件列表(类型 `List[ToolMiddlewareBase] | None`)。Tool middlewares wrapping the tool execution.
源码Source agentscope/tool/_builtin/_glob.py:99–133

属性详情Attribute Detail

name

str = 'Glob'

名称字段。声明为 str。

The name field.

源码Source agentscope/tool/_builtin/_glob.py:48

description

str = 'Fast file pattern matching tool that works with\nany codebase size.\n\nSupports glob patterns like "**/*.js" or "src/**/*.ts" and returns\nmatching file paths sorted by modification time (newest first).\n\nUse this tool when you need to find files by pattern across the\ncodebase.\n\nUse head_limit to cap the number of results returned.'

description 字段。声明为 str。

The description field.

源码Source agentscope/tool/_builtin/_glob.py:51

input_schema

dict[str, Any] = {'type': 'object', 'properties': {'pattern': {'type': 'string', 'description': "The glob pattern to match against (e.g., '**/*.py', 'src/**/*.ts')"}, 'path': {'type': 'string', 'description': 'The base directory to search from (defaults to current working directory)'}, 'head_limit': {'type': 'integer', 'minimum': 0, 'description': 'Limit output to first N paths. Defaults to 250 when unspecified. Pass 0 for unlimited.'}, 'offset': {'type': 'integer', 'minimum': 0, 'default': 0, 'description': 'Number of matching files to skip before returning results'}}, 'required': ['pattern']}

输入模式字段。声明为 dict[str, Any]。

The input schema field.

源码Source agentscope/tool/_builtin/_glob.py:63

is_mcp

bool = False

是 MCP字段。声明为 bool。

The is mcp field.

源码Source agentscope/tool/_builtin/_glob.py:93

is_read_only

bool = True

is_read_only 字段。声明为 bool。

The is read only field.

源码Source agentscope/tool/_builtin/_glob.py:94

is_concurrency_safe

bool = True

is_concurrency_safe 字段。声明为 bool。

The is concurrency safe field.

源码Source agentscope/tool/_builtin/_glob.py:95

is_external_tool

bool = False

是外部工具字段。声明为 bool。

The is external tool field.

源码Source agentscope/tool/_builtin/_glob.py:96

is_state_injected

bool = False

is_state_injected 字段。声明为 bool。

The is state injected field.

源码Source agentscope/tool/_builtin/_glob.py:97

方法详情Method Detail

check_permissions

async def check_permissions(tool_input: dict[str, Any], context: PermissionContext) -> PermissionDecision
async

检查权限。

Glob is a read-only tool.

参数Parameters
名称Name类型Type说明Description
tool_inputdict[str, Any]工具输入(类型 `dict[str, Any]`)。The tool input.
contextPermissionContext上下文(类型 `PermissionContext`)。The context.
返回Returns PermissionDecision
返回PermissionDecision。Returns permission decision.
源码Source agentscope/tool/_builtin/_glob.py:135–148

match_rule

async def match_rule(rule_content: str | None, tool_input: dict[str, Any]) -> bool
async

执行 match_rule 方法。

Matches rule_content as a glob pattern against the "pattern" or "path" parameters.

参数Parameters
名称Name类型Type说明Description
rule_contentstr | None规则内容(类型 `str | None`)。Glob pattern to match (e.g., "src/**" to match searches in src), or None to match all invocations
tool_inputdict[str, Any]工具输入(类型 `dict[str, Any]`)。The tool input data containing "pattern" and optional "path"
返回Returns bool
返回布尔值,表示判断结果。`bool`:
源码Source agentscope/tool/_builtin/_glob.py:150–187

generate_suggestions

async def generate_suggestions(tool_input: dict[str, Any]) -> List[PermissionRule]
async

设置该参数。

Suggests a rule based on the search path.

参数Parameters
名称Name类型Type说明Description
tool_inputdict[str, Any]工具输入(类型 `dict[str, Any]`)。The tool input data containing optional "path" key
返回Returns List[PermissionRule]
返回PermissionRule列表。`List[PermissionRule]`:
源码Source agentscope/tool/_builtin/_glob.py:189–222

call

async def call(pattern: str, path: str | None = None, head_limit: int | None = None, offset: int = 0) -> ToolChunk
async

向智能体发送输入并返回最终回复。

Invokes the standalone _glob_helper.py script via exec_shell.

参数Parameters
名称Name类型Type说明Description
patternstrpattern(类型 `str`)。The glob pattern to match against (e.g. `**/*.py`).
path默认default Nonestr | None路径(类型 `str | None`)。Base directory to search from. Defaults to the current working directory when `None`.
head_limit默认default Noneint | Nonehead 限制(类型 `int | None`)。Maximum number of matching paths to return. Defaults to `250`. Pass `0` for unlimited.
offset默认default 0int偏移量(类型 `int`)。Number of matching paths to skip before returning results. Defaults to `0`.
返回Returns ToolChunk
返回ToolChunk。`ToolChunk`:
源码Source agentscope/tool/_builtin/_glob.py:224–365

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.