AttributeError when using the GlobalInstructionPlugin with a Runner
Describe the bug
When using the GlobalInstructionPlugin with a Runner, an AttributeError is raised during the before_model_callback. The error message, 'CallbackContext' object has no attribute 'invocation_context', indicates that the plugin is trying to access an attribute that does not exist on the context object provided by the runner's execution flow.
To Reproduce
Steps to reproduce the behavior:
- Initialize a
Runnerand includeGlobalInstructionPluginin thepluginslist. - Call the
runner.run_async()method to start an agent execution. - The following error occurs.
Code:
# Simplified reproduction code based on provided snippets
from google.adk.runners import Runner
from google.adk.plugins import GlobalInstructionPlugin
# ... other necessary imports for agent, services, etc.
async def get_runner_async():
"""Returns a runner configured with the GlobalInstructionPlugin."""
# Assume root_agent and services are defined elsewhere
root_agent = ...
artifact_service = ...
session_service = ...
memory_service = ...
runner = Runner(
app_name="my_app",
agent=root_agent,
artifact_service=artifact_service,
session_service=session_service,
memory_service=memory_service,
plugins=[
GlobalInstructionPlugin(
global_instruction="This is a global instruction."
)
]
)
return runner
async def main():
"""Main execution function to demonstrate the bug."""
runner = await get_runner_async()
# The error occurs when run_async is called and the plugin's callback is triggered
async for event in runner.run_async(
user_id="test_user",
session_id="test_session",
new_message="Hello, agent!",
):
print(event)
# To run:
# import asyncio
# asyncio.run(main())
Hello, While migrating related parts of GlobalInstructionPlugin, I encountered this error and have created this PR to address it. Although using a variable prefixed with an underscore (_) is not ideal, it seems to be the most straightforward and practical solution in this case.
Hi thank you for pointing out this error, we merged @UlookEE . If this does not fix this problem please reopen the issue!
I'm seeing an error while use this plugin 2025-11-09 23:56:42,792 - ERROR - google_adk.google.adk.cli.adk_web_server - Failed to load plugin <google.adk.plugins.global_instruction_plugin.GlobalInstructionPlugin object at 0x1436f28d0>: 'GlobalInstructionPlugin' object has no attribute 'rsplit'
@adityapandey216 I don't think this is an implementation error in the plugin.