Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

🚀 Smarter Google ADK Prompts: Inject State and Artifact Data Dynamically Placeholders

If you're building AI agents using Google's Agent Development Kit (ADK), you might have asked: "How can I make my agent prompts context-aware without hardcoding a ton of data?" Good news — while exploring how LlmAgent handles session d…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

If you're building AI agents using Google's Agent Development Kit (ADK), you might have asked:




"How can I make my agent prompts context-aware without hardcoding a ton of data?"




Good news — while exploring how LlmAgent handles session data and artifacts, we discovered a built-in (and kind of undocumented 👀) feature: placeholder substitution in the instruction field.



Let’s explore how this feature works and how you can use it to dynamically inject values from session.state and ArtifactService into your prompts — cleanly and automatically.









🎯 The Problem: Making Prompts Smarter



Agents often need to reference:




  • A user's previous input

  • Output from another agent/tool

  • A document or file uploaded earlier



ADK gives us tools like session.state and ArtifactService to manage that data.


But manually inserting all that into the prompt? 😵 That’s messy, hard to maintain, and likely to hit LLM context size limits.



Wouldn’t it be nice if your instruction could just say something like {user_name} or {artifact.summary.txt} — and the framework filled in the blanks?







🧩 The Solution: Built-In Placeholder Substitution



Turns out, you can do exactly that.



After diving into ADK's internals (especially _populate_values in instructions.py), we confirmed that ADK supports templated instructions using {} syntax. These placeholders are evaluated before sending the prompt to the LLM.





🧠 Supported Placeholder Types



Here’s what you can use:





1. Session State





  • {key} or {state.key} → looks up session.state["key"]


  • {app:key} → gets value from app-scoped state


  • {user:key} → gets value from user-scoped state


  • {key?} or {state.key?} → optional placeholder (returns empty string if key not found)



All values are converted to string with str() before being inserted.





2. Artifact Content





  • {artifact.filename} → inserts the content of the given artifact file (if available)





🧪 Confirmed in Tests



We found unit tests in test_instructions.py that confirm this behavior.


Tests like test_build_system_instruction verify that placeholders like {customerId}, {app:key}, {user:key}, and {artifact.filename} are correctly replaced with session or artifact data during instruction building.



✅ The placeholder feature is clearly supported both by the ADK source code and validated through unit tests!







🛠️ Example 1: Using State in Prompts



Let’s say a generator_agent writes a draft, and a reviewer_agent checks it.




from google.adk.agents import Agent

# Generator saves its output into session.state['draft_text']
generator = Agent(
name="generator_agent",
model="gemini-2.0-flash",
instruction="Write a short paragraph about subject X.",
output_key="draft_text"
)

# Reviewer reads the state and uses it in the prompt
reviewer = Agent(
name="reviewer_agent",
model="gemini-2.0-flash",
instruction="Please review the following draft: {draft_text}. Check for factual accuracy and provide feedback."
)






No need to manually pass variables around — ADK handles it for you 🙌









📁 Example 2: Using Artifacts in Prompts






from google.adk.agents import Agent

summarizer = Agent(
name="summarizer_agent",
model="gemini-2.0-flash",
instruction="Summarize the document provided in the artifact named 'meeting_notes.txt': {artifact.meeting_notes.txt}"
)






This is a clean way to reference file contents without bloating your code or prompt logic.









🔄 Alternative: Build Instructions in Code (If You Must)



If you want more control, you can still build prompts manually using callbacks:




def update_instruction_before_call(callback_context: CallbackContext, llm_request: LlmRequest):
draft = callback_context.state.get('draft_text', '')
llm_request.config.system_instruction = f"Please review the following draft: {draft}. Check for factual accuracy."
return None

reviewer = Agent(
name="reviewer_agent",
model="gemini-2.0-flash",
instruction=None,
before_model_callback=update_instruction_before_call
)






It works — but for simple cases, placeholder substitution is much cleaner ✨









🧭 Final Thoughts



The placeholder feature ({state.key}, {artifact.filename}) lets you write smarter, more flexible agent instructions without string hacking or bloated callbacks.



💡 Important Note:


While this behavior is clearly present in the source code and unit tests, it is not emphasized in the official documentation.


In fact, the official example in the docs here shows state referencing using manual Python string interpolation instead of placeholders — which slightly contradicts the built-in behavior we observed.



So, while it works beautifully today, this feature may be considered an internal implementation detail, and future ADK versions could potentially change or formalize it.


Always check the latest ADK release notes when upgrading! 🚀



Use it wisely, and you’ll make your ADK agents a whole lot more powerful.






👍 Found this helpful? Let’s connect in the comments — and share if you discover any other hidden ADK tricks!

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Remote Code Execution (RCE) Defense
Syntax validiert (0 Fehler)
title: Detect Exploitation - 🚀 Smarter Google ADK Prompts: Inject State and Artifact Data Dynamically Placeholders
id: 1cfd35a9-664a-46f5-9d2e-19a8072a8375
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "🚀 Smarter Google ADK Prompts: " ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Smarter Google ADK Prompts Inject State ")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*Smarter Google ADK Prompts Inject State *"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Smarter Google ADK Prompts Inject State "
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

CTI Threat Relationship Graph2 Knoten / 1 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich 🚀 Smarter Google ADK Prompts: Inject Sta.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 🚀 Smarter Google ADK Prompts: Inject State and Artifact Data Dynamically Placeholders

Thematisch verwandte Begriffe: Smarter, Google, Prompts, Inject · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-97818 | phpIPAM through 1.8.3 has incorrect authorization for id=="admins" and i…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag