AS AgentScopeAPI 手册 / API Reference

AguiAgentRegistry

public class AguiAgentRegistry
源码Source io/agentscope/core/agui/registry/AguiAgentRegistry.java:47–150

AGUI 智能体注册表,在智能体、模型与前端之间传递结构化消息和事件。位于 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
agentIdString智能体标识。The agent ID
agentAgent智能体实例。The agent instance
源码Source io/agentscope/core/agui/registry/AguiAgentRegistry.java:60–68

registerFactory

public void registerFactory(String agentId, Supplier<Agent> factory)

注册工厂。

Register an agent factory with the given ID.

参数Parameters
名称Name类型Type说明Description
agentIdString智能体标识。The agent ID
factorySupplier<Agent>工厂(类型 `Supplier`)。The factory that creates new agent instances
源码Source io/agentscope/core/agui/registry/AguiAgentRegistry.java:79–87

getAgent

public Optional<Agent> getAgent(String agentId)

获取智能体通过标识。

Get an agent by ID.

参数Parameters
名称Name类型Type说明Description
agentIdString智能体标识。The agent ID
返回Returns Optional<Agent>
返回可选。An Optional containing the agent, or empty if not found
源码Source io/agentscope/core/agui/registry/AguiAgentRegistry.java:101–110

hasAgent

public boolean hasAgent(String agentId)

判断是否具有智能体。

Check if an agent is registered with the given ID.

参数Parameters
名称Name类型Type说明Description
agentIdString智能体标识。The agent ID
返回Returns boolean
返回布尔值,表示判断结果。true if an agent is registered
源码Source io/agentscope/core/agui/registry/AguiAgentRegistry.java:118–120

unregister

public boolean unregister(String agentId)

设置注销。

Unregister an agent by ID.

参数Parameters
名称Name类型Type说明Description
agentIdString智能体标识。The agent ID
返回Returns boolean
返回布尔值,表示判断结果。true if an agent was unregistered
源码Source io/agentscope/core/agui/registry/AguiAgentRegistry.java:128–132

clear

public void clear()

清空或重置内部状态。

Clear all registered agents.

源码Source io/agentscope/core/agui/registry/AguiAgentRegistry.java:137–140

size

public int size()

返回大小。

Get the number of registered agents (both factories and singletons).

返回Returns int
已注册智能体的总数数量。The total count of registered agents
源码Source io/agentscope/core/agui/registry/AguiAgentRegistry.java:147–149
基于官方固定版本源码静态生成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.