Class AguiAgentRegistry

java.lang.Object
io.agentscope.core.agui.registry.AguiAgentRegistry

public class AguiAgentRegistry extends Object
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 Details

    • AguiAgentRegistry

      public AguiAgentRegistry()
  • Method Details

    • register

      public void register(String agentId, io.agentscope.core.agent.Agent agent)
      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 ID
      agent - The agent instance
    • registerFactory

      public void registerFactory(String agentId, Supplier<io.agentscope.core.agent.Agent> factory)
      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 ID
      factory - The factory that creates new agent instances
    • getAgent

      public Optional<io.agentscope.core.agent.Agent> getAgent(String agentId)
      Get an agent by ID.

      The agent is resolved in the following order:

      1. Check for a registered factory and create a new instance
      2. Return the singleton agent if registered
      Parameters:
      agentId - The agent ID
      Returns:
      An Optional containing the agent, or empty if not found
    • hasAgent

      public boolean hasAgent(String agentId)
      Check if an agent is registered with the given ID.
      Parameters:
      agentId - The agent ID
      Returns:
      true if an agent is registered
    • unregister

      public boolean unregister(String agentId)
      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