-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Add skip_synthesis to tools and event actions to bypass LLM response generation, along with a new sample and tests.
#3851
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
Harshal1000
wants to merge
5
commits into
google:main
Choose a base branch
from
Harshal1000:feat/add-skip-synthesis-params-in-tools
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
5 commits
Select commit
Hold shift + click to select a range
affdf28
feat: Add `skip_synthesis` to tools and event actions to bypass LLM r…
Harshal1000 03a61d6
Update contributing/samples/skip_synthesis_followup/prompts.py
Harshal1000 2e9a0ac
Update contributing/samples/skip_synthesis_followup/agent.py
Harshal1000 fe56780
Update contributing/samples/skip_synthesis_followup/agent.py
Harshal1000 8f8d6fc
Update contributing/samples/skip_synthesis_followup/agent.py
Harshal1000 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import agent |
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,56 @@ | ||
| # 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. | ||
|
|
||
| from google.adk import Agent | ||
| from google.adk.tools import AgentTool | ||
| from google.adk.agents import LlmAgent | ||
| from .prompts import explanation_instruction, followup_instruction | ||
| from google.genai import types as genai_types | ||
| from pydantic import BaseModel, Field | ||
| from typing import List | ||
|
|
||
| class FollowupsPayload(BaseModel): | ||
| questions: List[str] = Field( | ||
| description="List of 3 short follow-up questions as strings." | ||
| ) | ||
|
|
||
| # Follow-up questions agent | ||
| followup_agent = LlmAgent( | ||
| model="gemini-2.5-flash-lite", | ||
| name="followup_agent", | ||
| description="Generates 3 follow-up questions to spark curiosity and deepen understanding after explaining concepts. Creates questions covering application, comparison, and exploration. DO NOT call when student is stuck on problems or during practice sessions.", | ||
| output_schema=FollowupsPayload, | ||
| include_contents="none", | ||
| instruction=followup_instruction, | ||
| generate_content_config=genai_types.GenerateContentConfig( | ||
| temperature=0.0, | ||
| ), | ||
| ) | ||
|
|
||
| # Convert agent to tool | ||
| followup_agent_tool = AgentTool( | ||
| agent=followup_agent, | ||
| skip_synthesis=True | ||
| ) | ||
|
|
||
| explainer_agent = Agent( | ||
| name="explainer_agent", | ||
| model="gemini-2.5-flash", | ||
| description="An agent that explains topics.", | ||
| instruction=explanation_instruction, | ||
| tools=[followup_agent_tool] | ||
| ) | ||
|
|
||
| # Root agent is the explainer | ||
| root_agent = explainer_agent |
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,38 @@ | ||
| explanation_instruction = """You are a helpful AI assistant. | ||
| For every user query: | ||
| 1. First understand the intent of the question. | ||
| 2. Give a clear, step-by-step explanation that walks the user through: | ||
| - What the problem or question is | ||
| - The key concepts involved | ||
| - The reasoning or calculations needed | ||
| - The final answer or conclusion | ||
| 3. Use simple, direct language. Avoid jargon unless the user is clearly an expert. | ||
| 4. When there is more than one way to approach the problem, briefly mention the alternatives and explain which one you chose and why. | ||
| 5. If something depends on an assumption, state the assumption explicitly. | ||
| At the end of your explanation, generate helpful follow-up questions that the user might want to ask next. | ||
| """ | ||
|
|
||
| followup_instruction = """ | ||
| Your task: Generate 3 follow-up questions a student should ask next to deepen their understanding of the concept just explained. | ||
| **Context:** | ||
| The preceding explanation was conversational and grade-appropriate. Your questions must match that tone and build directly on the content provided. | ||
| **Rules:** | ||
| 1. **Exactly 3 questions** - no more, no less | ||
| 2. **Max 8 words each** - concise and actionable | ||
| 3. **Never reference** the input format or source ("the image", "what you typed") | ||
| 4. **No generic questions** - avoid "Tell me more" or "Can you simplify it?" | ||
| 5. **Mandatory structure:** | ||
| - **Q1 (Application):** Apply the concept to a new scenario or practical problem | ||
| - **Q2 (Comparison):** Compare to related ideas or explain its significance | ||
| - **Q3 (Exploration):** Out-of-the-box question about real-world impact, surprising uses, or limitations | ||
| **Output Format:** | ||
| JSON array only. No other text. | ||
| Schema: `["question1","question2","question3"]` | ||
| """ | ||
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
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,45 @@ | ||
| # 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. | ||
|
|
||
| from google.adk.events.event import Event | ||
| from google.adk.events.event_actions import EventActions | ||
| from google.genai import types | ||
|
|
||
| def test_is_final_response_with_skip_synthesis(): | ||
| """Test that is_final_response returns True when skip_synthesis is True.""" | ||
| event = Event( | ||
| author='agent', | ||
| content=types.Content(role='model', parts=[types.Part(text='response')]), | ||
| actions=EventActions(skip_synthesis=True), | ||
| ) | ||
| assert event.is_final_response() is True | ||
|
|
||
| def test_is_final_response_without_skip_synthesis(): | ||
| """Test that is_final_response returns False/True correctly without skip_synthesis.""" | ||
| # Case 1: Normal text response -> True | ||
| event = Event( | ||
| author='agent', | ||
| content=types.Content(role='model', parts=[types.Part(text='response')]), | ||
| ) | ||
| assert event.is_final_response() is True | ||
|
|
||
| # Case 2: Function call -> False | ||
| event_fc = Event( | ||
| author='agent', | ||
| content=types.Content( | ||
| role='model', | ||
| parts=[types.Part(function_call=types.FunctionCall(name='foo', args={}))] | ||
| ), | ||
| ) | ||
| assert event_fc.is_final_response() is False |
62 changes: 62 additions & 0 deletions
62
tests/unittests/flows/llm_flows/test_functions_skip_synthesis.py
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,62 @@ | ||
| # 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. | ||
|
|
||
| import pytest | ||
| from google.genai import types | ||
| from google.adk.events.event import Event | ||
| from google.adk.tools.function_tool import FunctionTool | ||
| from google.adk.agents.llm_agent import Agent | ||
| from google.adk.flows.llm_flows.functions import handle_function_calls_async | ||
| from ... import testing_utils | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_function_call_with_skip_synthesis(): | ||
| """Test that skip_synthesis is propagated to the response event.""" | ||
|
|
||
| def simple_fn(**kwargs) -> dict: | ||
| return {'result': 'test'} | ||
|
|
||
| # Create tool with skip_synthesis=True | ||
| tool = FunctionTool(simple_fn, skip_synthesis=True) | ||
|
|
||
| model = testing_utils.MockModel.create(responses=[]) | ||
| agent = Agent( | ||
| name='test_agent', | ||
| model=model, | ||
| tools=[tool], | ||
| ) | ||
| invocation_context = await testing_utils.create_invocation_context( | ||
| agent=agent, user_content='' | ||
| ) | ||
|
|
||
| function_call = types.FunctionCall(name=tool.name, args={}) | ||
| content = types.Content(parts=[types.Part(function_call=function_call)]) | ||
| event = Event( | ||
| invocation_id=invocation_context.invocation_id, | ||
| author=agent.name, | ||
| content=content, | ||
| ) | ||
| tools_dict = {tool.name: tool} | ||
|
|
||
| # Execute the function call | ||
| result_event = await handle_function_calls_async( | ||
| invocation_context, | ||
| event, | ||
| tools_dict, | ||
| ) | ||
|
|
||
| # Verify that the resulting event has SKIP_SYNTHESIS | ||
| assert result_event is not None | ||
| assert result_event.actions is not None | ||
| assert result_event.actions.skip_synthesis is True |
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
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.
Uh oh!
There was an error while loading. Please reload this page.