agentscope-ai / agentscope-ai/agentscope
[Bug]: Glob can overflow agent context with unbounded output
- Dominant language
- Python
- Stars
- 31.5k
- Forks
- 3.5k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 95
Description
### Describe the bug
The built-in `Glob` tool currently joins every matching file path into one tool result. For a broad pattern such as `**/*`, the result can grow with the entire workspace and add an unnecessarily large message to the agent context.
The built-in `Grep` tool already has a default `head_limit` of 250 entries and supports `offset`, but `Glob` has no equivalent default result limit or pagination mechanism.
This is not an exception. The problem is that the tool has no default result limit and no pagination mechanism:
```text
broad Glob pattern
|
+-- match 1
+-- match 2
+-- ...
+-- match 201
|
+-- current: all paths are returned in one result
+-- expected: a bounded page with a way to fetch more
```
### To reproduce
1. Create more than 200 files matching the same pattern.
2. Call the built-in `Glob` tool without an explicit result limit:
```python
result = await Glob()(pattern="match_*.log", path="/tmp/workspace")
```
3. Observe that every matching path is returned in one result and no truncation guidance is provided.
Example observation with 201 matching files:
```text
matched_paths=201
truncation_notice=False
```
No exception is raised.
### Expected behavior
`Glob` output should remain bounded even when the caller omits optional arguments:
- enforce a tool-side default result limit;
- allow callers to request a smaller or larger page within a hard cap;
- include an explicit truncation notice when more matches exist;
- provide a way to request later pages.
### Additional context
The proposed defaults for `Glob` are a default limit of 200 paths and a hard maximum of 1000 paths. The proposed first version applies the limit at the tool-output boundary; moving the limit into helper traversal can be handled as a separate optimization.
Contributor guide
Assessment
This issue has not been assessed yet.