# 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
  Constructor
  Description
  `CompiledAgentLoader(AgentLoadingProperties properties)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `com.google.common.collect.ImmutableList<String>`
  `listAgents()`
  Returns a list of available agent names.
  `BaseAgent`
  `loadAgent(String name)`
  Loads the BaseAgent instance for the specified agent name.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CompiledAgentLoader

    public CompiledAgentLoader(AgentLoadingProperties properties)

- ## Method Details

  - ### listAgents

    @Nonnull public com.google.common.collect.ImmutableList<String> listAgents()
    Description copied from interface: `AgentLoader`
    Returns a list of available agent names.
    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)
    Description copied from interface: `AgentLoader`
    Loads the BaseAgent instance for the specified agent name.
    Specified by:
      `loadAgent` in interface `AgentLoader`
    Parameters:
      `name` - the name of the agent to load
    Returns:
      BaseAgent instance for the given name