类class
agentscope.stateToolContext
class ToolContext(BaseModel)
源码Source
agentscope/state/_state.py:32–172工具上下文,在多次调用之间保存和恢复会话与记忆数据。位于 agentscope.state 包。核心成员包括 get_cache、cache_file、clean_file_cache。
The tool context, e.g. Declared in agentscope.state.
属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
max_cache_files | int | 最大缓存文件字段。 | Field(default=100, gt=1) |
max_cache_bytes | float | 最大缓存字节字段。 | Field(default=25000, gt=10000) |
read_file_cache | list[ReadCacheEntry] | 读取文件缓存字段。 | Field(default_factory=list) |
activated_groups | list[str] | `activated_groups` 字段。 | Field(default_factory=list) |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
async def get_cache(file_path: str, mtime: float | None = None) -> ReadCacheEntry | Noneasync | 获取缓存。 Get cached file content if still valid. |
async def cache_file(file_path: str, lines: list[str], mtime: float | None = None) -> Noneasync | 执行缓存文件相关操作。 Cache file content with LRU eviction. |
async def clean_file_cache(reserved_file_paths: set[str] | None = None) -> Noneasync | 设置干净文件缓存。 Drop read caches whose paths are not in ``reserved_file_paths``. |
属性详情Attribute Detail
max_cache_files
int = Field(default=100, gt=1)最大缓存文件字段。声明为 int。
The max cache files field.
源码Source
agentscope/state/_state.py:35max_cache_bytes
float = Field(default=25000, gt=10000)最大缓存字节字段。声明为 float。
The max cache bytes field.
源码Source
agentscope/state/_state.py:37read_file_cache
list[ReadCacheEntry] = Field(default_factory=list)读取文件缓存字段。声明为 list[ReadCacheEntry]。
The read file cache field.
源码Source
agentscope/state/_state.py:39activated_groups
list[str] = Field(default_factory=list)activated_groups 字段。声明为 list[str]。
The activated groups field.
源码Source
agentscope/state/_state.py:42方法详情Method Detail
get_cache
async def get_cache(file_path: str, mtime: float | None = None) -> ReadCacheEntry | None
async
获取缓存。
Get cached file content if still valid.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
file_path | str | 文件路径(类型 `str`)。The absolute path of the file. |
mtime默认default None | float | None | mtime(类型 `float | None`)。The file's modification time, obtained from the same filesystem that read the file, e.g. a workspace backend. Falls back to the host filesystem when not provided. |
ReadCacheEntry | None
返回ReadCacheEntry|None。`ReadCacheEntry | None`:
源码Source
agentscope/state/_state.py:46–88cache_file
async def cache_file(file_path: str, lines: list[str], mtime: float | None = None) -> None
async
执行缓存文件相关操作。
Cache file content with LRU eviction.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
file_path | str | 文件路径(类型 `str`)。The absolute path of the file. |
lines | list[str] | lines(类型 `list[str]`)。The lines of the file content. |
mtime默认default None | float | None | mtime(类型 `float | None`)。The file's modification time, obtained from the same filesystem that read the file, e.g. a workspace backend. Falls back to the host filesystem when not provided. |
None
无返回值。No value is returned.
源码Source
agentscope/state/_state.py:90–153clean_file_cache
async def clean_file_cache(reserved_file_paths: set[str] | None = None) -> None
async
设置干净文件缓存。
Drop read caches whose paths are not in reserved_file_paths.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
reserved_file_paths默认default None | set[str] | None | reserved 文件 paths(类型 `set[str] | None`)。File paths from Read calls that remain in the context. Caches for these files are kept; all others are evicted. |
None
无返回值。No value is returned.
源码Source
agentscope/state/_state.py:155–172