Package io.agentscope.core.agui.registry
Class AguiAgentRegistry
java.lang.Object
io.agentscope.core.agui.registry.AguiAgentRegistry
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");
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all registered agents.Optional<io.agentscope.core.agent.Agent> Get an agent by ID.booleanCheck if an agent is registered with the given ID.voidRegister a singleton agent with the given ID.voidregisterFactory(String agentId, Supplier<io.agentscope.core.agent.Agent> factory) Register an agent factory with the given ID.intsize()Get the number of registered agents (both factories and singletons).booleanunregister(String agentId) Unregister an agent by ID.
-
Constructor Details
-
AguiAgentRegistry
public AguiAgentRegistry()
-
-
Method Details
-
register
Register a singleton agent with the given ID.The same agent instance will be returned for all requests with this ID.
- Parameters:
agentId- The agent IDagent- The agent instance
-
registerFactory
Register an agent factory with the given ID.A new agent instance will be created for each request with this ID. This is useful for stateful agents that should not be shared.
- Parameters:
agentId- The agent IDfactory- The factory that creates new agent instances
-
getAgent
Get an agent by ID.The agent is resolved in the following order:
- Check for a registered factory and create a new instance
- Return the singleton agent if registered
- Parameters:
agentId- The agent ID- Returns:
- An Optional containing the agent, or empty if not found
-
hasAgent
Check if an agent is registered with the given ID.- Parameters:
agentId- The agent ID- Returns:
- true if an agent is registered
-
unregister
Unregister an agent by ID.- Parameters:
agentId- The agent ID- Returns:
- true if an agent was unregistered
-
clear
public void clear()Clear all registered agents. -
size
public int size()Get the number of registered agents (both factories and singletons).- Returns:
- The total count of registered agents
-