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

ContextConfig

class ContextConfig(BaseModel)
源码Source agentscope/agent/_config.py:51–192

AgentScope 的上下文相关配置。位于 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_ratiofloat
`trigger_ratio` 字段。
Field(default=0.8, gt=0, le=0.9)
reserve_ratiofloat
`reserve_ratio` 字段。
Field(default=0.1, gt=0, lt=0.9)
context_buffer_ratiofloat
`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_promptstr
压缩提示词字段。
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_templatestr
摘要模板字段。
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_schemadict
摘要模式字段。
Field(default_factory=SummarySchema.model_json_schema)
tool_result_limitint
工具结果限制字段。
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_truncationbool
`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_enabledbool
压缩工具已启用字段。
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_numint
`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.

源码Source agentscope/agent/_config.py:54

trigger_ratio

float = Field(default=0.8, gt=0, le=0.9)

trigger_ratio 字段。声明为 float。

The trigger ratio field.

源码Source agentscope/agent/_config.py:57

reserve_ratio

float = Field(default=0.1, gt=0, lt=0.9)

reserve_ratio 字段。声明为 float。

The reserve ratio field.

源码Source agentscope/agent/_config.py:62

context_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.

源码Source agentscope/agent/_config.py:66

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'})

压缩提示词字段。声明为 str。

The compression prompt field.

源码Source agentscope/agent/_config.py:82

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'})

摘要模板字段。声明为 str。

The summary template field.

源码Source agentscope/agent/_config.py:119

summary_schema

dict = Field(default_factory=SummarySchema.model_json_schema)

摘要模式字段。声明为 dict。

The summary schema field.

源码Source agentscope/agent/_config.py:140

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.')

工具结果限制字段。声明为 int。

The maximum length of the tool results in tokens.

源码Source agentscope/agent/_config.py:146

compression_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.

源码Source agentscope/agent/_config.py:156

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.')

压缩工具已启用字段。声明为 bool。

Whether to expose a context compression tool to the agent.

源码Source agentscope/agent/_config.py:168

max_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.

源码Source agentscope/agent/_config.py:179
基于官方固定版本源码静态生成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.