AgentFactory
@FunctionalInterface public interface AgentFactory
io/agentscope/extensions/agentprotocol/AgentFactory.java:43–63定义智能体工厂契约的接口。位于 io.agentscope.extensions.agentprotocol 包。核心成员包括 create、fixed、of。
Resolves the HarnessAgent that executes an Agent Protocol task.
Called once per run — on the initial POST /tasks submission and again for every
POST /tasks/{id}/resume — with the full AgentRequest, including the submission
context map. Implementations may therefore route by agentId, tenant, or any
custom context attribute, and may build a fresh agent per task.
Register a bean of this type to override the default factory, which always returns the single
HarnessAgent bean:
`@Bean
AgentFactory agentFactory(Map<String, HarnessAgent> agentsByName) {
return request -> agentsByName.getOrDefault(request.agentId(), agentsByName.get("default"));
}
`
For concurrent tasks, return a distinct instance per call (e.g. a prototype-scoped bean),
or configure the shared agent with checkRunning(false).
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public HarnessAgent create(AgentRequest request) | 返回智能体用于此运行。 Returns the agent for this run. |
static public AgentFactory fixed(HarnessAgent agent)static | 设置该参数。 Factory that always returns the same agent, ignoring the request. |
static public AgentFactory of(Supplier<HarnessAgent> supplier)static | 创建并返回实例。 Factory backed by a supplier, ignoring the request. |
方法详情Method Detail
create
public HarnessAgent create(AgentRequest request)
返回智能体用于此运行。
Returns the agent for this run.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | AgentRequest | 请求(类型 `AgentRequest`)。The request. |
HarnessAgentio/agentscope/extensions/agentprotocol/AgentFactory.java:50fixed
static public AgentFactory fixed(HarnessAgent agent)
设置该参数。
Factory that always returns the same agent, ignoring the request.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | HarnessAgent | 智能体(类型 `HarnessAgent`)。The agent. |
AgentFactoryio/agentscope/extensions/agentprotocol/AgentFactory.java:53–56of
static public AgentFactory of(Supplier<HarnessAgent> supplier)
创建并返回实例。
Factory backed by a supplier, ignoring the request.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
supplier | Supplier<HarnessAgent> | supplier(类型 `Supplier`)。The supplier. |
AgentFactoryio/agentscope/extensions/agentprotocol/AgentFactory.java:59–62