Class 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 implementation for the dev environment.
This loader scans the configured source directory and treats the source directory or a
subdirectory as an "agent unit" containing pre-compiled classes. It does not perform runtime
compilation - agents must be pre-compiled. Agents are identified by a public static field named
ROOT_AGENT assignable to BaseAgent.
Example directory structure for path 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
This loader is thread-safe and uses memoized suppliers to ensure agents are created only once when first requested, improving performance for repeated access.
Configuration:
- To enable this loader:
adk.agents.loader=compiled - To specify agent source directory:
adk.agents.source-dir=/path/to/agents
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.collect.ImmutableList<String> Returns a list of available agent names.Loads the BaseAgent instance for the specified agent name.
-
Constructor Details
-
CompiledAgentLoader
-
-
Method Details
-
listAgents
Description copied from interface:AgentLoaderReturns a list of available agent names.- Specified by:
listAgentsin interfaceAgentLoader- Returns:
- ImmutableList of agent names. Must not return null - return an empty list if no agents are available.
-
loadAgent
Description copied from interface:AgentLoaderLoads the BaseAgent instance for the specified agent name.- Specified by:
loadAgentin interfaceAgentLoader- Parameters:
name- the name of the agent to load- Returns:
- BaseAgent instance for the given name
-