MCPcopy Index your code
hub / github.com/google/adk-python / A2aAgentExecutor

Class A2aAgentExecutor

src/google/adk/a2a/executor/a2a_agent_executor.py:58–378  ·  view source on GitHub ↗

An AgentExecutor that runs an ADK Agent against an A2A request and publishes updates to an event queue. Args: runner: The runner to use for the agent. config: The config to use for the executor. use_legacy: If true, force the legacy implementation. force_new_version: If true, f

Source from the content-addressed store, hash-verified

56
57@a2a_experimental
58class A2aAgentExecutor(AgentExecutor):
59 """An AgentExecutor that runs an ADK Agent against an A2A request and
60
61 publishes updates to an event queue.
62
63 Args:
64 runner: The runner to use for the agent.
65 config: The config to use for the executor.
66 use_legacy: If true, force the legacy implementation.
67 force_new_version: If true, force the new implementation regardless of the
68 extension.
69 """
70
71 def __init__(
72 self,
73 *,
74 runner: Runner | Callable[..., Runner | Awaitable[Runner]],
75 config: Optional[A2aAgentExecutorConfig] = None,
76 use_legacy: bool = False,
77 force_new_version: bool = False,
78 ):
79 super().__init__()
80 self._runner = runner
81 self._config = config or A2aAgentExecutorConfig()
82 self._use_legacy = use_legacy
83 self._force_new_version = force_new_version
84 self._executor_impl = None
85
86 async def _resolve_runner(self) -> Runner:
87 """Resolve the runner, handling cases where it's a callable that returns a Runner."""
88 # If already resolved and cached, return it
89 if isinstance(self._runner, Runner):
90 return self._runner
91 if callable(self._runner):
92 # Call the function to get the runner
93 result = self._runner()
94
95 # Handle async callables
96 if inspect.iscoroutine(result):
97 resolved_runner = await result
98 else:
99 resolved_runner = result
100
101 # Cache the resolved runner for future calls
102 self._runner = resolved_runner
103 return resolved_runner
104
105 raise TypeError(
106 'Runner must be a Runner instance or a callable that returns a'
107 f' Runner, got {type(self._runner)}'
108 )
109
110 @override
111 async def cancel(self, context: RequestContext, event_queue: EventQueue):
112 """Cancel the execution."""
113 if self._executor_impl:
114 await self._executor_impl.cancel(context, event_queue)
115 return

Calls

no outgoing calls