Class AguiAgentAutoRegistration

java.lang.Object
io.agentscope.spring.boot.agui.common.AguiAgentAutoRegistration
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean

public class AguiAgentAutoRegistration extends Object implements org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean
A Scanner class for automatically registering Agent beans with the AguiAgentRegistry.

This configuration scans all Agent beans in the application context and registers them with the registry. It supports both singleton and prototype scoped beans:

  • Singleton beans: The bean instance is registered directly
  • Prototype beans: A factory is registered that creates new instances per request (thread-safe)

Agent ID Resolution:

  1. AguiAgentId annotation on the bean method or class
  2. Bean name (default)

Usage:


 // Singleton bean (shared instance)
 @Bean
 public Agent chatAgent() {
     return ReActAgent.builder().name("Chat").model(model).build();
 }

 // Prototype bean (new instance per request - thread-safe)
 @Bean
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public Agent isolatedAgent() {
     return ReActAgent.builder().name("Isolated").model(model).build();
 }

 // Custom agent ID
 @Bean
 @AguiAgentId("custom-id")
 public Agent myAgent() {
     return ReActAgent.builder().name("Custom").model(model).build();
 }
 
  • Constructor Details

    • AguiAgentAutoRegistration

      public AguiAgentAutoRegistration(io.agentscope.core.agui.registry.AguiAgentRegistry registry)
      Creates a new AguiAgentAutoRegistration.
      Parameters:
      registry - The agent registry
  • Method Details

    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Throws:
      org.springframework.beans.BeansException
    • aguiAgentAutoRegistrar

      protected void aguiAgentAutoRegistrar()
      Registers all Agent beans with the AguiAgentRegistry.

      This method is called after the registry is created and scans for all Agent beans.

    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Invoke aguiAgentAutoRegistrar() after all properties are set.
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception