Repository navigation
Labels
core[Component] This issue is related to the core interface and implementation
Description
An after_agent_callback that sets callback_context.actions.escalate = True
and returns None does not emit an escalation event. A LoopAgent runs its
child to max_iterations instead of stopping. Adding an unrelated state write
to the callback makes escalation work. Plugin after_agent_callback hooks
have the same failure through the shared callback handler.
Environment: ADK main (2.15.x), Python 3.11.
Run this offline reproduction without model credentials or network access:
"""Offline: action-only after-agent callbacks should stop their LoopAgent."""
import asyncio
import warnings
from google.adk.agents.base_agent import BaseAgent
from google.adk.agents.invocation_context import InvocationContext
from google.adk.agents.loop_agent import LoopAgent
from google.adk.events.event import Event
from google.adk.sessions.in_memory_session_service import InMemorySessionService
class Worker(BaseAgent):
async def _run_async_impl(self, ctx):
yield Event(author=self.name, invocation_id=ctx.invocation_id)
async def run(write_state):
def stop(callback_context):
callback_context.actions.escalate = True
if write_state:
callback_context.state["unrelated"] = True
worker = Worker(name="worker", after_agent_callback=stop)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
loop = LoopAgent(name="loop", max_iterations=3, sub_agents=[worker])
service = InMemorySessionService()
session = await service.create_session(app_name="app", user_id="user")
ctx = InvocationContext(session_service=service, session=session,
invocation_id="invocation", agent=loop)
events = [event async for event in loop.run_async(ctx)]
return sum(event.actions.escalate is True for event in events), len(events)
async def main():
print("action only (escalation events, total events):", await run(False))
print("same callback plus unrelated state write:", await run(True))
assert await run(False) == (1, 2)
assert await run(True) == (1, 2)
asyncio.run(main())Expected: both calls print (1, 2) (one escalation, two total events).
Actual: the action-only call prints (0, 3); the state-writing control prints
(1, 2). The action-only assertion fails.
Metadata
Metadata
Assignees
Labels
core[Component] This issue is related to the core interface and implementation
Activity
surajksharma07 commentedon Dec 2, 2026
Thanks @sumedh-aerram, your script reproduces this on main (b1566b8 / 2.15.1). I get (0, 3) for the action-only callback. I also checked 1.34.1 and 1.19.0 from PyPI and got the same result, so this isn't a regression. The check in _handle_agent_callbacks has only ever looked at state (and artifacts since 2.13).
I tried a workaround locally. It emits the event whenever callback_context.actions != EventActions() and calls has_delta() first so nested state writes still get flushed. Escalation then stops the loop and no-op callbacks still emit nothing. That seems to match #8391.
Could you check that it holds on your end? That includes the before_agent_callback path, which now emits events for action-only callbacks too. It would also help to confirm that no framework-set action fields make no-op callbacks start emitting events.
Once that's confirmed I'll ask the core owners to take a look at #8391. Until then, writing any state key in the callback is a safe workaround on released versions.
sumedh-aerram commentedon Dec 2, 2026
Thanks @surajksharma07. I confirmed this on #8391 merged with current main (now at f374364, which adds the docstring notes):
callback_context.actionsfirst, which flushes nested state writes, then emits an event when the actions differ fromEventActions().escalateinside aLoopAgentemits one content-less event authored by the agent. The agent body still runs once, then the loop stops. That is the same as a callback that escalates and writes state on main today. To skip the body, returnContentfrombefore_agent_callback. The PR now documents this in theLoopAgentandbefore_agent_callbackdocstrings.transfer_to_agentandskip_summarizationproduce the same event sequence as a callback that also writes state, minusstate_delta, with no duplicates.CallbackContextwith freshEventActions. Framework fields (agent state, tool confirmations, auth requests, compaction, rewind, route) go on separate events. Runner tests show no-op before and after callbacks emit nothing for LlmAgent, Sequential, Loop and Parallel agents, resumable or not, including runs with tool confirmations and agent-state checkpoints.tests/unittests/agents/test_agent_callback_events.py. 8 of 26 fail on upstreambase_agent.py, all of them action-only cases, and all 26 pass with the PR. The agents, flows and runners suites pass (2,379 passed).