Agent Executor (AX) is Google's open agentic orchestration runtime
Go
Add content conversion utilities to support confirmation and thought content for ADK bridge (#316)
zbl94dfc9a6014a8e
diff --git a/python/adk/README.md b/python/adk/README.mdindex 2726e44..589aad1 100644--- a/python/adk/README.md+++ b/python/adk/README.md@@ -47,10 +47,10 @@ export GEMINI_API_KEY="your-gemini-api-key-here"### 2. Start the Server-Run the server using your Python virtual environment:+Run the server using your Python virtual environment (from the project root):```bash-python python/adk/adk_agent_server.py [options]+python -m python.adk.adk_agent_server [options]```#### Available CLI Options:@@ -62,13 +62,13 @@ python python/adk/adk_agent_server.py [options]```bash# Start with default weather agent on port 50051-python python/adk/adk_agent_server.py+python -m python.adk.adk_agent_server# Start with debug logging enabled-python python/adk/adk_agent_server.py --debug+python -m python.adk.adk_agent_server --debug# Start with a custom agent file on a custom port with debug mode-python python/adk/adk_agent_server.py --agent_file path/to/your_agent.py --port 50055 --debug+python -m python.adk.adk_agent_server --agent_file path/to/your_agent.py --port 50055 --debug```Once started, the server will print:diff --git a/python/adk/__init__.py b/python/adk/__init__.pynew file mode 100644index 0000000..47cc7f8--- /dev/null+++ b/python/adk/__init__.py@@ -0,0 +1,15 @@+# Copyright 2026 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.++"""ADK Agent Server and utilities."""diff --git a/python/adk/adk_agent_server.py b/python/adk/adk_agent_server.pyindex f3dce8c..1bf4235 100644--- a/python/adk/adk_agent_server.py+++ b/python/adk/adk_agent_server.py@@ -20,16 +20,14 @@ import asyncioimport importlib.utilimport uuid-# Add the root of the project to sys.path to find generated protos-sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../proto')))--import ax_pb2-import ax_pb2_grpc-import content_pb2+from python.proto import ax_pb2+from python.proto import ax_pb2_grpc+from python.proto import content_pb2from google.adk.agents import Agent, InvocationContextfrom google.adk.sessions import Session, InMemorySessionServicefrom google.genai import typesfrom google.adk.runners import Runner, Event+from .content_conversion import ax_content_to_adk_part, adk_part_to_ax_contentclass ADKAgentServicer(ax_pb2_grpc.AgentServiceServicer):def __init__(self, agent, debug=False):@@ -62,8 +60,11 @@ class ADKAgentServicer(ax_pb2_grpc.AgentServiceServicer):# Hydrate past history into the session without executing themfor msg in historical_messages:- # TODO - Conversion logic for different content types beyond text- content = types.Content(role=msg.role, parts=[types.Part(text=msg.content.text.text)])+ part = ax_content_to_adk_part(msg.content)+ if not part:+ print(f"[WARNING] Skipping message with unsupported content type: {msg.content}")+ continue+ content = types.Content(role=msg.role, parts=[part])event = Event(invocation_id=str(uuid.uuid4()),author=self.agent.name,@@ -72,40 +73,26 @@ class ADKAgentServicer(ax_pb2_grpc.AgentServiceServicer):await self.session_service.append_event(session, event)# Execute only the latest query- content = types.Content(role=latest_message.role, parts=[types.Part(text=latest_message.content.text.text)])- async for event in self.runner.run_async(session_id=session.id, user_id=session.user_id, new_message=content):- if event.content and event.content.parts:- for part in event.content.parts:- # TODO - Conversion logic for different content types beyond text- if getattr(part, 'text', None):- if part.thought:- thought_summary = content_pb2.ThoughtSummaryContent(- text=content_pb2.TextContent(text=part.text)- )- response_msg = ax_pb2.Message(- role="assistant",- content=content_pb2.Content(- thought=content_pb2.ThoughtContent(- summary=[thought_summary]- )- )- )- else:- response_msg = ax_pb2.Message(- role="assistant",- content=content_pb2.Content(- text=content_pb2.TextContent(text=part.text)- )+ part = ax_content_to_adk_part(latest_message.content)+ if not part:+ print(f"[WARNING] Skipping message with unsupported content type: {latest_message.content}")+ else:+ content = types.Content(role=latest_message.role, parts=[part])+ async for event in self.runner.run_async(session_id=session.id, user_id=session.user_id, new_message=content):+ if event.content and event.content.parts:+ for part in event.content.parts:+ ax_content = adk_part_to_ax_content(part)+ if ax_content:+ response_msg = ax_pb2.Message(role="assistant", content=ax_content)+ # Sub agents should always send back the same IDs.+ yield_msg = ax_pb2.AgentMessage(+ conversation_id=conversation_id,+ exec_id=exec_id,+ outputs=ax_pb2.AgentOutputs(messages=[response_msg]))- # Send conversion_id and exec_id as it is, since ADK agent is stateless.- yield_msg = ax_pb2.AgentMessage(- conversation_id=conversation_id,- exec_id=exec_id,- outputs=ax_pb2.AgentOutputs(messages=[response_msg])- )- if self.debug:- print(f"[DEBUG] Yielding AgentMessage Response Chunk:\n{yield_msg}\n{'-'*80}")- yield yield_msg+ if self.debug:+ print(f"[DEBUG] Yielding AgentMessage Response Chunk:\n{yield_msg}\n{'-'*80}")+ yield yield_msg# Clean up/delete the stateless session to free resourcesawait self.session_service.delete_session(diff --git a/python/adk/adk_agent_server_test.py b/python/adk/adk_agent_server_test.pyindex b5e689f..8f82bde 100644--- a/python/adk/adk_agent_server_test.py+++ b/python/adk/adk_agent_server_test.py@@ -26,11 +26,8 @@ import asyncioimport sysimport os-# Add proto path to sys.path-sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../proto')))--import ax_pb2-import content_pb2+from python.proto import ax_pb2+from python.proto import content_pb2from google.genai import typesfrom google.adk.runners import Eventdiff --git a/python/adk/content_conversion.py b/python/adk/content_conversion.pynew file mode 100644index 0000000..96d142b--- /dev/null+++ b/python/adk/content_conversion.py@@ -0,0 +1,99 @@+# Copyright 2026 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.genai import types+from python.proto import content_pb2++def ax_content_to_adk_part(content: content_pb2.Content) -> types.Part:+ """Converts a AX Content to ADK Part."""+ # TODO - Conversion logic for more content types+ active_type = content.WhichOneof('type')++ if active_type == 'text':+ if content.text.text:+ return types.Part(text=content.text.text)++ elif active_type == 'thought':+ if content.thought.summary:+ texts = []+ for s in content.thought.summary:+ if s.WhichOneof('type') == 'text':+ texts.append(s.text.text)+ text = "".join(texts)+ if text:+ part = types.Part(text=text)+ part.thought = True+ return part++ elif active_type == 'confirmation':+ decision = content.confirmation.WhichOneof('decision')+ if decision == 'approval':+ return types.Part(+ function_response=types.FunctionResponse(+ id=content.confirmation.id,+ name="adk_request_confirmation",+ response={"approved": True}+ )+ )+ elif decision == 'decline':+ return types.Part(+ function_response=types.FunctionResponse(+ id=content.confirmation.id,+ name="adk_request_confirmation",+ response={"approved": False}+ )+ )+ else:+ return types.Part(+ function_call=types.FunctionCall(+ id=content.confirmation.id,+ name="adk_request_confirmation",+ args={+ "prompt": content.confirmation.question+ }+ )+ )++ return None++def adk_part_to_ax_content(part: types.Part) -> content_pb2.Content:+ """Converts an ADK Part to a AX Content."""+ # TODO - Conversion logic for more content types+ if getattr(part, 'text', None):+ if getattr(part, 'thought', None):+ thought_summary = content_pb2.ThoughtSummaryContent(+ text=content_pb2.TextContent(text=part.text)+ )+ return content_pb2.Content(+ thought=content_pb2.ThoughtContent(+ summary=[thought_summary]+ )+ )+ else:+ return content_pb2.Content(+ text=content_pb2.TextContent(text=part.text)+ )+ elif part.function_call and part.function_call.name == "adk_request_confirmation":+ args = part.function_call.args+ tool_conf = args.get("toolConfirmation")+ question = tool_conf.get("hint") if isinstance(tool_conf, dict) else None+ if question is None:+ question = str(args)+ return content_pb2.Content(+ confirmation=content_pb2.ConfirmationContent(+ id=part.function_call.id,+ question=question+ )+ )+ return Nonediff --git a/python/adk/content_conversion_test.py b/python/adk/content_conversion_test.pynew file mode 100644index 0000000..4c253e4--- /dev/null+++ b/python/adk/content_conversion_test.py@@ -0,0 +1,124 @@+# Copyright 2026 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 unittest+import sys+import os+from unittest.mock import MagicMock++from python.proto import content_pb2+from google.genai import types+from .content_conversion import ax_content_to_adk_part, adk_part_to_ax_content++class TestContentConversion(unittest.TestCase):++ def test_ax_content_to_adk_part_text(self):+ content = content_pb2.Content(text=content_pb2.TextContent(text="hello"))+ part = ax_content_to_adk_part(content)+ self.assertEqual(part.text, "hello")+ self.assertFalse(getattr(part, 'thought', False))++ def test_ax_content_to_adk_part_thought(self):+ thought_summary = content_pb2.ThoughtSummaryContent(+ text=content_pb2.TextContent(text="Thinking...")+ )+ content = content_pb2.Content(+ thought=content_pb2.ThoughtContent(+ summary=[thought_summary]+ )+ )+ part = ax_content_to_adk_part(content)+ self.assertEqual(part.text, "Thinking...")+ self.assertTrue(getattr(part, 'thought', False))++ def test_adk_part_to_ax_content_text(self):+ part = MagicMock()+ part.text = "hello"+ part.thought = False+ part.function_call = None+ content = adk_part_to_ax_content(part)+ self.assertEqual(content.text.text, "hello")++ def test_adk_part_to_ax_content_thought(self):+ part = MagicMock()+ part.text = "Thinking..."+ part.thought = True+ part.function_call = None+ content = adk_part_to_ax_content(part)+ self.assertTrue(content.HasField("thought"))+ self.assertEqual(len(content.thought.summary), 1)+ self.assertEqual(content.thought.summary[0].text.text, "Thinking...")++ def test_ax_content_to_adk_part_confirmation_request(self):+ content = content_pb2.Content(+ confirmation=content_pb2.ConfirmationContent(+ id="conf-123",+ question="Are you sure?"+ )+ )+ part = ax_content_to_adk_part(content)+ self.assertIsNotNone(part.function_call)+ self.assertEqual(part.function_call.name, "adk_request_confirmation")+ self.assertEqual(part.function_call.args["prompt"], "Are you sure?")+ self.assertEqual(part.function_call.id, "conf-123")+ self.assertNotIn("id", part.function_call.args)++ def test_ax_content_to_adk_part_confirmation_approval(self):+ content = content_pb2.Content(+ confirmation=content_pb2.ConfirmationContent(+ id="conf-123",+ approval=content_pb2.ApprovalDecision(approved=True)+ )+ )+ part = ax_content_to_adk_part(content)+ self.assertIsNotNone(part.function_response)+ self.assertEqual(part.function_response.name, "adk_request_confirmation")+ self.assertEqual(part.function_response.id, "conf-123")+ self.assertEqual(part.function_response.response["approved"], True)++ def test_ax_content_to_adk_part_confirmation_decline(self):+ content = content_pb2.Content(+ confirmation=content_pb2.ConfirmationContent(+ id="conf-123",+ decline=content_pb2.DeclineDecision(declined=True)+ )+ )+ part = ax_content_to_adk_part(content)+ self.assertIsNotNone(part.function_response)+ self.assertEqual(part.function_response.name, "adk_request_confirmation")+ self.assertEqual(part.function_response.id, "conf-123")+ self.assertEqual(part.function_response.response["approved"], False)++ def test_adk_part_to_ax_content_confirmation(self):+ class MockFunctionCall:+ def __init__(self, name, args, id):+ self.name = name+ self.args = args+ self.id = id++ part = MagicMock()+ part.text = None+ part.thought = False+ part.function_call = MockFunctionCall(+ name="adk_request_confirmation",+ args={"toolConfirmation": {"hint": "Are you sure?"}},+ id="conf-123"+ )+ content = adk_part_to_ax_content(part)+ self.assertTrue(content.HasField("confirmation"))+ self.assertEqual(content.confirmation.id, "conf-123")+ self.assertEqual(content.confirmation.question, "Are you sure?")++if __name__ == "__main__":+ unittest.main()diff --git a/python/proto/__init__.py b/python/proto/__init__.pynew file mode 100644index 0000000..ce346f1--- /dev/null+++ b/python/proto/__init__.py@@ -0,0 +1,21 @@+# Copyright 2026 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.++"""Generated proto files."""++import sys+import os++# Add this directory to sys.path to allow generated files to find each other.+sys.path.insert(0, os.path.dirname(__file__))