adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Global Instructions not getting applied using the GlobalInstructionPlugin

Open iampushkar opened this issue 1 year ago • 1 comments

Describe the bug I am noticing that the global_instructions are not getting applied using the plugin. from google.adk.plugins.global_instruction_plugin import GlobalInstructionPlugin.

Earlier, global_instructions needed to be passed along the root_agent, and it was working as expected. But I saw that this field is deprecated and will be removed in future versions. After trying out the GlobalInstructionPlugin, it's not working as expected.

Code Snippet

  • app.py
from google.adk.apps.app import App, EventsCompactionConfig
from .agent import root_agent, GLOBAL_INSTRUCTION
from google.adk.plugins.reflect_retry_tool_plugin import ReflectAndRetryToolPlugin, TrackingScope
from google.adk.plugins.logging_plugin import LoggingPlugin
from google.adk.plugins.global_instruction_plugin import GlobalInstructionPlugin

retry_plugin = ReflectAndRetryToolPlugin(
    max_retries=3,
    throw_exception_if_retry_exceeded=False,
    tracking_scope=TrackingScope.GLOBAL
)

logging_plugin = LoggingPlugin()

global_instruction_plugin = GlobalInstructionPlugin(
    global_instruction=GLOBAL_INSTRUCTION
)

compaction_config = EventsCompactionConfig(
    compaction_interval=3,  # Summarize history every 3 turns
    overlap_size=1          # Include 1 event from the previous window for continuity
)

app = App(
    name=root_agent.name,
    root_agent=root_agent,
    events_compaction_config=compaction_config,
    plugins=[logging_plugin, retry_plugin,global_instruction_plugin]
)

  • main.py
import os

import uvicorn
from fastapi import FastAPI
from google.adk.cli.fast_api import get_fast_api_app
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Get the directory where main.py is located
AGENT_DIR = os.path.dirname(os.path.abspath(__file__))
# Example session DB URL (e.g., SQLite)
SESSION_DB_URL = "sqlite:///./sessions.db"
# Example allowed origins for CORS
ALLOWED_ORIGINS = ["http://localhost", "http://localhost:8000", "*"]
# Set web=True if you intend to serve a web interface, False otherwise
SERVE_WEB_INTERFACE = True

# Call the function to get the FastAPI app instance
app: FastAPI = get_fast_api_app(
    agents_dir=AGENT_DIR,
    session_service_uri=SESSION_DB_URL,
    allow_origins=ALLOWED_ORIGINS,
    web=SERVE_WEB_INTERFACE,
)

if __name__ == "__main__":
    # Use the PORT environment variable provided by Cloud Run, defaulting to 8000
    uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 8000)))

In the GLOBAL_INSTRUCTION prompt is to return the response in a particular HTML format.

I noticed that even the LoggingPlugin & ReflectAndRetryToolPlugin is not adding the logs. However I am more concerned towards the global instructions otherwise my entire prod will break.

Do ensure not to remove the global_instructions field from the Agent for now.

Screenshots Here's the response using global instruction plugin ❌

Image

Here's the response using global_instruction field ✅

Image

Desktop (please complete the following information):

  • OS: macOS
  • Python version(python -V): 3.12.10
  • ADK version(pip show google-adk): 1.19.0

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used(e.g. gemini-2.5-pro) - GPT4.1

Additional context None of the plugins that i tried is working as expected. What i am missing out?

iampushkar avatar Nov 27 '25 12:11 iampushkar

Hi @iampushkar Thanks for raising this issue.

The ADK loader only detected root_agent and never your App, so the plugin list stayed empty—export app from agent.py (with init.py importing it) to register GlobalInstructionPlugin and the other plugins

GWeale avatar Dec 02 '25 02:12 GWeale