Skip to content

Session state references in agent instructions don't work - no actual injection occurs #460

@HelloThisIsFlo

Description

@HelloThisIsFlo

Describe the bug

The official Custom Agents documentation example claims that LLM agents can access session state data directly through natural language instructions (e.g., "based on the topic provided in session state with key 'topic'"), but session state is never actually injected into the LLM prompts. The agents work only through conversation context and output_key mappings, not through direct session state access as documented.

To Reproduce

Steps to reproduce the behavior:

  1. Copy the StoryFlowAgent example from https://google.github.io/adk-docs/agents/custom-agents/#full-code-example
  2. Configure ADK to use a local model via LM Studio:
    model=LiteLlm(
        model="openai/qwen3-14b-mlx",  # or any other model
        api_base="http://localhost:1234/v1",
    )
  3. In a separate terminal, execute lms log stream to begin monitoring raw requests sent to LM Studio
  4. Run the example
  5. Observe in the log stream that no session state data is included in the actual prompts, only conversation history

Expected behavior

Based on the documentation, I expected one of the following:

  1. Session state should be automatically injected into LLM prompts when referenced in instructions
  2. OR the documentation should not reference session state access in agent instructions

Screenshots

Example of actual LLM input from lms log stream (showing no session state injection):

<|im_start|>system
You are a story critic. Review the story provided in
session state with key 'current_story'. Provide 1-2 sentences of constructive criticism
on how to improve it. Focus on plot or character.

You are an agent. Your internal name is "Critic".<|im_end|>
<|im_start|>user
Generate a story about: a lonely robot finding a friend in a junkyard

For context:

[StoryGenerator] said:

In the sun-scorched desert junkyard, a rusted robot named Echo scoured debris for parts...
<|im_end|>

Notice that:

  • The instruction references "session state with key 'current_story'"
  • But no actual session state data is present in the prompt
  • Only conversation history ("For context: [StoryGenerator] said:...") is provided

Versions

  • OS: macOS
  • ADK version: 1.5.0
  • Python version: 3.12.9

Additional context

This issue affects the core Custom Agents documentation and potentially misleads developers about ADK capabilities. The example works in practice because:

  1. LLMs infer required data from conversation context (previous agent outputs)
  2. output_key parameters handle state persistence programmatically
  3. The session state references in instructions are essentially ignored

Impact:

  • Developers may expect session state injection functionality that doesn't exist
  • The documentation example suggests features not implemented in the current ADK version
  • Could lead to confusion about how multi-agent communication actually works in ADK

Suggested fixes:

  1. Implement actual session state injection to match the documentation, OR
  2. Update the documentation to remove session state references and explain the actual communication mechanism (conversation context + output_key)

Related documentation:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions