|
| 1 | +from google.genai import types |
| 2 | + |
| 3 | + |
| 4 | +async def before_agent_callback(callback_context): |
| 5 | + print('@before_agent_callback') |
| 6 | + return None |
| 7 | + |
| 8 | + |
| 9 | +async def after_agent_callback(callback_context): |
| 10 | + print('@after_agent_callback') |
| 11 | + return None |
| 12 | + |
| 13 | + |
| 14 | +async def before_model_callback(callback_context, llm_request): |
| 15 | + print('@before_model_callback') |
| 16 | + return None |
| 17 | + |
| 18 | + |
| 19 | +async def after_model_callback(callback_context, llm_response): |
| 20 | + print('@after_model_callback') |
| 21 | + return None |
| 22 | + |
| 23 | + |
| 24 | +def after_agent_callback1(callback_context): |
| 25 | + print('@after_agent_callback1') |
| 26 | + |
| 27 | + |
| 28 | +def after_agent_callback2(callback_context): |
| 29 | + print('@after_agent_callback2') |
| 30 | + # ModelContent (or Content with role set to 'model') must be returned. |
| 31 | + # Otherwise, the event will be excluded from the context in the next turn. |
| 32 | + return types.ModelContent( |
| 33 | + parts=[ |
| 34 | + types.Part( |
| 35 | + text='(stopped) after_agent_callback2', |
| 36 | + ), |
| 37 | + ], |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +def after_agent_callback3(callback_context): |
| 42 | + print('@after_agent_callback3') |
| 43 | + |
| 44 | + |
| 45 | +def before_agent_callback1(callback_context): |
| 46 | + print('@before_agent_callback1') |
| 47 | + |
| 48 | + |
| 49 | +def before_agent_callback2(callback_context): |
| 50 | + print('@before_agent_callback2') |
| 51 | + |
| 52 | + |
| 53 | +def before_agent_callback3(callback_context): |
| 54 | + print('@before_agent_callback3') |
| 55 | + |
| 56 | + |
| 57 | +def before_tool_callback1(tool, args, tool_context): |
| 58 | + print('@before_tool_callback1') |
| 59 | + |
| 60 | + |
| 61 | +def before_tool_callback2(tool, args, tool_context): |
| 62 | + print('@before_tool_callback2') |
| 63 | + |
| 64 | + |
| 65 | +def before_tool_callback3(tool, args, tool_context): |
| 66 | + print('@before_tool_callback3') |
| 67 | + |
| 68 | + |
| 69 | +def after_tool_callback1(tool, args, tool_context, tool_response): |
| 70 | + print('@after_tool_callback1') |
| 71 | + |
| 72 | + |
| 73 | +def after_tool_callback2(tool, args, tool_context, tool_response): |
| 74 | + print('@after_tool_callback2') |
| 75 | + return {'test': 'after_tool_callback2', 'response': tool_response} |
| 76 | + |
| 77 | + |
| 78 | +def after_tool_callback3(tool, args, tool_context, tool_response): |
| 79 | + print('@after_tool_callback3') |
0 commit comments