-
Notifications
You must be signed in to change notification settings - Fork 296
Add support of ReAct and builtin planner #318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
git-hulk
wants to merge
2
commits into
google:main
Choose a base branch
from
git-hulk:feature/react-planner
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // Package planner provides interfaces and implementations for AI agent planning capabilities. | ||
| package planner | ||
|
|
||
| import ( | ||
| "google.golang.org/genai" | ||
|
|
||
| "google.golang.org/adk/agent" | ||
| "google.golang.org/adk/model" | ||
| ) | ||
|
|
||
| // BasePlanner is the abstract base interface for all planners. | ||
| // | ||
| // The planner allows the agent to generate plans for the queries to guide its | ||
| // action. | ||
| type BasePlanner interface { | ||
| // BuildPlanningInstruction builds the system instruction to be appended to the LLM request for planning. | ||
| // | ||
| // Args: | ||
| // readonlyContext: The readonly context of the invocation. | ||
| // llmRequest: The LLM request. Readonly. | ||
| // | ||
| // Returns: | ||
| // The planning system instruction, or empty string if no instruction is needed. | ||
| BuildPlanningInstruction(readonlyContext agent.ReadonlyContext, llmRequest *model.LLMRequest) string | ||
|
|
||
| // ProcessPlanningResponse processes the LLM response for planning. | ||
| // | ||
| // Args: | ||
| // callbackContext: The callback context of the invocation. | ||
| // responseParts: The LLM response parts. Readonly. | ||
| // | ||
| // Returns: | ||
| // The processed response parts, or nil if no processing is needed. | ||
| ProcessPlanningResponse(callbackContext agent.CallbackContext, responseParts []*genai.Part) []*genai.Part | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package planner | ||
|
|
||
| import ( | ||
| "google.golang.org/genai" | ||
|
|
||
| "google.golang.org/adk/agent" | ||
| "google.golang.org/adk/model" | ||
| ) | ||
|
|
||
| // BuiltInPlanner is the built-in planner that uses model's built-in thinking features. | ||
| type BuiltInPlanner struct { | ||
| // ThinkingConfig is the config for model built-in thinking features. An error | ||
| // will be returned if this field is set for models that don't support | ||
| // thinking. | ||
| ThinkingConfig *genai.ThinkingConfig | ||
| } | ||
|
|
||
| // NewBuiltInPlanner initializes the built-in planner. | ||
| // | ||
| // Args: | ||
| // | ||
| // thinkingConfig: Config for model built-in thinking features. An error | ||
| // will be returned if this field is set for models that don't support | ||
| // thinking. | ||
| func NewBuiltInPlanner(thinkingConfig *genai.ThinkingConfig) *BuiltInPlanner { | ||
| return &BuiltInPlanner{ | ||
| ThinkingConfig: thinkingConfig, | ||
| } | ||
| } | ||
|
|
||
| // ApplyThinkingConfig applies the thinking config to the LLM request. | ||
| // | ||
| // Args: | ||
| // | ||
| // llmRequest: The LLM request to apply the thinking config to. | ||
| func (b *BuiltInPlanner) ApplyThinkingConfig(llmRequest *model.LLMRequest) { | ||
| if b.ThinkingConfig != nil { | ||
| if llmRequest.Config == nil { | ||
| llmRequest.Config = &genai.GenerateContentConfig{} | ||
| } | ||
| llmRequest.Config.ThinkingConfig = b.ThinkingConfig | ||
| } | ||
| } | ||
|
|
||
| // BuildPlanningInstruction implements BasePlanner. | ||
| func (b *BuiltInPlanner) BuildPlanningInstruction(readonlyContext agent.ReadonlyContext, llmRequest *model.LLMRequest) string { | ||
| // Built-in planner doesn't add planning instructions | ||
| return "" | ||
| } | ||
|
|
||
| // ProcessPlanningResponse implements BasePlanner. | ||
| func (b *BuiltInPlanner) ProcessPlanningResponse(callbackContext agent.CallbackContext, responseParts []*genai.Part) []*genai.Part { | ||
| // Built-in planner doesn't process planning response | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package planner | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "google.golang.org/genai" | ||
| ) | ||
|
|
||
| func TestBuiltInPlanner_New(t *testing.T) { | ||
| p := NewBuiltInPlanner(nil) | ||
| if p == nil { | ||
| t.Fatal("NewBuiltInPlanner returned nil") | ||
| } | ||
| if p.ThinkingConfig != nil { | ||
| t.Errorf("Expected ThinkingConfig to be nil, got %+v", p.ThinkingConfig) | ||
| } | ||
|
|
||
| config := &genai.ThinkingConfig{IncludeThoughts: true} | ||
| p = NewBuiltInPlanner(config) | ||
| if p == nil { | ||
| t.Fatal("NewBuiltInPlanner returned nil") | ||
| } | ||
| if p.ThinkingConfig == nil { | ||
| t.Fatal("Expected ThinkingConfig to be set, got nil") | ||
| } | ||
| if p.ThinkingConfig.IncludeThoughts != true { | ||
| t.Errorf("Expected IncludeThoughts true, got %v", p.ThinkingConfig.IncludeThoughts) | ||
| } | ||
| } | ||
|
|
||
| func TestBuiltInPlanner_BuildPlanningInstruction(t *testing.T) { | ||
| p := NewBuiltInPlanner(&genai.ThinkingConfig{ | ||
| IncludeThoughts: true, | ||
| }) | ||
|
|
||
| instruction := p.BuildPlanningInstruction(nil, nil) | ||
| if instruction != "" { | ||
| t.Errorf("BuiltInPlanner should return empty instruction, got: %q", instruction) | ||
| } | ||
| } | ||
|
|
||
| func TestBuiltInPlanner_ProcessPlanningResponse(t *testing.T) { | ||
| p := NewBuiltInPlanner(&genai.ThinkingConfig{ | ||
| IncludeThoughts: true, | ||
| }) | ||
|
|
||
| parts := []*genai.Part{ | ||
| {Text: "Hello world"}, | ||
| {Text: "Another part"}, | ||
| } | ||
|
|
||
| result := p.ProcessPlanningResponse(nil, parts) | ||
| if result != nil { | ||
| t.Errorf("BuiltInPlanner should return nil for response processing, got: %+v", result) | ||
| } | ||
| } | ||
|
|
||
| func TestBuiltInPlanner_ApplyThinkingConfig(t *testing.T) { | ||
| req := &struct { | ||
| Config *genai.GenerateContentConfig | ||
| }{ | ||
| Config: nil, | ||
| } | ||
|
|
||
| if req.Config != nil && req.Config.ThinkingConfig != nil { | ||
| t.Error("Expected ThinkingConfig to not be set") | ||
| } | ||
|
|
||
| thinkingConfig := &genai.ThinkingConfig{IncludeThoughts: true} | ||
| req = &struct { | ||
| Config *genai.GenerateContentConfig | ||
| }{ | ||
| Config: nil, | ||
| } | ||
|
|
||
| if req.Config == nil { | ||
| req.Config = &genai.GenerateContentConfig{} | ||
| } | ||
| req.Config.ThinkingConfig = thinkingConfig | ||
|
|
||
| if req.Config == nil { | ||
| t.Error("Expected Config to be set") | ||
| } else if req.Config.ThinkingConfig == nil { | ||
| t.Error("Expected ThinkingConfig to be set") | ||
| } else if req.Config.ThinkingConfig.IncludeThoughts != true { | ||
| t.Errorf("Expected IncludeThoughts true, got %v", req.Config.ThinkingConfig.IncludeThoughts) | ||
| } | ||
|
|
||
| req = &struct { | ||
| Config *genai.GenerateContentConfig | ||
| }{ | ||
| Config: &genai.GenerateContentConfig{}, | ||
| } | ||
| req.Config.ThinkingConfig = thinkingConfig | ||
|
|
||
| if req.Config.ThinkingConfig == nil { | ||
| t.Error("Expected ThinkingConfig to be set") | ||
| } else if req.Config.ThinkingConfig.IncludeThoughts != true { | ||
| t.Errorf("Expected IncludeThoughts true, got %v", req.Config.ThinkingConfig.IncludeThoughts) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // Package planner provides planning capabilities for AI agents. | ||
| // | ||
| // Planners allow agents to generate structured plans for user queries to guide their actions. | ||
| // This package includes implementations for: | ||
| // - BasePlanner: The core planner interface | ||
| // - BuiltInPlanner: Uses model's built-in thinking features | ||
| // - ReActPlanner: Plan-Re-Act planner that constrains LLM response to generate plans before actions | ||
| package planner |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a good reason to make this read only?
One thing we want to be able to do is pass around budget information to the instruction generation process. Having writable context would be helpful, otherwise we have to basically shim this entire process