Skip to content

Plugin framework: on_state_change_callback is never invoked #4393

@mportdata

Description

@mportdata

Description

The plugin framework provides hooks for various lifecycle events (before/after agent, tool, model callbacks, etc.), but there is no mechanism to notify plugins when session state changes occur via event.actions.state_delta.

The BigQueryAgentAnalyticsPlugin already implements an on_state_change_callback() method, demonstrating real demand for this hook, but the framework never invokes it because:

  1. BasePlugin has no default on_state_change_callback method
  2. PluginManager has no dispatcher for it
  3. The runner never detects state deltas and triggers the callback

Expected Behavior

When an event with a non-empty state_delta is yielded from the runner, all registered plugins should have their on_state_change_callback invoked with the state delta (as a copy, to prevent mutation).

Proposed Solution

  1. Add on_state_change_callback to BasePlugin as a default no-op method
  2. Add "on_state_change_callback" to PluginCallbackName and a run_on_state_change_callback dispatcher to PluginManager
  3. In Runner._exec_with_plugin, after yielding the final event, check for state_delta and invoke the callback

The callback should be observational (return value ignored) and receive a copy of the state delta to prevent plugins from mutating event state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    core[Component] This issue is related to the core interface and implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions