Skip to content

Commit 80bc3c7

Browse files
authored
Merge branch 'main' into feat/planner-support
2 parents 322378e + 1d47235 commit 80bc3c7

File tree

52 files changed

+3330
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3330
-166
lines changed

CHANGELOG.md

Lines changed: 125 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
44
[![Maven Central](https://img.shields.io/maven-central/v/com.google.adk/google-adk)](https://search.maven.org/artifact/com.google.adk/google-adk)
55
[![r/agentdevelopmentkit](https://img.shields.io/badge/Reddit-r%2Fagentdevelopmentkit-FF4500?style=flat&logo=reddit&logoColor=white)](https://www.reddit.com/r/agentdevelopmentkit/)
6+
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/google/adk-java)
67

78
<html>
89
<h2 align="center">
@@ -49,13 +50,13 @@ If you're using Maven, add the following to your dependencies:
4950
<dependency>
5051
<groupId>com.google.adk</groupId>
5152
<artifactId>google-adk</artifactId>
52-
<version>0.2.0</version>
53+
<version>0.3.0</version>
5354
</dependency>
5455
<!-- Dev UI -->
5556
<dependency>
5657
<groupId>com.google.adk</groupId>
5758
<artifactId>google-adk-dev</artifactId>
58-
<version>0.2.0</version>
59+
<version>0.3.0</version>
5960
</dependency>
6061
```
6162

contrib/README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,33 @@
33
**Before You Start:**
44
Please take a look at [ADK Contribution Guidelines](https://google.github.io/adk-docs/contributing-guide/).
55

6-
**Coding Guidelines For PR Approval:**
6+
## Samples
77

8-
* **Base Interfaces:** Inherit from base interfaces (e.g. `BaseLlm`) for
9-
compatibility. This allows existing tooling to work seamlessly with your new
10-
components.
11-
* **Asynchronous and Streaming:** Keep our code asynchronous (e.g. RxJava
12-
`Flowable`).
8+
The samples folder hosts minimal examples to test different features. These samples are intentionally simplistic and focused on testing specific scenarios.
9+
10+
**Note:** This is different from the [google/adk-samples](https://github.com/google/adk-samples) repository, which hosts more complex end-to-end samples for customers to use or modify directly.
11+
12+
## Coding Guidelines For PR Approval
13+
14+
* **Base Interfaces:** Inherit from base interfaces (e.g. `BaseLlm`) for compatibility. This allows existing tooling to work seamlessly with your new components.
15+
* **Asynchronous and Streaming:** Keep our code asynchronous (e.g. RxJava `Flowable`).
1316
* **Readability:** Write clear, well-commented code.
1417
* **Consistency:** Adhere to the project's coding/formatting style.
15-
* **Testing:** Include unit and integration tests for new features and bug
16-
fixes.
18+
* **Testing:** Include unit and integration tests for new features and bug fixes.
1719
* **Error Handling:** Handle errors gracefully with informative messages.
1820
* **Documentation:** Document your code and its usage.
1921

20-
**Compatibility Guarantees:**
22+
## Compatibility Guarantees
2123

22-
* All code in `contrib/` is explictly not covered by any sort of backwards API Compatibility Guarantees, even across minor (patch) releases.
24+
* All code in `contrib/` is explicitly not covered by any sort of backwards API Compatibility Guarantees, even across minor (patch) releases.
2325
* The maintainers (committers) of this project are going to merge any changes in both implementations and interfaces without API stability concerns.
2426
* Contributors are welcome to raise their PRs based on this policy, and incrementally improve code without worrying about API breakage.
2527

26-
**Contrib Graduation:**
28+
## Contrib Graduation
2729

2830
We'll consider graduating community contributions into officially maintained
2931
plugins based on:
3032

31-
* **Usage:** Widespread use by the community (e.g., at least x users over y
32-
months).
33+
* **Usage:** Widespread use by the community (e.g., at least x users over y months).
3334
* **Stability:** Stable and reliable code.
3435
* **Compatibility:** Integrates well with the core framework.

contrib/langchain4j/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
-->
17-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1918
<modelVersion>4.0.0</modelVersion>
2019

2120
<parent>
2221
<groupId>com.google.adk</groupId>
2322
<artifactId>google-adk-parent</artifactId>
24-
<version>0.2.1-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
23+
<version>0.3.0</version><!-- {x-version-update:google-adk:current} -->
2524
<relativePath>../../pom.xml</relativePath>
2625
</parent>
2726

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# Config-based Agent Samples
2+
3+
This directory contains several samples demonstrating ADK agent configuration using YAML files:
4+
5+
1. **Core Basic Config** - The simplest possible agent configuration
6+
2. **Core Callback Config** - An agent with comprehensive callback hooks for lifecycle events
7+
3. **Core Generate Content Config** - An agent demonstrating generate_content_config settings
8+
4. **Tool Builtin Config** - An agent with built-in Google search tool
9+
5. **Tool Functions Config** - An agent with custom Java-based function tools
10+
6. **Multi Agent Basic Config** - Multiple specialized agents (coding tutor, math tutor)
11+
7. **Multi Agent LLM Config** - Multi-agent system with dice rolling and prime checking capabilities
12+
8. **Tool MCP Stdio File System Config** - An agent with MCP filesystem tools via stdio transport
13+
9. **Sub Agents Config** - Demonstrates programmatic sub-agent resolution using the `code` field
14+
15+
## Project Structure
16+
17+
```
18+
├── core_basic_config/
19+
│ └── root_agent.yaml # Basic agent configuration
20+
├── core_callback_config/
21+
│ └── root_agent.yaml # Agent with callback hooks
22+
├── core_generate_content_config_config/
23+
│ └── root_agent.yaml # Agent with generate_content_config settings
24+
├── tool_builtin_config/
25+
│ └── root_agent.yaml # Agent with built-in search tool
26+
├── tool_functions_config/
27+
│ └── root_agent.yaml # Agent with custom function tools
28+
├── multi_agent_basic_config/
29+
│ ├── root_agent.yaml # Root coordinator agent
30+
│ ├── code_tutor_agent.yaml # Coding tutor sub-agent
31+
│ └── math_tutor_agent.yaml # Math tutor sub-agent
32+
├── multi_agent_llm_config/
33+
│ ├── root_agent.yaml # Root agent with dice/prime delegation
34+
│ ├── roll_agent.yaml # Dice rolling sub-agent
35+
│ └── prime_agent.yaml # Prime checking sub-agent
36+
├── tool_mcp_stdio_file_system_config/
37+
│ └── root_agent.yaml # Agent with MCP filesystem tools
38+
├── sub_agents_config/
39+
│ ├── root_agent.yaml # Root agent using programmatic sub-agents
40+
│ ├── work_agent.yaml # Work-related sub-agent
41+
│ └── LifeAgent.java # Life agent implementation (registered via code)
42+
├── src/
43+
│ ├── CustomDieTool.java # Custom tool implementation
44+
│ ├── CoreCallbacks.java # Callback implementations
45+
│ └── CustomDemoRegistry.java # Consolidated custom registry
46+
├── pom.xml # Maven configuration
47+
└── README.md # This file
48+
```
49+
50+
## How to Use
51+
52+
### 1. Navigate to this sample directory
53+
```bash
54+
cd contrib/samples/configagent
55+
```
56+
57+
### 2. Run the ADK web server
58+
Run all agents simultaneously:
59+
```bash
60+
mvn clean compile google-adk:web -Dagents=. \
61+
-Dregistry=com.example.CustomDemoRegistry
62+
```
63+
64+
Or run individual agents:
65+
```bash
66+
# Basic agent only
67+
mvn google-adk:web -Dagents=core_basic_config
68+
69+
# Custom function tools agent (requires compilation and registry)
70+
mvn clean compile google-adk:web \
71+
-Dagents=tool_functions_config \
72+
-Dregistry=com.example.CustomDemoRegistry
73+
```
74+
75+
### 3. Access the Web UI
76+
Open your browser and navigate to:
77+
```
78+
http://localhost:8000
79+
```
80+
81+
You will see the configured agent(s) available in the UI.
82+
83+
## Sample 1: Core Basic Config (`core_basic_config/`)
84+
85+
Basic Q&A agent with essential fields: name, model, description, instruction.
86+
87+
**Sample queries:**
88+
- "Hello, can you help me?"
89+
- "Explain what machine learning is"
90+
91+
## Sample 2: Core Callback Config (`core_callback_config/`)
92+
93+
Agent demonstrating comprehensive callback hooks for monitoring and debugging agent lifecycle events. This sample showcases how callbacks can be used to track agent execution, model interactions, and tool usage.
94+
95+
96+
**Sample queries:**
97+
- "Roll a 6-sided die" - Triggers tool callbacks
98+
- "Roll a 20-sided die and check if it's prime" - Demonstrates multiple callback types
99+
- "Check if 7, 11, and 13 are prime numbers" - Shows batch processing with callbacks
100+
101+
**Callback Types:**
102+
- **Agent callbacks**: Execute before/after the agent processes a request
103+
- **Model callbacks**: Execute before/after LLM invocation
104+
- **Tool callbacks**: Execute before/after tool execution
105+
106+
## Sample 3: Core Generate Content Config (`core_generate_content_config_config/`)
107+
108+
Search agent demonstrating the use of `generate_content_config` to control LLM generation parameters.
109+
110+
**Key Configuration:**
111+
```yaml
112+
generate_content_config:
113+
temperature: 0.1 # Lower temperature for more focused responses
114+
max_output_tokens: 2000 # Limit response length
115+
```
116+
117+
**Sample queries that demonstrate the configuration:**
118+
- "Generate a creative story about a robot" - Run this multiple times; with temperature 0.1, you'll get very similar stories each time (low creativity/high consistency)
119+
- "List 3 uses for a paperclip" - Run multiple times; low temperature means you'll likely get the same common uses each time (writing, holding papers, reset button)
120+
- "Search for machine learning frameworks and provide a comprehensive comparison" - Tests the max_output_tokens limit of 2000; response will be truncated if it exceeds this limit
121+
122+
## Sample 4: Tool Builtin Config (`tool_builtin_config/`)
123+
124+
Search agent with built-in Google search tool.
125+
126+
**Sample queries:**
127+
- "Search for the latest news about artificial intelligence"
128+
- "What are the top Python frameworks in 2024?"
129+
130+
## Sample 5: Tool Functions Config (`tool_functions_config/`)
131+
132+
Agent with custom Java-based function tools for dice rolling and prime number checking.
133+
134+
**Custom Tools:**
135+
- `roll_die(sides)` - Rolls a die with specified number of sides
136+
- `check_prime(nums)` - Checks if a list of numbers are prime
137+
138+
**Sample queries:**
139+
- "Roll a 6-sided die"
140+
- "Roll a 20-sided die and check if the result is prime"
141+
142+
## Sample 6: Multi Agent Basic Config (`multi_agent_basic_config/`)
143+
144+
Learning assistant with specialized sub-agents for coding and math tutoring. The root agent coordinates between specialized tutors.
145+
146+
**Sub-agents:**
147+
- `code_tutor_agent` - Programming concepts and code debugging
148+
- `math_tutor_agent` - Mathematical concepts and problem solving
149+
150+
**Sample queries:**
151+
- "How do I write a for loop in Python?"
152+
- "Explain what recursion is with an example"
153+
154+
## Sample 7: Multi Agent LLM Config (`multi_agent_llm_config/`)
155+
156+
Multi-agent system demonstrating delegation between specialized agents for dice rolling and prime number checking. Includes few-shot examples and safety settings configuration.
157+
158+
**Sub-agents:**
159+
- `roll_agent` - Handles dice rolling with different sizes
160+
- `prime_agent` - Checks whether numbers are prime
161+
162+
**Features:**
163+
- Demonstrates multi-agent coordination and delegation
164+
- Uses custom Java tools (roll_die, check_prime)
165+
- Includes few-shot examples via ExampleTool
166+
- Shows safety settings configuration
167+
- Root agent delegates tasks to specialized sub-agents
168+
169+
**Sample queries:**
170+
- "Roll a 6-sided die"
171+
- "Roll a 20-sided die and check if the result is prime"
172+
173+
## Sample 8: Tool MCP Stdio File System Config (`tool_mcp_stdio_file_system_config/`)
174+
175+
File system assistant using Model Context Protocol (MCP) stdio transport to manage files and directories.
176+
177+
**Features:**
178+
- Connects to file system via MCP stdio server
179+
- Read, write, search, and manage files and directories
180+
- Uses `@modelcontextprotocol/server-filesystem` npm package
181+
- Works with `/tmp/mcp-demo` directory
182+
183+
**Setup:**
184+
1. Ensure you have Node.js installed
185+
2. Create the demo directory: `mkdir -p /tmp/mcp-demo`
186+
3. Run the agent:
187+
```bash
188+
mvn google-adk:web -Dagents=tool_mcp_stdio_file_system_config -Dport=8001
189+
```
190+
191+
**Sample queries:**
192+
- "List all files in the current directory"
193+
- "Create a new file called 'notes.txt' in /tmp/mcp-demo with some random content"
194+
195+
## Sample 9: Sub Agents Config (`sub_agents_config/`)
196+
197+
Demonstrates programmatic sub-agent resolution using the `code` field, which provides Python ADK compatibility. This sample shows how to reference agents registered in the ComponentRegistry.
198+
199+
**Features:**
200+
- Root agent that routes queries to different sub-agents
201+
- Life agent loaded programmatically via `code` field
202+
- Work agent loaded from YAML config file
203+
- Uses CustomDemoRegistry to register the LifeAgent
204+
205+
**Configuration Example:**
206+
```yaml
207+
sub_agents:
208+
- config_path: ./work_agent.yaml # Traditional YAML file reference
209+
- code: sub_agents_config.life_agent.agent # Programmatic reference via registry
210+
```
211+
212+
**Setup:**
213+
```bash
214+
mvn clean compile google-adk:web \
215+
-Dagents=sub_agents_config \
216+
-Dregistry=com.example.CustomDemoRegistry
217+
```
218+
219+
**Sample queries:**
220+
- "What is the meaning of life?" (routed to life agent)
221+
- "How can I be more productive at work?" (routed to work agent)
222+
- "Tell me about the weather" (handled by root agent)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json
2+
name: assistant_agent
3+
model: gemini-2.5-flash
4+
description: A helper agent that can answer users' questions.
5+
instruction: |
6+
You are an agent to help answer users' various questions.
7+
8+
1. If the user's intention is not clear, ask clarifying questions to better understand their needs.
9+
2. Once the intention is clear, provide accurate and helpful answers to the user's questions.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json
2+
name: hello_world_agent
3+
model: gemini-2.0-flash
4+
description: hello world agent that can roll a dice and check prime numbers.
5+
instruction: |
6+
You roll dice and answer questions about the outcome of the dice rolls.
7+
You can roll dice of different sizes.
8+
You can use multiple tools in parallel by calling functions in parallel(in one request and in one round).
9+
It is ok to discuss previous dice roles, and comment on the dice rolls.
10+
When you are asked to roll a die, you must call the roll_die tool with the number of sides. Be sure to pass in an integer. Do not pass in a string.
11+
You should never roll a die on your own.
12+
When checking prime numbers, call the check_prime tool with a list of integers. Be sure to pass in a list of integers. You should never pass in a string.
13+
You should not check prime numbers before calling the tool.
14+
When you are asked to roll a die and check prime numbers, you should always make the following two function calls:
15+
1. You should first call the roll_die tool to get a roll. Wait for the function response before calling the check_prime tool.
16+
2. After you get the function response from roll_die tool, you should call the check_prime tool with the roll_die result.
17+
2.1 If user asks you to check primes based on previous rolls, make sure you include the previous rolls in the list.
18+
3. When you respond, you must include the roll_die result from step 1.
19+
You should always perform the previous 3 steps when asking for a roll and checking prime numbers.
20+
You should not rely on the previous history on prime results.
21+
tools:
22+
- name: core_callback_config.tools.roll_die
23+
- name: core_callback_config.tools.check_prime
24+
before_agent_callbacks:
25+
- name: core_callback_config.callbacks.before_agent_callback1
26+
- name: core_callback_config.callbacks.before_agent_callback2
27+
- name: core_callback_config.callbacks.before_agent_callback3
28+
after_agent_callbacks:
29+
- name: core_callback_config.callbacks.after_agent_callback1
30+
- name: core_callback_config.callbacks.after_agent_callback2
31+
- name: core_callback_config.callbacks.after_agent_callback3
32+
before_model_callbacks:
33+
- name: core_callback_config.callbacks.before_model_callback
34+
after_model_callbacks:
35+
- name: core_callback_config.callbacks.after_model_callback
36+
before_tool_callbacks:
37+
- name: core_callback_config.callbacks.before_tool_callback1
38+
- name: core_callback_config.callbacks.before_tool_callback2
39+
- name: core_callback_config.callbacks.before_tool_callback3
40+
after_tool_callbacks:
41+
- name: core_callback_config.callbacks.after_tool_callback1
42+
- name: core_callback_config.callbacks.after_tool_callback2
43+
- name: core_callback_config.callbacks.after_tool_callback3
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json
2+
name: search_agent
3+
model: gemini-2.0-flash
4+
description: 'an agent whose job it is to perform Google search queries and answer questions about the results.'
5+
instruction: You are an agent whose job is to perform Google search queries and answer questions about the results.
6+
tools:
7+
- name: google_search
8+
generate_content_config:
9+
temperature: 0.1
10+
max_output_tokens: 2000
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json
2+
agent_class: LlmAgent
3+
name: code_tutor_agent
4+
description: Coding tutor that helps with programming concepts and questions.
5+
instruction: |
6+
You are a helpful coding tutor that specializes in teaching programming concepts.
7+
8+
Your role is to:
9+
1. Explain programming concepts clearly and simply
10+
2. Help debug code issues
11+
3. Provide code examples and best practices
12+
4. Guide students through problem-solving approaches
13+
5. Encourage good coding habits
14+
15+
Always be patient, encouraging, and provide step-by-step explanations.

0 commit comments

Comments
 (0)