Skip to content

docs(plugins): correct before_run_callback flow control behavior#1822

Open
yana-gi wants to merge 1 commit into
google:mainfrom
yana-gi:fix/before-run-callback-flow-control
Open

docs(plugins): correct before_run_callback flow control behavior#1822
yana-gi wants to merge 1 commit into
google:mainfrom
yana-gi:fix/before-run-callback-flow-control

Conversation

@yana-gi

@yana-gi yana-gi commented Jun 9, 2026

Copy link
Copy Markdown

Summary

The Runner start callbacks section of the Plugins guide describes before_run_callback as returning a types.Content to replace the user's original message. That is actually the behavior of on_user_message_callback — the text (including the Purpose line) appears to have been duplicated from the User Message callbacks section.

In the implementation, returning a Content from before_run_callback halts the run (early exit): the Runner yields it as an early-exit event and skips all subsequent processing instead of invoking the agent.

Evidence

Runner._exec_with_plugin in src/google/adk/runners.py:

early_exit_result = await plugin_manager.run_before_run_callback(...)
if isinstance(early_exit_result, types.Content):
    early_exit_event = Event(..., content=early_exit_result)
    ...
    yield early_exit_event      # early exit, agent never runs
else:
    # normal execution

This also matches the BasePlugin.before_run_callback docstring:

Returning a value to halt execution of the runner and ends the runner with that event.

The early-exit behavior was established in adk-python bf72426a ("fix: runner was expecting Event object instead of Content object when using early exit feature", 2025-07-29), which predates this guide (added 2025-08-01). So the doc has been inaccurate since it was first written.

Changes

Fix the When It Runs, Purpose, and Flow Control bullets for before_run_callback:

  • When It Runs — clarify it runs after on_user_message_callback (the order shown in the callback diagram), not "before any other processing".
  • Purpose — global setup/initialization before the invocation (was duplicated from on_user_message_callback).
  • Flow Control — returning Content halts execution / early-exits, rather than replacing the user message.

The on_user_message_callback section is unchanged — its description is correct.

@netlify

netlify Bot commented Jun 9, 2026

Copy link
Copy Markdown

Deploy Preview for adk-docs-preview ready!

Name Link
🔨 Latest commit bbcc5fd
🔍 Latest deploy log https://app.netlify.com/projects/adk-docs-preview/deploys/6a27aa0bed4c610008c4d14a
😎 Deploy Preview https://deploy-preview-1822--adk-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@google-cla

google-cla Bot commented Jun 9, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

The "Runner start callbacks" section described `before_run_callback` as
returning a `types.Content` to "replace the user's original message". That is
actually the behavior of `on_user_message_callback`; the text (including the
"Purpose" line) was duplicated from that section.

In the implementation, returning a `Content` from `before_run_callback` halts
the run: the Runner yields it as an early-exit event and skips all subsequent
processing instead of invoking the agent.

See `Runner._exec_with_plugin` in `src/google/adk/runners.py`:

    early_exit_result = await plugin_manager.run_before_run_callback(...)
    if isinstance(early_exit_result, types.Content):
        early_exit_event = Event(..., content=early_exit_result)
        ...
        yield early_exit_event      # early exit, agent never runs
    else:
        # normal execution

This also matches the BasePlugin docstring: "Returning a value to halt
execution of the runner and ends the runner with that event."

Fix the "When It Runs", "Purpose", and "Flow Control" bullets accordingly.
@yana-gi yana-gi force-pushed the fix/before-run-callback-flow-control branch from 08456dc to bbcc5fd Compare June 9, 2026 05:52
@yana-gi yana-gi marked this pull request as ready for review June 9, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant