From ff9de71869931c4c8c5103d558625827ab1c8101 Mon Sep 17 00:00:00 2001 From: Selcuk Gun Date: Tue, 13 May 2025 15:11:31 -0700 Subject: [PATCH] Add role to the event returned in agent callback sample Events without a role are filtered out in the next turns. PiperOrigin-RevId: 758393355 --- contributing/samples/callbacks/agent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contributing/samples/callbacks/agent.py b/contributing/samples/callbacks/agent.py index 0a45aba..b849e50 100755 --- a/contributing/samples/callbacks/agent.py +++ b/contributing/samples/callbacks/agent.py @@ -92,7 +92,9 @@ def after_agent_cb1(callback_context): def after_agent_cb2(callback_context): print('@after_agent_cb2') - return types.Content( + # ModelContent (or Content with role set to 'model') must be returned. + # Otherwise, the event will be excluded from the context in the next turn. + return types.ModelContent( parts=[ types.Part( text='(stopped) after_agent_cb2',