AguiAgentRegistry
public class AguiAgentRegistry
源码Source
io/agentscope/core/agui/registry/AguiAgentRegistry.java:47–150AGUI 智能体注册表,在智能体、模型与前端之间传递结构化消息和事件。位于 io.agentscope.core.agui.registry 包。核心成员包括 register、registerFactory、getAgent、hasAgent、unregister、clear。
Registry for managing agents accessible via the AG-UI protocol.
This registry supports two types of agent registration:
-
Singleton agents - A single shared instance
-
Factory agents - A new instance created per request
Usage:
`AguiAgentRegistry registry = new AguiAgentRegistry();
// Register a singleton agent
registry.register("assistant", myAgent);
// Register a factory for per-request agents
registry.registerFactory("chat", () -> createNewAgent());
// Get an agent
Optional<Agent> agent = registry.getAgent("assistant");
`
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void register(String agentId, Agent agent) | 执行注册相关操作。 Register a singleton agent with the given ID. |
public void registerFactory(String agentId, Supplier<Agent> factory) | 注册工厂。 Register an agent factory with the given ID. |
public Optional<Agent> getAgent(String agentId) | 获取智能体通过标识。 Get an agent by ID. |
public boolean hasAgent(String agentId) | 判断是否具有智能体。 Check if an agent is registered with the given ID. |
public boolean unregister(String agentId) | 设置注销。 Unregister an agent by ID. |
public void clear() | 清空或重置内部状态。 Clear all registered agents. |
public int size() | 返回大小。 Get the number of registered agents (both factories and singletons). |
方法详情Method Detail
register
public void register(String agentId, Agent agent)
执行注册相关操作。
Register a singleton agent with the given ID.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识。The agent ID |
agent | Agent | 智能体实例。The agent instance |
源码Source
io/agentscope/core/agui/registry/AguiAgentRegistry.java:60–68registerFactory
public void registerFactory(String agentId, Supplier<Agent> factory)
注册工厂。
Register an agent factory with the given ID.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识。The agent ID |
factory | Supplier<Agent> | 工厂(类型 `Supplier`)。The factory that creates new agent instances |
源码Source
io/agentscope/core/agui/registry/AguiAgentRegistry.java:79–87getAgent
public Optional<Agent> getAgent(String agentId)
获取智能体通过标识。
Get an agent by ID.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识。The agent ID |
Optional<Agent>返回可选。An Optional containing the agent, or empty if not found
源码Source
io/agentscope/core/agui/registry/AguiAgentRegistry.java:101–110hasAgent
public boolean hasAgent(String agentId)
判断是否具有智能体。
Check if an agent is registered with the given ID.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识。The agent ID |
boolean返回布尔值,表示判断结果。true if an agent is registered
源码Source
io/agentscope/core/agui/registry/AguiAgentRegistry.java:118–120unregister
public boolean unregister(String agentId)
设置注销。
Unregister an agent by ID.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识。The agent ID |
boolean返回布尔值,表示判断结果。true if an agent was unregistered
源码Source
io/agentscope/core/agui/registry/AguiAgentRegistry.java:128–132clear
public void clear()
清空或重置内部状态。
Clear all registered agents.
源码Source
io/agentscope/core/agui/registry/AguiAgentRegistry.java:137–140size
public int size()
返回大小。
Get the number of registered agents (both factories and singletons).
int已注册智能体的总数数量。The total count of registered agents
源码Source
io/agentscope/core/agui/registry/AguiAgentRegistry.java:147–149