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

EvalCase session state data does not seem to be propagated

Open khaledhikmat opened this issue 8 months ago • 8 comments

Hi, based on my observation and trials, the EvalCase session state data is not propagated. So if I have something like this:

eval_case = EvalCase(
  eval_id = "something",
  conversation = [
    ...
  ],
  session_input = SessionInput(
    app_name = "...",
    user_id = "...",
    state = {
      "some_key": "some_value" 
    }
)

The agent under test does not get the state value in the session. What am I doing wrong? Thanks.

khaledhikmat avatar Mar 28 '26 03:03 khaledhikmat

@khaledhikmat State propagation itself is actually working fine under the hood — the likely culprit is how it's being read inside the agent. Bare keys like "some_key" in session_input.state are session-scoped, which means they need to be accessed as tool_context.state.get("some_key") rather than tool_context.state.get("app:some_key") — the app: prefix would be looking for an app-scoped key that doesn't exist, so it'd just come back empty.

Could you try that access pattern in your tool or agent and let me know if that clears it up? It'd also help to see the snippet where you're reading the state — just in case there's something else going on there.

surajksharma07 avatar Mar 31 '26 14:03 surajksharma07

Hi @surajksharma07 , thanks for your response. I am actually using it in my agent's prompt using bare keys:

Input Format

You will receive a JSON event:

{some_key}

When running in regular mode (non-test), this works really well. However, when I run in pytest mode (using the EvalCase shown above), the agent does not see the {some_key} input and asks for input. As a workaround when running in test, I inject the event in the input prompt.

I am sorry I am not able to provide an actual code snippet because I work for an enterprise that does not allow us to participate in Github issues. So I am doing this from my personal account.

khaledhikmat avatar Apr 01 '26 02:04 khaledhikmat

@khaledhikmat Thanks for clarifying — using {some_key} in the instruction template is actually a different code path from tool context access, so my earlier reply was pointing at the wrong thing. Sorry about that!

Instruction template variables in ADK are supposed to be filled from session.state at call time, so this should work via eval too.

The fact that it works in regular mode but not specifically in eval is interesting — that might be a real gap worth tracking down.

To help isolate it: could you add a quick temporary tool to your agent that just returns tool_context.state.get("some_key") and invoke it in your EvalCase conversation? If the tool sees the value but the instruction template doesn't render it, the state is reaching the session and the bug is specifically in template substitution during eval. If the tool also comes back empty, the state isn't making it into the session at all — which points to a different issue entirely.

Also, what version of google-adk are you on? (pip show google-adk) — that'll help narrow down whether this is a known version-specific issue.

surajksharma07 avatar Apr 01 '26 13:04 surajksharma07

GM @surajksharma07 , thank you for your comment.

I just tried your good suggestion above and I actually see the data in tool_context.state.get("some_key") which is good...right?

I am on version 1.27.2.

I appreciate your help on this.

khaledhikmat avatar Apr 01 '26 13:04 khaledhikmat

@khaledhikmat That's exactly the diagnostic we needed — state is hitting the session correctly, so the issue is specifically that the eval path isn't feeding session.state into the instruction template substitution when building the LLM request.

Checked against v1.28.0 and there's no fix there either, so it's still open across versions.

Your workaround of injecting the value directly in the input prompt is the right call for now.

I'll get this flagged as a confirmed eval/instruction-template bug so it gets properly tracked and prioritized.

surajksharma07 avatar Apr 01 '26 14:04 surajksharma07

@ankursharmas Please have a look into it once.

surajksharma07 avatar Apr 01 '26 14:04 surajksharma07

Ok thanks @surajksharma07. I appreciate your help and tenacity.

khaledhikmat avatar Apr 01 '26 15:04 khaledhikmat

Hi @ankursharmas — are you still actively working on this? I'd be happy to pick it up and submit a fix if you're not currently on it. The root cause seems well-isolated from the thread discussion (eval runner not feeding session.state into instruction template substitution).

mahasarabesh avatar May 17 '26 10:05 mahasarabesh