agentscope.agentReActConfig
class ReActConfig(BaseModel)
agentscope/agent/_config.py:362–412ReActConfig 描述一次回复内推理—行动循环的策略:最多迭代多少次、结构化输出失败后给多少宽限、被拒绝或中断时如何结束。位于 agentscope.agent 包。
The reasoning related configuration Declared in agentscope.agent.
核心精讲Deep dive
ReActConfig:循环策略ReActConfig: loop policy
ReActConfig 描述一次回复内推理—行动循环的策略:最多迭代多少次、结构化输出失败后给多少宽限、被拒绝或中断时如何结束。
ReActConfig describes the policy of the reasoning-acting loop: how many iterations to allow, how much grace to give structured output, and how to end when a tool call is rejected or the reply is interrupted.
- max_iters 默认 50,按“一次模型调用 + 一次工具执行”计一轮。max_iters defaults to 50, counting one model call plus one tool execution as one iteration.
- structured_output_grace_iters 在超出迭代上限后仍允许模型补交结构化结果。structured_output_grace_iters lets the model submit a structured result after the iteration limit is reached.
- stop_on_reject 与 interruption_message 决定权限拒绝和用户中断后的收尾方式。stop_on_reject and interruption_message decide how the reply ends after a permission rejection or user interruption.
收紧循环预算Tighten the loop budget
import os
from agentscope.agent import Agent, ReActConfig
from agentscope.credential import OpenAICredential
from agentscope.model import OpenAIChatModel
model = OpenAIChatModel(
credential=OpenAICredential(api_key=os.environ["OPENAI_API_KEY"]),
model="gpt-4.1-mini",
)
agent = Agent(
name="assistant",
system_prompt="You are a careful analyst.",
model=model,
react_config=ReActConfig(
max_iters=6,
structured_output_grace_iters=2,
stop_on_reject=True,
interruption_message="Stopped by the user.",
),
)属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
max_iters | int | 单次回复允许的最大推理—行动迭代次数。 | Field(title='Max Iterations', default=50, description='The maximum number of reasoning-acting iterations in one reply') |
structured_output_grace_iters | int | 超出迭代上限后,仍允许模型补交结构化结果的轮数。 | Field(title='Grace Iters for Structured Output', description='The grace iterations for structured output when exceeding the max iterations', default=5, gt=0) |
stop_on_reject | bool | 工具调用被拒绝时是否立即结束回复。 | Field(title='Rejection Handling', default=False, description='Whether to stop replying when being rejected to execute tools.') |
interruption_message | str | 用户中断回复时返回的提示消息。 | Field(title='Interruption Message', default='I notice the interruption. How can I help you?', description='The quick reply message when interrupted.') |
interruption_raise_cancelled_error | bool | 处理中断后是否继续抛出 CancelledError。 | Field(title='Raise CancelledError on Interruption', default=False, description='Whether to re-raise ``asyncio.CancelledError`` after handling the interruption. When ``False``, the ``CancelledError`` is swallowed once the interruption context has been produced.') |
属性详情Attribute Detail
max_iters
int = Field(title='Max Iterations', default=50, description='The maximum number of reasoning-acting iterations in one reply')最大迭代次数字段。声明为 int。
The maximum number of reasoning-acting iterations in one reply
agentscope/agent/_config.py:365structured_output_grace_iters
int = Field(title='Grace Iters for Structured Output', description='The grace iterations for structured output when exceeding the max iterations', default=5, gt=0)结构化输出宽限迭代次数字段。声明为 int。
The grace iterations for structured output when exceeding the max iterations
agentscope/agent/_config.py:373stop_on_reject
bool = Field(title='Rejection Handling', default=False, description='Whether to stop replying when being rejected to execute tools.')拒绝时停止字段。声明为 bool。
Whether to stop replying when being rejected to execute tools.
agentscope/agent/_config.py:385interruption_message
str = Field(title='Interruption Message', default='I notice the interruption. How can I help you?', description='The quick reply message when interrupted.')中断消息字段。声明为 str。
The quick reply message when interrupted.
agentscope/agent/_config.py:395interruption_raise_cancelled_error
bool = Field(title='Raise CancelledError on Interruption', default=False, description='Whether to re-raise ``asyncio.CancelledError`` after handling the interruption. When ``False``, the ``CancelledError`` is swallowed once the interruption context has been produced.')interruption_raise_cancelled_error 字段。声明为 bool。
Whether to re-raise asyncio.CancelledError after handling the interruption.
agentscope/agent/_config.py:402