refactor(kagent-adk): subclass upstream ADK executor and deduplicate …#1294
refactor(kagent-adk): subclass upstream ADK executor and deduplicate …#1294
Conversation
…A2A constants Structural alignment toward upstream google-adk A2A support: - Change A2aAgentExecutor to subclass google.adk.a2a.A2aAgentExecutor instead of the raw a2a-sdk AgentExecutor base class. Kagent's custom converters are plugged in via UpstreamA2aAgentExecutorConfig. All kagent-specific behavior (per-request runner lifecycle, OTel spans, Ollama error handling, partial event filtering, session naming, header forwarding, invocation ID tracking) is preserved via method overrides. - Replace locally-defined A2A DataPart metadata constants in kagent-core/_consts.py with imports from upstream google.adk.a2a.converters.part_converter. The values are identical; this eliminates duplication and ensures kagent stays in sync with upstream definitions. - Bump google-adk dependency to >=1.25.0. No behavior change — all existing tests pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
There was a problem hiding this comment.
Pull request overview
This PR refactors the kagent A2A (Agent-to-Agent) implementation to better align with upstream google-adk patterns while preserving all kagent-specific behaviors. The changes focus on eliminating code duplication and establishing a cleaner inheritance hierarchy.
Changes:
- A2aAgentExecutor now subclasses the upstream google-adk A2aAgentExecutor instead of the raw a2a-sdk AgentExecutor base class
- A2A DataPart metadata constants are now imported from upstream google.adk.a2a.converters.part_converter instead of being locally defined
- Bumped google-adk dependency from >=1.22.1 to >=1.25.0
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/uv.lock | Updated dependency versions: google-adk 1.22.1→1.25.0, fastapi 0.123.10→0.129.0, added pyopenssl 25.3.0 and httpx dependencies |
| python/packages/kagent-core/src/kagent/core/a2a/_consts.py | Replaced local A2A constant definitions with imports from upstream google.adk.a2a.converters.part_converter |
| python/packages/kagent-adk/src/kagent/adk/_agent_executor.py | Refactored A2aAgentExecutor to subclass upstream executor; added adapter functions for converters; removed unused opentelemetry import; moved asyncio import to proper location |
| python/packages/kagent-adk/pyproject.toml | Updated google-adk version requirement to >=1.25.0 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| A2A_DATA_PART_METADATA_TYPE_EXECUTABLE_CODE = "executable_code" | ||
| # Re-export A2A DataPart metadata constants from upstream google-adk. | ||
| # These are the canonical definitions — kagent should not redefine them. | ||
| from google.adk.a2a.converters.part_converter import ( # noqa: E402 |
There was a problem hiding this comment.
The # noqa: E402 comment is unnecessary here. E402 ("module level import not at top of file") applies when imports appear after code statements, but this import is at the top of the file immediately after comments. The noqa directive should be removed as it's misleading and serves no purpose.
| from google.adk.a2a.converters.part_converter import ( # noqa: E402 | |
| from google.adk.a2a.converters.part_converter import ( |
| from google.adk.a2a.converters.part_converter import ( # noqa: E402 | ||
| A2A_DATA_PART_METADATA_IS_LONG_RUNNING_KEY, | ||
| A2A_DATA_PART_METADATA_TYPE_CODE_EXECUTION_RESULT, | ||
| A2A_DATA_PART_METADATA_TYPE_EXECUTABLE_CODE, | ||
| A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL, | ||
| A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE, | ||
| A2A_DATA_PART_METADATA_TYPE_KEY, | ||
| ) |
There was a problem hiding this comment.
Import of 'A2A_DATA_PART_METADATA_IS_LONG_RUNNING_KEY' is not used.
Import of 'A2A_DATA_PART_METADATA_TYPE_CODE_EXECUTION_RESULT' is not used.
Import of 'A2A_DATA_PART_METADATA_TYPE_EXECUTABLE_CODE' is not used.
Import of 'A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL' is not used.
Import of 'A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE' is not used.
Import of 'A2A_DATA_PART_METADATA_TYPE_KEY' is not used.
Address PR review feedback: - Remove unnecessary `# noqa: E402` directive - Use `X as X` syntax for explicit re-exports so linters recognize these imports are intentionally re-exported, not unused Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
EItanya
left a comment
There was a problem hiding this comment.
Addressed both comments in dd68443:
- noqa removal — Good catch, removed the unnecessary
# noqa: E402. - "Unused imports" — These are intentional re-exports (consumed by
__init__.pyand downstream packages). Switched to the explicitX as Xre-export syntax so linters recognize them as intentional.
…dependency kagent-core is a lightweight library that should not depend on google-adk. The previous re-export from google.adk caused ImportError in packages like kagent-openai that depend on kagent-core but not google-adk. Define the constants as local string literals and add a sync-check test in kagent-adk to ensure they stay aligned with upstream. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
9e97da1 to
3ecd539
Compare
…A2A constants
Structural alignment toward upstream google-adk A2A support:
Change A2aAgentExecutor to subclass google.adk.a2a.A2aAgentExecutor instead of the raw a2a-sdk AgentExecutor base class. Kagent's custom converters are plugged in via UpstreamA2aAgentExecutorConfig. All kagent-specific behavior (per-request runner lifecycle, OTel spans, Ollama error handling, partial event filtering, session naming, header forwarding, invocation ID tracking) is preserved via method overrides.
Replace locally-defined A2A DataPart metadata constants in kagent-core/_consts.py with imports from upstream google.adk.a2a.converters.part_converter. The values are identical; this eliminates duplication and ensures kagent stays in sync with upstream definitions.
Bump google-adk dependency to >=1.25.0.
No behavior change — all existing tests pass.