Builder
@SuppressWarnings("deprecation") public static class Builder
io/agentscope/core/ReActAgent.java:4798–5657链式配置 ReActAgent 的名称、模型、工具、状态存储、权限与中间件,最后调用 build() 得到实例。位于 io.agentscope.core 包。核心成员包括 name、description、checkRunning、sysPrompt、model、toolkit。
A class in io.agentscope.core that drives agent reasoning, tool calls and conversation execution. Declared in io.agentscope.core.
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Builder name(String name) | 设置智能体名称。 Sets the name for this agent. |
public Builder description(String description) | 设置智能体描述。 Performs the description operation. |
public Builder checkRunning(boolean checkRunning)deprecated | 设置检查运行中。 Performs the check running operation. |
public Builder sysPrompt(String sysPrompt) | 设置系统提示词。 Sets the system prompt for this agent. |
public Builder model(Model model) | 设置聊天模型,可传模型实例或模型 ID。 Sets the language model for this agent. |
public Builder model(String modelId) | 设置聊天模型,可传模型实例或模型 ID。 Configures the model from a string id resolved via `ModelRegistry`: a named
registration (`ModelRegistry#register(String, Model)`) or an extension provider
pattern such as `openai:gpt-5.5`, `dashscope:qwen-max`, `
anthropic:claude-sonnet-4-5`, `gemini:gemini-2.0-flash`, or `ollama:llama3`. |
public Builder toolkit(Toolkit toolkit) | 设置工具注册表。 Sets the toolkit containing available tools for this agent. |
public Builder maxIters(int maxIters) | 设置推理—行动循环的最大迭代次数。 Sets the maximum number of reasoning-acting iterations. |
public Builder hook(Hook hook) | 设置钩子。 Adds a hook for monitoring and intercepting agent execution events. |
public Builder hooks(List<Hook> hooks) | 设置该配置项。 Adds multiple hooks for monitoring and intercepting agent execution events. |
public Builder middleware(MiddlewareBase middleware) | 追加一个中间件。 Adds a middleware for intercepting agent execution. |
public Builder middlewares(List<? extends MiddlewareBase> middlewares) | 批量设置中间件。 Adds multiple middlewares for intercepting agent execution. |
public Builder enableMetaTool(boolean enableMetaTool) | 启用元数据工具。 Enables or disables the meta-tool functionality. |
public Builder enableTaskList() | 启用任务列表。 Enables the built-in task-list capability (`todo_write` tool + per-turn reminder). |
public Builder enableTaskList(boolean enabled) | 启用任务列表。 Enables or disables the built-in task-list capability. |
public Builder enablePendingToolRecovery(boolean enable) | 启用该配置。 Enables or disables automatic recovery from orphaned pending tool calls. |
public Builder modelExecutionConfig(ExecutionConfig modelExecutionConfig) | 设置执行配置用于模型 API 调用。 Sets the execution configuration for model API calls. |
public Builder toolExecutionConfig(ExecutionConfig toolExecutionConfig) | 设置工具执行配置。 Sets the execution configuration for tool executions. |
public Builder generateOptions(GenerateOptions generateOptions) | 设置该配置项。 Sets the generation options for model API calls. |
public Builder toolExecutionContext(ToolExecutionContext toolExecutionContext)deprecated | 设置工具执行上下文用于此智能体。 Sets the tool execution context for this agent. |
public Builder stateStore(AgentStateStore stateStore) | 设置跨会话的状态存储。 Sets the `AgentStateStore` backing automatic AgentState load (at construction) and save
(after every successful `call()` and on graceful shutdown). |
public Builder conflictPolicy(ConflictPolicy conflictPolicy) | 设置该配置项。 Sets the policy applied when an optimistic-concurrency save of `agent_state`
conflicts with another writer's update. |
public Builder defaultSessionId(String sessionId) | 设置默认会话 ID。 Sets the builder-time fallback `sessionId` used to persist `agent_state`
when a call does not supply a `sessionId` on its `RuntimeContext`. |
public Builder maxRetries(int maxRetries) | 设置最大重试。 Sets the model-call retry budget (max attempts including the first try). |
public Builder fallbackModel(Model fallbackModel) | 设置回退模型。 Sets the fallback model invoked after the primary model exhausts its retry budget. |
public Builder fallbackModel(String modelId) | 设置回退模型。 Convenience overload that resolves `modelId` via
`io.agentscope.core.model.ModelRegistry#resolve(String)` (named registration or
`provider:model` pattern like `openai:gpt-5.5`, `dashscope:qwen-max`). |
public Builder failoverListener(FailoverListener failoverListener) | 设置故障转移监听器。 Sets the listener notified when the fallback model takes over from a failed primary
model. |
public Builder stopOnReject(boolean stopOnReject) | 设置停止 On 拒绝。 Controls whether a permission rejection of any tool call terminates the reasoning loop
(instead of feeding the rejection back into the next reasoning round). |
public Builder permissionContext(PermissionContextState permissionContext) | 设置权限上下文。 Sets the `PermissionContextState` consulted by the `PermissionEngine` during tool
execution. |
public Builder longTermMemory(LongTermMemory longTermMemory)deprecated | 设置该配置项。 Performs the long term memory operation. |
public Builder longTermMemoryMode(LongTermMemoryMode mode)deprecated | 设置该配置项。 Performs the long term memory mode operation. |
public Builder longTermMemoryAsyncRecord(boolean asyncRecord)deprecated | 设置该配置项。 Performs the long term memory async record operation. |
public Builder knowledge(Knowledge knowledge)deprecated | 挂载一个知识库用于 RAG。 Performs the knowledge operation. |
public Builder knowledges(List<Knowledge> knowledges)deprecated | 设置该配置项。 Performs the knowledges operation. |
public Builder ragMode(RAGMode mode)deprecated | 选择知识库的注入模式。 Performs the rag mode operation. |
public Builder retrieveConfig(RetrieveConfig config)deprecated | 设置检索配置。 Retrieves the config. |
public Builder skillBox(SkillBox skillBox)deprecated | 设置该配置项。 Performs the skill box operation. |
public Builder skillRepository(AgentSkillRepository repo) | 设置技能仓库。 Adds a single `AgentSkillRepository` to the layered skill stack. |
public Builder skillRepositories(List<AgentSkillRepository> repos) | 设置该配置项。 Replaces the current repository list with the supplied collection. |
public Builder skillFilter(SkillFilter filter) | 设置技能过滤器。 Builder-time `SkillFilter` applied by the auto-installed
`DynamicSkillMiddleware`. |
public Builder dynamicSkillsEnabled(boolean enabled) | 设置该配置项。 Toggles automatic installation of `DynamicSkillMiddleware`. |
public Builder skillCodeExecutionEnabled(boolean enabled) | 设置该配置项。 Enables the code-execution prompt block emitted by
`io.agentscope.core.skill.AgentSkillPromptProvider`. |
public Builder skillWorkDir(Path dir) | 设置该配置项。 Sets a stable working directory used by `DynamicSkillMiddleware` for
`uploadSkillFiles`. |
public static Builder fromAgent(ReActAgent agent)static | 设置来自智能体。 Returns a new `Builder` pre-populated with the given agent's observable
configuration: name, description, system prompt, model, maxIters, generateOptions, and
a defensive copy of the toolkit. |
public ReActAgent build() | 构建 ReActAgent 实例。 Builds and returns a new ReActAgent instance with the configured settings. |
方法详情Method Detail
name
public Builder name(String name)
设置名称用于此智能体。
Sets the name for this agent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 智能体名称。The agent name, must not be null |
Builderio/agentscope/core/ReActAgent.java:4888–4891description
public Builder description(String description)
设置该配置项。
Performs the description operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
description | String | 描述(类型 `String`)。The description. |
Builderio/agentscope/core/ReActAgent.java:4893–4896checkRunning
public Builder checkRunning(boolean checkRunning)
设置检查运行中。
Performs the check running operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
checkRunning | boolean | 检查运行中(类型 `boolean`)。The check running. |
Builderio/agentscope/core/ReActAgent.java:4899–4902sysPrompt
public Builder sysPrompt(String sysPrompt)
设置系统提示词用于此智能体。
Sets the system prompt for this agent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sysPrompt | String | 系统提示词。The system prompt, can be null or empty |
Builderio/agentscope/core/ReActAgent.java:4910–4913model
public Builder model(Model model)
设置模型。
Sets the language model for this agent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
model | Model | 聊天模型实例或模型 ID。The language model to use for reasoning, must not be null |
Builderio/agentscope/core/ReActAgent.java:4921–4924model
public Builder model(String modelId)
设置模型。
Configures the model from a string id resolved via ModelRegistry: a named registration (ModelRegistry#register(String, Model)) or an extension provider pattern such as openai:gpt-5.5, dashscope:qwen-max, anthropic:claude-sonnet-4-5, gemini:gemini-2.0-flash, or `olla…
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelId | String | 模型标识(类型 `String`)。registry id or `provider:model` string |
BuilderIllegalArgumentException可能抛出 `IllegalArgumentException`。if the id cannot be resolved
io/agentscope/core/ReActAgent.java:4937–4940toolkit
public Builder toolkit(Toolkit toolkit)
设置工具包。
Sets the toolkit containing available tools for this agent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolkit | Toolkit | 工具注册表。The toolkit with available tools, must not be null |
Builderio/agentscope/core/ReActAgent.java:4951–4954maxIters
public Builder maxIters(int maxIters)
设置最大迭代次数。
Sets the maximum number of reasoning-acting iterations.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
maxIters | int | 推理—行动循环的最大迭代次数。Maximum iterations, must be positive |
Builderio/agentscope/core/ReActAgent.java:4962–4965hook
public Builder hook(Hook hook)
设置钩子。
Adds a hook for monitoring and intercepting agent execution events.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
hook | Hook | 钩子(类型 `Hook`)。The hook to add, must not be null |
Builderio/agentscope/core/ReActAgent.java:4979–4982hooks
public Builder hooks(List<Hook> hooks)
设置该配置项。
Adds multiple hooks for monitoring and intercepting agent execution events.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
hooks | List<Hook> | hooks(类型 `List`)。The list of hooks to add, must not be null |
Builderio/agentscope/core/ReActAgent.java:4995–4998middleware
public Builder middleware(MiddlewareBase middleware)
设置中间件。
Adds a middleware for intercepting agent execution.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
middleware | MiddlewareBase | 中间件到添加。the middleware to add |
Builderio/agentscope/core/ReActAgent.java:5006–5009middlewares
public Builder middlewares(List<? extends MiddlewareBase> middlewares)
设置该配置项。
Adds multiple middlewares for intercepting agent execution.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
middlewares | List<? extends MiddlewareBase> | 中间件列表(类型 `List`)。the list of middlewares to add |
Builderio/agentscope/core/ReActAgent.java:5017–5020enableMetaTool
public Builder enableMetaTool(boolean enableMetaTool)
启用元数据工具。
Enables or disables the meta-tool functionality.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
enableMetaTool | boolean | 启用元数据工具(类型 `boolean`)。true to enable meta-tool, false to disable |
Builderio/agentscope/core/ReActAgent.java:5032–5035enableTaskList
public Builder enableTaskList()
启用任务列表。
Enables the built-in task-list capability (todo_write tool + per-turn reminder).
Builderio/agentscope/core/ReActAgent.java:5044–5046enableTaskList
public Builder enableTaskList(boolean enabled)
启用任务列表。
Enables or disables the built-in task-list capability.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
enabled | boolean | 已启用(类型 `boolean`)。true to enable the task list |
Builderio/agentscope/core/ReActAgent.java:5059–5062enablePendingToolRecovery
public Builder enablePendingToolRecovery(boolean enable)
启用该配置。
Enables or disables automatic recovery from orphaned pending tool calls.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
enable | boolean | 启用(类型 `boolean`)。true to enable auto-recovery, false to disable |
Builderio/agentscope/core/ReActAgent.java:5077–5080modelExecutionConfig
public Builder modelExecutionConfig(ExecutionConfig modelExecutionConfig)
设置执行配置用于模型 API 调用。
Sets the execution configuration for model API calls.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelExecutionConfig | ExecutionConfig | 模型执行配置(类型 `ExecutionConfig`)。The execution configuration for model calls, can be null |
Builderio/agentscope/core/ReActAgent.java:5093–5096toolExecutionConfig
public Builder toolExecutionConfig(ExecutionConfig toolExecutionConfig)
设置工具执行配置。
Sets the execution configuration for tool executions.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolExecutionConfig | ExecutionConfig | 工具执行配置(类型 `ExecutionConfig`)。The execution configuration for tool calls, can be null |
Builderio/agentscope/core/ReActAgent.java:5109–5112generateOptions
public Builder generateOptions(GenerateOptions generateOptions)
设置该配置项。
Sets the generation options for model API calls.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
generateOptions | GenerateOptions | generate 选项(类型 `GenerateOptions`)。The generation options for model calls, can be null |
Builderio/agentscope/core/ReActAgent.java:5142–5145toolExecutionContext
public Builder toolExecutionContext(ToolExecutionContext toolExecutionContext)
设置工具执行上下文用于此智能体。
Sets the tool execution context for this agent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolExecutionContext | ToolExecutionContext | 工具执行上下文。The tool execution context |
Builderio/agentscope/core/ReActAgent.java:5155–5159stateStore
public Builder stateStore(AgentStateStore stateStore)
设置状态存储。
Sets the AgentStateStore backing automatic AgentState load (at construction) and save (after every successful call() and on graceful shutdown).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stateStore | AgentStateStore | 会话状态存储。The state store. |
Builderio/agentscope/core/ReActAgent.java:5166–5169conflictPolicy
public Builder conflictPolicy(ConflictPolicy conflictPolicy)
设置该配置项。
Sets the policy applied when an optimistic-concurrency save of agent_state conflicts with another writer's update.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
conflictPolicy | ConflictPolicy | conflict 策略(类型 `ConflictPolicy`)。The conflict policy. |
Builderio/agentscope/core/ReActAgent.java:5176–5179defaultSessionId
public Builder defaultSessionId(String sessionId)
设置默认会话标识。
Sets the builder-time fallback sessionId used to persist agent_state when a call does not supply a sessionId on its RuntimeContext.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识(类型 `String`)。The session id. |
Builderio/agentscope/core/ReActAgent.java:5187–5190maxRetries
public Builder maxRetries(int maxRetries)
设置最大重试。
Sets the model-call retry budget (max attempts including the first try).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
maxRetries | int | 最大重试(类型 `int`)。The max retries. |
Builderio/agentscope/core/ReActAgent.java:5196–5202fallbackModel
public Builder fallbackModel(Model fallbackModel)
设置回退模型。
Sets the fallback model invoked after the primary model exhausts its retry budget.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
fallbackModel | Model | 回退模型(类型 `Model`)。The fallback model. |
Builderio/agentscope/core/ReActAgent.java:5208–5211fallbackModel
public Builder fallbackModel(String modelId)
设置回退模型。
Convenience overload that resolves modelId via io.agentscope.core.model.ModelRegistry#resolve(String) (named registration or provider:model pattern like openai:gpt-5.5, dashscope:qwen-max).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelId | String | 模型标识(类型 `String`)。The model id. |
BuilderIllegalArgumentException可能抛出 `IllegalArgumentException`。if the id cannot be resolved
io/agentscope/core/ReActAgent.java:5220–5223failoverListener
public Builder failoverListener(FailoverListener failoverListener)
设置故障转移监听器。
Sets the listener notified when the fallback model takes over from a failed primary model.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
failoverListener | FailoverListener | 故障转移监听器(类型 `FailoverListener`)。The failover listener. |
Builderio/agentscope/core/ReActAgent.java:5231–5234stopOnReject
public Builder stopOnReject(boolean stopOnReject)
设置停止 On 拒绝。
Controls whether a permission rejection of any tool call terminates the reasoning loop (instead of feeding the rejection back into the next reasoning round).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stopOnReject | boolean | 停止 On 拒绝(类型 `boolean`)。The stop on reject. |
Builderio/agentscope/core/ReActAgent.java:5241–5244permissionContext
public Builder permissionContext(PermissionContextState permissionContext)
设置权限上下文。
Sets the PermissionContextState consulted by the PermissionEngine during tool execution.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
permissionContext | PermissionContextState | 权限上下文(类型 `PermissionContextState`)。The permission context. |
Builderio/agentscope/core/ReActAgent.java:5250–5253longTermMemory
public Builder longTermMemory(LongTermMemory longTermMemory)
设置该配置项。
Performs the long term memory operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
longTermMemory | LongTermMemory | long Term 记忆(类型 `LongTermMemory`)。The long term memory. |
Builderio/agentscope/core/ReActAgent.java:5265–5269longTermMemoryMode
public Builder longTermMemoryMode(LongTermMemoryMode mode)
设置该配置项。
Performs the long term memory mode operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
mode | LongTermMemoryMode | 模式(类型 `LongTermMemoryMode`)。The mode. |
Builderio/agentscope/core/ReActAgent.java:5274–5278longTermMemoryAsyncRecord
public Builder longTermMemoryAsyncRecord(boolean asyncRecord)
设置该配置项。
Performs the long term memory async record operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
asyncRecord | boolean | 异步记录(类型 `boolean`)。The async record. |
Builderio/agentscope/core/ReActAgent.java:5283–5287knowledge
public Builder knowledge(Knowledge knowledge)
设置知识库。
Performs the knowledge operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
knowledge | Knowledge | 用于 RAG 的知识库。The knowledge. |
Builderio/agentscope/core/ReActAgent.java:5292–5298knowledges
public Builder knowledges(List<Knowledge> knowledges)
设置该配置项。
Performs the knowledges operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
knowledges | List<Knowledge> | knowledges(类型 `List`)。The knowledges. |
Builderio/agentscope/core/ReActAgent.java:5303–5309ragMode
public Builder ragMode(RAGMode mode)
设置该配置项。
Performs the rag mode operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
mode | RAGMode | 模式(类型 `RAGMode`)。The mode. |
Builderio/agentscope/core/ReActAgent.java:5314–5320retrieveConfig
public Builder retrieveConfig(RetrieveConfig config)
设置检索配置。
Retrieves the config.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
config | RetrieveConfig | 配置对象(类型 `RetrieveConfig`)。The config. |
Builderio/agentscope/core/ReActAgent.java:5325–5331skillBox
public Builder skillBox(SkillBox skillBox)
设置该配置项。
Performs the skill box operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
skillBox | SkillBox | 技能 Box(类型 `SkillBox`)。The skill box. |
Builderio/agentscope/core/ReActAgent.java:5340–5344skillRepository
public Builder skillRepository(AgentSkillRepository repo)
设置技能仓库。
Adds a single AgentSkillRepository to the layered skill stack.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
repo | AgentSkillRepository | 仓库(类型 `AgentSkillRepository`)。The repo. |
Builderio/agentscope/core/ReActAgent.java:5356–5361skillRepositories
public Builder skillRepositories(List<AgentSkillRepository> repos)
设置该配置项。
Replaces the current repository list with the supplied collection.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
repos | List<AgentSkillRepository> | repos(类型 `List`)。The repos. |
Builderio/agentscope/core/ReActAgent.java:5367–5377skillFilter
public Builder skillFilter(SkillFilter filter)
设置技能过滤器。
Builder-time SkillFilter applied by the auto-installed DynamicSkillMiddleware.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
filter | SkillFilter | 过滤条件(类型 `SkillFilter`)。The filter. |
Builderio/agentscope/core/ReActAgent.java:5383–5386dynamicSkillsEnabled
public Builder dynamicSkillsEnabled(boolean enabled)
设置该配置项。
Toggles automatic installation of DynamicSkillMiddleware.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
enabled | boolean | 已启用(类型 `boolean`)。The enabled. |
Builderio/agentscope/core/ReActAgent.java:5394–5397skillCodeExecutionEnabled
public Builder skillCodeExecutionEnabled(boolean enabled)
设置该配置项。
Enables the code-execution prompt block emitted by io.agentscope.core.skill.AgentSkillPromptProvider.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
enabled | boolean | 已启用(类型 `boolean`)。The enabled. |
Builderio/agentscope/core/ReActAgent.java:5413–5416skillWorkDir
public Builder skillWorkDir(Path dir)
设置该配置项。
Sets a stable working directory used by DynamicSkillMiddleware for uploadSkillFiles.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
dir | Path | 目录(类型 `Path`)。The dir. |
Builderio/agentscope/core/ReActAgent.java:5423–5426fromAgent
public static Builder fromAgent(ReActAgent agent)
设置来自智能体。
Returns a new Builder pre-populated with the given agent's observable configuration: name, description, system prompt, model, maxIters, generateOptions, and a defensive copy of the toolkit.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | ReActAgent | 智能体(类型 `ReActAgent`)。The agent. |
Builderio/agentscope/core/ReActAgent.java:5435–5451build
public ReActAgent build()
构建并返回最终实例。
Builds and returns a new ReActAgent instance with the configured settings.
ReActAgentIllegalArgumentException可能抛出 `IllegalArgumentException`。if required parameters are missing or invalid
io/agentscope/core/ReActAgent.java:5585–5636