类:CompiledAgentLoader

java.lang.Object
com.google.adk.web.CompiledAgentLoader
All Implemented Interfaces:
AgentLoader

@Service("agentLoader") @Primary @ConditionalOnProperty(name="adk.agents.loader", havingValue="compiled", matchIfMissing=true) @ThreadSafe public class CompiledAgentLoader extends Object implements AgentLoader
为开发环境编译了 `CompiledAgentLoader` 的实现代码。

该加载器会扫描配置好的源目录,并将源目录或其子目录视为包含预编译类的“代理单元”(agent unit)。它不会在运行时进行编译;所有代理都必须预先被编译完成。代理是通过一个名为……的公共静态字段来识别的。 ROOT_AGENT 可分配给 BaseAgent.

路径的示例目录结构 internal/samples:

agent/samples/
  ├── my-chat-agent/
  │   ├── MyAgent.class (with ROOT_AGENT field)
  │   └── helper/
  │       └── HelperClass.class
  └── code-assistant/
      ├── CodeAssistant.class (with ROOT_AGENT field)
      └── tools/
          └── CodeTools.class

这个加载器是线程安全的(即多个线程可以同时使用它),并且使用了“记忆化”(memoized)的供应商(supplier)机制,以确保代理对象仅在首次被请求时才会被创建。这样一来,在后续多次访问时性能得到了提升。

配置:

  • 要启用此加载器,请执行以下操作: adk.agents.loader=compiled
  • 要指定代理程序的源目录,请执行以下操作: adk.agents.source-dir=/path/to/agents
  • 目录限制功能(推荐使用;默认情况下该功能是关闭的): adk.agents.confine-to-source-dir=true 将编译后的类限制为(仅能在特定环境中使用)…… source-dir当该功能被禁用时,系统仍会记录一条警告信息。
  • 构造函数详细信息

  • 方法详细信息(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