Class AgentCompilerLoader
java.lang.Object
com.google.adk.web.AgentCompilerLoader
Dynamically compiles and loads ADK
BaseAgent
implementations from source files. It
orchestrates the discovery of the ADK core JAR, compilation of agent sources using the Eclipse
JDT (ECJ) compiler, and loading of compiled agents into isolated classloaders. Agents are
identified by a public static field named ROOT_AGENT
. Supports agent organization in
subdirectories or as individual .java
files.-
Constructor Summary
ConstructorsConstructorDescriptionAgentCompilerLoader
(AgentLoadingProperties properties) Initializes the loader with agent configuration and proactively attempts to locate the ADK core JAR. -
Method Summary
Modifier and TypeMethodDescriptionDiscovers, compiles, and loads agents from the configured source directory.
-
Constructor Details
-
AgentCompilerLoader
Initializes the loader with agent configuration and proactively attempts to locate the ADK core JAR. This JAR, containingBaseAgent
and other core ADK types, is crucial for agent compilation. The location strategy (seelocateAndPrepareAdkCoreJar()
) includes handling directly available JARs and extracting nested JARs (e.g., in Spring Boot fat JARs) to ensure it's available for the compilation classpath.- Parameters:
properties
- Configuration detailing agent source locations and compilation settings.
-
-
Method Details
-
loadAgents
Discovers, compiles, and loads agents from the configured source directory.The process for each potential "agent unit" (a subdirectory or a root
.java
file):- Collects
.java
source files. - Compiles these sources using ECJ (see
compileSourcesWithECJ(List, Path)
) into a temporary, unit-specific output directory. This directory is cleaned up on JVM exit. - Creates a dedicated
URLClassLoader
for the compiled unit, isolating its classes. - Scans compiled classes for a public static field
ROOT_AGENT
assignable toBaseAgent
. This field serves as the designated entry point for an agent. - Instantiates and stores the
BaseAgent
if found, keyed by its name.
- Returns:
- A map of successfully loaded agent names to their
BaseAgent
instances. Returns an empty map if the source directory isn't configured or no agents are found. - Throws:
IOException
- If an I/O error occurs (e.g., creating temp directories, reading sources).
- Collects
-