agentscope.agentContextConfig
class ContextConfig(BaseModel)
agentscope/agent/_config.py:51–192AgentScope 的上下文相关配置。位于 agentscope.agent 包。
The context related configuration in AgentScope Declared in agentscope.agent.
属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
model_config | — | 模型配置字段。 | {'arbitrary_types_allowed': True} |
trigger_ratio | float | `trigger_ratio` 字段。 | Field(default=0.8, gt=0, le=0.9) |
reserve_ratio | float | `reserve_ratio` 字段。 | Field(default=0.1, gt=0, lt=0.9) |
context_buffer_ratio | float | `context_buffer_ratio` 字段。 | Field(title='Context Buffer', default=0.2, ge=0, le=1, description="The buffer ahead of the 'trigger_ratio', within which the agent is told that a compression is near, and can compress by itself if the compression tool is enabled. It must be smaller than the 'trigger_ratio'.") |
compression_prompt | str | 压缩提示词字段。 | Field(default="<system-hint>You have been working on the task described above. Now write a continuation summary that will allow you to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable.\nThe current time is {current_time}.\nThis summary may itself be summarized again later, and the conversation history it refers to will be gone, so every reference must be self-contained — resolve anything that depends on the vanished context into an absolute, fully-qualified form:\n- Time: convert relative expressions ('today', 'now', 'yesterday', 'tomorrow', 'recently') to absolute dates using the current time above; re-anchor them even if an earlier summary already wrote them relatively.\n- Names & pointers: use file paths, symbol names, PR/issue numbers, IDs, URLs, and exact commands/error strings verbatim instead of 'this file', 'the above', 'the second approach', 'the 5 failing tests'.\n- In-flight work: record everything still pending, especially tools launched in the background whose results you are still waiting on — give each one's id and a short note of what it is doing — and mark each item's owner (user request vs your own decision) and status (done / pending / blocked).\n</system-hint>", json_schema_extra={'format': 'textarea'}) |
summary_template | str | 摘要模板字段。 | Field(default='<system-info>Here is a summary of your previous work\n# Task Overview\n{task_overview}\n\n# Current State\n{current_state}\n\n# Important Discoveries\n{important_discoveries}\n\n# Next Steps\n{next_steps}\n\n# Context to Preserve\n{context_to_preserve}</system-info>', json_schema_extra={'format': 'textarea'}) |
summary_schema | dict | 摘要模式字段。 | Field(default_factory=SummarySchema.model_json_schema) |
tool_result_limit | int | 工具结果限制字段。 | Field(title='Tool Result Limit', default=50000, description='The maximum length of the tool results in tokens. If exceeded, the tool result will be truncated.') |
compression_fallback_to_truncation | bool | `compression_fallback_to_truncation` 字段。 | Field(default=True, description='Whether to truncate the oldest context when the compression summary cannot be generated. Turning it off raises the error instead, keeping the context intact at the cost of exceeding the context length.') |
compression_tool_enabled | bool | 压缩工具已启用字段。 | Field(default=False, description='Whether to expose a context compression tool to the agent. When runtime-state injection is enabled, the agent is prompted to use the tool between tasks as the context approaches the hard compression threshold.') |
max_image_num | int | `max_image_num` 字段。 | Field(title='Max Image Number', default=5, ge=0, description='The maximum number of images kept in the context. The oldest images exceeding the limit will be removed.') |
属性详情Attribute Detail
model_config
= {'arbitrary_types_allowed': True}模型配置字段。
The model config field.
agentscope/agent/_config.py:54trigger_ratio
float = Field(default=0.8, gt=0, le=0.9)trigger_ratio 字段。声明为 float。
The trigger ratio field.
agentscope/agent/_config.py:57reserve_ratio
float = Field(default=0.1, gt=0, lt=0.9)reserve_ratio 字段。声明为 float。
The reserve ratio field.
agentscope/agent/_config.py:62context_buffer_ratio
float = Field(title='Context Buffer', default=0.2, ge=0, le=1, description="The buffer ahead of the 'trigger_ratio', within which the agent is told that a compression is near, and can compress by itself if the compression tool is enabled. It must be smaller than the 'trigger_ratio'.")context_buffer_ratio 字段。声明为 float。
The buffer ahead of the 'trigger_ratio', within which the agent is told that a compression is near, and can compress by itself if the compression tool is enabled.
agentscope/agent/_config.py:66compression_prompt
str = Field(default="<system-hint>You have been working on the task described above. Now write a continuation summary that will allow you to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable.\nThe current time is {current_time}.\nThis summary may itself be summarized again later, and the conversation history it refers to will be gone, so every reference must be self-contained — resolve anything that depends on the vanished context into an absolute, fully-qualified form:\n- Time: convert relative expressions ('today', 'now', 'yesterday', 'tomorrow', 'recently') to absolute dates using the current time above; re-anchor them even if an earlier summary already wrote them relatively.\n- Names & pointers: use file paths, symbol names, PR/issue numbers, IDs, URLs, and exact commands/error strings verbatim instead of 'this file', 'the above', 'the second approach', 'the 5 failing tests'.\n- In-flight work: record everything still pending, especially tools launched in the background whose results you are still waiting on — give each one's id and a short note of what it is doing — and mark each item's owner (user request vs your own decision) and status (done / pending / blocked).\n</system-hint>", json_schema_extra={'format': 'textarea'})压缩提示词字段。声明为 str。
The compression prompt field.
agentscope/agent/_config.py:82summary_template
str = Field(default='<system-info>Here is a summary of your previous work\n# Task Overview\n{task_overview}\n\n# Current State\n{current_state}\n\n# Important Discoveries\n{important_discoveries}\n\n# Next Steps\n{next_steps}\n\n# Context to Preserve\n{context_to_preserve}</system-info>', json_schema_extra={'format': 'textarea'})摘要模板字段。声明为 str。
The summary template field.
agentscope/agent/_config.py:119summary_schema
dict = Field(default_factory=SummarySchema.model_json_schema)摘要模式字段。声明为 dict。
The summary schema field.
agentscope/agent/_config.py:140tool_result_limit
int = Field(title='Tool Result Limit', default=50000, description='The maximum length of the tool results in tokens. If exceeded, the tool result will be truncated.')工具结果限制字段。声明为 int。
The maximum length of the tool results in tokens.
agentscope/agent/_config.py:146compression_fallback_to_truncation
bool = Field(default=True, description='Whether to truncate the oldest context when the compression summary cannot be generated. Turning it off raises the error instead, keeping the context intact at the cost of exceeding the context length.')compression_fallback_to_truncation 字段。声明为 bool。
Whether to truncate the oldest context when the compression summary cannot be generated.
agentscope/agent/_config.py:156compression_tool_enabled
bool = Field(default=False, description='Whether to expose a context compression tool to the agent. When runtime-state injection is enabled, the agent is prompted to use the tool between tasks as the context approaches the hard compression threshold.')压缩工具已启用字段。声明为 bool。
Whether to expose a context compression tool to the agent.
agentscope/agent/_config.py:168max_image_num
int = Field(title='Max Image Number', default=5, ge=0, description='The maximum number of images kept in the context. The oldest images exceeding the limit will be removed.')max_image_num 字段。声明为 int。
The maximum number of images kept in the context.
agentscope/agent/_config.py:179