Skip to content

Commit 34d8c3d

Browse files
authored
Merge branch 'planner' into main
2 parents 84dff10 + 9ca4384 commit 34d8c3d

25 files changed

Lines changed: 3118 additions & 30 deletions

contrib/planners/pom.xml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2025 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
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">
18+
<modelVersion>4.0.0</modelVersion>
19+
20+
<parent>
21+
<groupId>com.google.adk</groupId>
22+
<artifactId>google-adk-parent</artifactId>
23+
<version>0.9.1-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
24+
<relativePath>../../pom.xml</relativePath>
25+
</parent>
26+
27+
<artifactId>google-adk-planners</artifactId>
28+
<name>Agent Development Kit - Planners</name>
29+
<description>Built-in planner implementations for the ADK PlannerAgent, including GOAP (Goal-Oriented Action Planning), P2P (Peer-to-Peer), and Supervisor planners.</description>
30+
31+
<dependencies>
32+
<!-- Main dependencies -->
33+
<dependency>
34+
<groupId>com.google.adk</groupId>
35+
<artifactId>google-adk</artifactId>
36+
<version>${project.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.google.genai</groupId>
40+
<artifactId>google-genai</artifactId>
41+
</dependency>
42+
43+
<!-- Test dependencies -->
44+
<dependency>
45+
<groupId>com.google.adk</groupId>
46+
<artifactId>google-adk</artifactId>
47+
<version>${project.version}</version>
48+
<type>test-jar</type>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter-api</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.junit.jupiter</groupId>
58+
<artifactId>junit-jupiter-engine</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>com.google.truth</groupId>
63+
<artifactId>truth</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.mockito</groupId>
68+
<artifactId>mockito-core</artifactId>
69+
<scope>test</scope>
70+
</dependency>
71+
</dependencies>
72+
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.adk.agents;
18+
19+
import io.reactivex.rxjava3.core.Single;
20+
21+
/**
22+
* Strategy interface for planning which sub-agent(s) to execute next.
23+
*
24+
* <p>A {@code Planner} is used by {@link PlannerAgent} to dynamically determine execution order at
25+
* runtime. The planning loop works as follows:
26+
*
27+
* <ol>
28+
* <li>{@link #init} is called once before the loop starts
29+
* <li>{@link #firstAction} returns the first action to execute
30+
* <li>The selected agent(s) execute, producing events and updating session state
31+
* <li>{@link #nextAction} is called with updated context to decide what to do next
32+
* <li>Steps 3-4 repeat until {@link PlannerAction.Done} or max iterations
33+
* </ol>
34+
*
35+
* <p>Returns {@link Single}{@code <PlannerAction>} to support both synchronous planners (wrap in
36+
* {@code Single.just()}) and asynchronous planners that call an LLM.
37+
*/
38+
public interface Planner {
39+
40+
/**
41+
* Initialize the planner with context and available agents. Called once before the planning loop
42+
* starts.
43+
*
44+
* <p>Default implementation is a no-op. Override to perform setup like building dependency
45+
* graphs.
46+
*/
47+
default void init(PlanningContext context) {}
48+
49+
/** Select the first action to execute. */
50+
Single<PlannerAction> firstAction(PlanningContext context);
51+
52+
/** Select the next action based on updated state and events. */
53+
Single<PlannerAction> nextAction(PlanningContext context);
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.adk.agents;
18+
19+
import com.google.common.collect.ImmutableList;
20+
21+
/**
22+
* Represents the next action a {@link Planner} wants the {@link PlannerAgent} to take.
23+
*
24+
* <p>This is a sealed interface with four variants:
25+
*
26+
* <ul>
27+
* <li>{@link RunAgents} — execute one or more sub-agents (multiple agents run in parallel)
28+
* <li>{@link Done} — planning is complete, no result to emit
29+
* <li>{@link DoneWithResult} — planning is complete with a final text result
30+
* <li>{@link NoOp} — skip this iteration (no-op), then ask the planner for the next action
31+
* </ul>
32+
*/
33+
public sealed interface PlannerAction
34+
permits PlannerAction.RunAgents,
35+
PlannerAction.Done,
36+
PlannerAction.DoneWithResult,
37+
PlannerAction.NoOp {
38+
39+
/** Run the specified sub-agent(s). Multiple agents are run in parallel. */
40+
record RunAgents(ImmutableList<BaseAgent> agents) implements PlannerAction {
41+
public RunAgents(BaseAgent singleAgent) {
42+
this(ImmutableList.of(singleAgent));
43+
}
44+
}
45+
46+
/** Plan is complete, no result to emit. */
47+
record Done() implements PlannerAction {}
48+
49+
/** Plan is complete with a final text result. */
50+
record DoneWithResult(String result) implements PlannerAction {}
51+
52+
/** Skip this iteration (no-op). */
53+
record NoOp() implements PlannerAction {}
54+
}

0 commit comments

Comments
 (0)