Interface AgentLoader


@ThreadSafe public interface AgentLoader
用于将代理程序加载到 ADK Web 服务器的接口。

用户通过实现该接口,将他们的代理程序注册到 ADK Web 服务器上。

线程安全性(Thread Safety): 该实现必须具备线程安全性(thread-safe),因为它将被作为 Spring 单例(singleton)Bean 使用,并且会被多个 HTTP 请求同时访问。

示例用法:

public class MyAgentLoader implements AgentLoader {
  @Override
  public ImmutableList<String> listAgents() {
    return ImmutableList.of("chat_bot", "code_assistant");
  }

  @Override
  public BaseAgent loadAgent(String name) {
    switch (name) {
      case "chat_bot": return createChatBot();
      case "code_assistant": return createCodeAssistant();
      default: throw new java.util.NoSuchElementException("Agent not found: " + name);
    }
  }
}

然后使用 Maven 插件进行配置:

mvn google-adk:web -Dagents=com.acme.MyAgentLoader
TODO:未来需要添加基于配置的代理注册功能。
  • 方法概述

    Modifier and Type
    Method
    Description
    com.google.common.collect.ImmutableList<String>
    返回一个包含所有可用代理名称的列表。
    加载指定代理名称对应的 BaseAgent 实例。
  • 方法详细信息(Method Details)

    • listAgents

      @Nonnull com.google.common.collect.ImmutableList<String> listAgents()
      返回一个包含所有可用代理名称的列表。
      Returns:
      ImmutableList of agent names. Must not return null - return an empty list if no agents are available.
    • loadAgent

      BaseAgent loadAgent(String name)
      加载指定代理名称对应的 BaseAgent 实例。
      Parameters:
      name - the name of the agent to load
      Returns:
      BaseAgent instance for the given name
      Throws:
      NoSuchElementException - if the agent doesn't exist
      IllegalStateException - if the agent exists but fails to load