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

Function test_use_plugins

tests/unittests/tools/test_agent_tool.py:217–278  ·  view source on GitHub ↗

The agent tool can use plugins from parent runner.

()

Source from the content-addressed store, hash-verified

215
216
217def test_use_plugins():
218 """The agent tool can use plugins from parent runner."""
219
220 class ModelResponseCapturePlugin(BasePlugin):
221
222 def __init__(self):
223 super().__init__('plugin')
224 self.model_responses = {}
225
226 async def after_model_callback(
227 self,
228 *,
229 callback_context: CallbackContext,
230 llm_response: LlmResponse,
231 ) -> Optional[LlmResponse]:
232 response_text = []
233 for part in llm_response.content.parts:
234 if not part.text:
235 continue
236 response_text.append(part.text)
237 if response_text:
238 if callback_context.agent_name not in self.model_responses:
239 self.model_responses[callback_context.agent_name] = []
240 self.model_responses[callback_context.agent_name].append(
241 ''.join(response_text)
242 )
243
244 mock_model = testing_utils.MockModel.create(
245 responses=[
246 function_call_no_schema,
247 'response1',
248 'response2',
249 ]
250 )
251
252 tool_agent = Agent(
253 name='tool_agent',
254 model=mock_model,
255 )
256
257 root_agent = Agent(
258 name='root_agent',
259 model=mock_model,
260 tools=[AgentTool(agent=tool_agent)],
261 )
262
263 model_response_capture = ModelResponseCapturePlugin()
264 runner = testing_utils.InMemoryRunner(
265 root_agent, plugins=[model_response_capture]
266 )
267
268 assert testing_utils.simplify_events(runner.run('test1')) == [
269 ('root_agent', function_call_no_schema),
270 ('root_agent', function_response_no_schema),
271 ('root_agent', 'response2'),
272 ]
273
274 # should be able to capture response from both root and tool agent.

Callers

nothing calls this directly

Calls 4

runMethod · 0.95
AgentToolClass · 0.90
createMethod · 0.45

Tested by

no test coverage detected