@@ -288,11 +288,11 @@ from typing import Optional
288288from google.genai import types
289289from google.adk.agents.callback_context import CallbackContext
290290
291- def content_filter_callback(context : CallbackContext) -> Optional[types.Content]:
291+ def content_filter_callback(callback_context : CallbackContext) -> Optional[types.Content]:
292292 """After agent callback to filter sensitive content."""
293- # Access the response content through context
294- if hasattr(context , 'response') and context .response:
295- response_text = str(context .response)
293+ # Access the response content through callback_context
294+ if hasattr(callback_context , 'response') and callback_context .response:
295+ response_text = str(callback_context .response)
296296 if "confidential" in response_text.lower():
297297 filtered_text = response_text.replace("confidential", "[FILTERED]")
298298 return types.Content(parts=[types.Part(text=filtered_text)])
@@ -308,12 +308,12 @@ from google.adk.models.llm_request import LlmRequest
308308from google.adk.models.llm_response import LlmResponse
309309from google.adk.agents.callback_context import CallbackContext
310310
311- def log_model_request(context : CallbackContext, request: LlmRequest) -> Optional[LlmResponse]:
311+ def log_model_request(callback_context : CallbackContext, request: LlmRequest) -> Optional[LlmResponse]:
312312 """Before model callback to log requests."""
313313 print(f"Model request: {{request.contents}}")
314314 return None # Return None to proceed with original request
315315
316- def modify_model_response(context : CallbackContext, response: LlmResponse) -> Optional[LlmResponse]:
316+ def modify_model_response(callback_context : CallbackContext, response: LlmResponse) -> Optional[LlmResponse]:
317317 """After model callback to modify response."""
318318 # Modify response if needed
319319 return response # Return modified response or None for original
@@ -327,25 +327,25 @@ from typing import Any, Dict, Optional
327327from google.adk.tools.base_tool import BaseTool
328328from google.adk.tools.tool_context import ToolContext
329329
330- def validate_tool_input(tool: BaseTool, args : Dict[str, Any], context : ToolContext) -> Optional[Dict]:
330+ def validate_tool_input(tool: BaseTool, tool_args : Dict[str, Any], tool_context : ToolContext) -> Optional[Dict]:
331331 """Before tool callback to validate input."""
332332 # Validate or modify tool arguments
333- if "unsafe_param" in args :
334- del args ["unsafe_param"]
335- return args # Return modified args or None for original
333+ if "unsafe_param" in tool_args :
334+ del tool_args ["unsafe_param"]
335+ return tool_args # Return modified args or None for original
336336
337- def log_tool_result(tool: BaseTool, args : Dict[str, Any], context : ToolContext, result: Dict) -> Optional[Dict]:
337+ def log_tool_result(tool: BaseTool, tool_args : Dict[str, Any], tool_context : ToolContext, result: Dict) -> Optional[Dict]:
338338 """After tool callback to log results."""
339339 print(f"Tool {{tool.name}} executed with result: {{result}}")
340340 return None # Return None to keep original result
341341```
342342
343343## Callback Signature Summary:
344- - **Agent Callbacks**: `(CallbackContext) -> Optional[types.Content]`
345- - **Before Model**: `(CallbackContext, LlmRequest) -> Optional[LlmResponse]`
346- - **After Model**: `(CallbackContext, LlmResponse) -> Optional[LlmResponse]`
347- - **Before Tool**: `(BaseTool, Dict[str, Any], ToolContext) -> Optional[Dict]`
348- - **After Tool**: `(BaseTool, Dict[str, Any], ToolContext, Dict) -> Optional[Dict]`
344+ - **Agent Callbacks**: `(callback_context: CallbackContext) -> Optional[types.Content]`
345+ - **Before Model**: `(callback_context: CallbackContext, request: LlmRequest) -> Optional[LlmResponse]`
346+ - **After Model**: `(callback_context: CallbackContext, response: LlmResponse) -> Optional[LlmResponse]`
347+ - **Before Tool**: `(tool: BaseTool, tool_args: Dict[str, Any], tool_context: ToolContext) -> Optional[Dict]`
348+ - **After Tool**: `(tool: BaseTool, tool_args: Dict[str, Any], tool_context: ToolContext, result: Dict) -> Optional[Dict]`
349349
350350## Important ADK Requirements
351351
0 commit comments