AS AgentScopeAPI 手册 / API Reference

AgentFactory

@FunctionalInterface public interface AgentFactory
源码Source 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.

参数Parameters
名称Name类型Type说明Description
requestAgentRequest请求(类型 `AgentRequest`)。The request.
返回Returns HarnessAgent
返回HarnessAgent。Returns harness agent.
源码Source io/agentscope/extensions/agentprotocol/AgentFactory.java:50

fixed

static public AgentFactory fixed(HarnessAgent agent)
static

设置该参数。

Factory that always returns the same agent, ignoring the request.

参数Parameters
名称Name类型Type说明Description
agentHarnessAgent智能体(类型 `HarnessAgent`)。The agent.
返回Returns AgentFactory
返回AgentFactory。Returns agent factory.
源码Source io/agentscope/extensions/agentprotocol/AgentFactory.java:53–56

of

static public AgentFactory of(Supplier<HarnessAgent> supplier)
static

创建并返回实例。

Factory backed by a supplier, ignoring the request.

参数Parameters
名称Name类型Type说明Description
supplierSupplier<HarnessAgent>supplier(类型 `Supplier`)。The supplier.
返回Returns AgentFactory
返回AgentFactory。Returns agent factory.
源码Source io/agentscope/extensions/agentprotocol/AgentFactory.java:59–62
基于官方固定版本源码静态生成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.