Skip to content

Conversation

copybara-service[bot]
Copy link

@copybara-service copybara-service bot commented Aug 22, 2025

feat: Implement automatic tool discovery for config-based agents

This change allows ConfigAgentLoader to scan agent YAML files for tool names that are fully qualified Java class or method/field references. It automatically registers these tools in the ComponentRegistry.

The following patterns for tool names in the YAML are supported:

  1. Class Name: e.g., com.example.MyTool

    • LlmAgent will instantiate this class.
    • If args are provided in the YAML, a static fromConfig(ToolArgsConfig) method must exist.
    • Otherwise, the class must have a default constructor.
    • This is typically used for tools extending BaseTool.
  2. Fully Qualified Static Field: e.g., com.example.MyTool.MY_TOOL_INSTANCE

    • LlmAgent will resolve the static field MY_TOOL_INSTANCE from the class com.example.MyTool.
    • The field must be of a type assignable to BaseTool.
  3. Registry Name: e.g., my_custom_tool

    • The tool must be pre-registered in the ComponentRegistry.
    • A custom ComponentRegistry can be specified via the system property -Dregistry=com.example.CustomRegistry.

Usage Example:

# Navigate to the example directory
cd maven_plugin/examples/custom_tools

# Clean, compile, and start the server
mvn clean compile google-adk:web \
  -Dagents=config_agents \
  -Dregistry=com.example.CustomDieRegistry

@copybara-service copybara-service bot force-pushed the test_798326228 branch 10 times, most recently from 48ffd92 to bb77b6a Compare August 27, 2025 00:07
This change allows `ConfigAgentLoader` to scan agent YAML files for tool names that are fully qualified Java class or method/field references. It automatically registers these tools in the `ComponentRegistry`.

The following patterns for tool names in the YAML are supported:

1.  **Class Name**: e.g., `com.example.MyTool`
    *   LlmAgent will instantiate this class.
    *   If `args` are provided in the YAML, a static `fromConfig(ToolArgsConfig)` method must exist.
    *   Otherwise, the class must have a default constructor.
    *   This is typically used for tools extending `BaseTool`.

2.  **Fully Qualified Static Field**: e.g., `com.example.MyTool.MY_TOOL_INSTANCE`
    *   LlmAgent will resolve the static field `MY_TOOL_INSTANCE` from the class `com.example.MyTool`.
    *   The field must be of a type assignable to `BaseTool`.

3.  **Registry Name**: e.g., `my_custom_tool`
    *   The tool must be pre-registered in the `ComponentRegistry`.
    *   A custom `ComponentRegistry` can be specified via the system property `-Dregistry=com.example.CustomRegistry`.

Usage Example:
```bash
# Navigate to the example directory
cd maven_plugin/examples/custom_tools

# Clean, compile, and start the server
mvn clean compile google-adk:web \
  -Dagents=config_agents \
  -Dregistry=com.example.CustomDieRegistry
```

PiperOrigin-RevId: 799781730
@copybara-service copybara-service bot merged commit a2d9533 into main Aug 27, 2025
1 check passed
@copybara-service copybara-service bot deleted the test_798326228 branch August 27, 2025 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant