|
How to use dynamic prompt in ADK? I tried creating a variable |
Replies: 1 comment
|
Pass a function as from google.adk.agents import Agent
from google.adk.agents.readonly_context import ReadonlyContext
def choose_instruction(ctx: ReadonlyContext) -> str:
match ctx.state.get("type_error"):
case "syntax":
return "Help the user diagnose and fix syntax errors."
case "runtime":
return "Help the user diagnose runtime errors from the traceback."
case _:
return "Ask for the error message and relevant code."
root_agent = Agent(
name="error_helper",
model="gemini-2.5-flash",
instruction=choose_instruction,
)Make sure the tool or callback that determines the error writes If you only need to insert a value into a fixed prompt, a string such as |
Pass a function as
instruction, so ADK chooses the prompt from the current session state at runtime. A switch executed while constructing the agent only sees the state at construction time.