Skip to content

Commit c31f7ef

Browse files
committed
fix(runners): widen Runner.__init__ agent param to accept BaseNode
The `Runner.agent` class field is typed `Optional[BaseAgent | 'BaseNode']` and the runtime explicitly branches on `isinstance(self.agent, BaseNode)` in both `run_async` and `run_live`, so a `BaseNode` root (e.g. a `Workflow`) works at runtime. However, the `__init__` `agent` parameter was still typed `Optional[BaseAgent]`, so type checkers reject `Runner(agent=my_workflow)`. Widen the `__init__` `agent` annotation to `Optional[BaseAgent | 'BaseNode']` to match the class field, mirroring the existing forward-reference style used for the field and the `run_live` `node` parameter. This is a type-only change with no runtime behavior change. Fixes #6270
1 parent e6df097 commit c31f7ef

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/google/adk/runners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def __init__(
177177
*,
178178
app: Optional[App] = None,
179179
app_name: Optional[str] = None,
180-
agent: Optional[BaseAgent] = None,
180+
agent: Optional[BaseAgent | 'BaseNode'] = None,
181181
node: Any = None,
182182
plugins: Optional[List[BasePlugin]] = None,
183183
artifact_service: Optional[BaseArtifactService] = None,

tests/unittests/test_runners.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,22 @@ def test_resolve_app_with_agent_wraps_in_app(self):
14091409
assert runner.app_name == "test_app"
14101410
assert runner.agent is self.root_agent
14111411

1412+
def test_resolve_app_with_base_node_via_agent_param(self):
1413+
"""Test that a BaseNode root passed via `agent` is accepted."""
1414+
from google.adk.workflow._base_node import BaseNode
1415+
1416+
node = BaseNode(name="test_node")
1417+
runner = Runner(
1418+
app_name="test_app",
1419+
agent=node,
1420+
session_service=self.session_service,
1421+
artifact_service=self.artifact_service,
1422+
)
1423+
assert runner.app is not None
1424+
assert runner.app.root_agent is node
1425+
assert runner.app_name == "test_app"
1426+
assert runner.agent is node
1427+
14121428
def test_resolve_app_with_node_wraps_in_app(self):
14131429
"""Test that a bare node is wrapped into an App."""
14141430
from google.adk.workflow._base_node import BaseNode

0 commit comments

Comments
 (0)