类名:ConfigAgentLoader

java.lang.Object
com.google.adk.maven.ConfigAgentLoader
All Implemented Interfaces:
AgentLoader

@ThreadSafe public class ConfigAgentLoader extends Object implements AgentLoader
这是一个基于配置的 AgentLoader,它可以从 YAML 配置文件中加载代理程序(agents)。

该加载器会监控配置好的源目录,寻找包含 `root_agent.yaml` 文件的文件夹;当这些文件发生变化时(如果启用了热重载功能),系统会自动重新加载相应的代理程序。

加载器会将每个包含 `root_agent.yaml` 文件的子目录视为一个代理(agent),并使用该子目录的名称作为代理的标识符。这些代理会在首次被请求时才被加载(即按需加载)。

预期的目录结构如下:

source-dir/
  ├── agent1/
  │   └── root_agent.yaml
  ├── agent2/
  │   └── root_agent.yaml
  └── ...

可以通过将 `hotReloadingEnabled` 的值设置为 `false` 来禁用热重载功能。

TODO:配置代理(Config Agent)的相关功能尚未准备好供公众使用。

  • 构造函数详细信息

    • ConfigAgentLoader

      public ConfigAgentLoader(String sourceDir, boolean hotReloadingEnabled)
      创建一个新的 ConfigAgentLoader。
      Parameters:
      sourceDir - The directory to scan for agent configuration files
      hotReloadingEnabled - Controls whether hot-reloading is enabled
    • ConfigAgentLoader

      public ConfigAgentLoader(String sourceDir)
      创建一个新的 `ConfigAgentLoader`,并启用热重载(hot-reloading)功能。
      Parameters:
      sourceDir - The directory to scan for agent configuration files
  • 方法详细信息(Method Details)

    • listAgents

      @Nonnull public com.google.common.collect.ImmutableList<String> listAgents()
      描述内容复制自接口文档: AgentLoader
      返回一个包含所有可用代理名称的列表。
      Specified by:
      listAgents in interface AgentLoader
      Returns:
      ImmutableList of agent names. Must not return null - return an empty list if no agents are available.
    • loadAgent

      public BaseAgent loadAgent(String name)
      描述内容复制自接口文档: AgentLoader
      加载指定代理名称对应的 BaseAgent 实例。
      Specified by:
      loadAgent in interface AgentLoader
      Parameters:
      name - the name of the agent to load
      Returns:
      BaseAgent instance for the given name
    • stop

      public void stop()
      停止热加载(hot-loading)服务。