I'm not able to access session id from 'tool_context.session.id. Here is the output if running the script when reaching the end of Step 4.
✅ New InMemorySessionService created for state demonstration.
✅ Session 'session_state_demo_001' created for user 'user_state_demo'.
--- Initial Session State ---
{'user_preference_temperature_unit': 'Celsius'}
✅ State-aware 'get_weather_stateful' tool defined.
Greeting and Farewell tools defined.
✅ Agent 'greeting_agent' created using model 'gemini-2.0-flash-exp'.
✅ Agent 'farewell_agent' created using model 'gemini-2.0-flash-exp'.
✅ Root Agent 'weather_agent_v4_stateful' created using stateful tool and output_key.
✅ Runner created for stateful root agent 'weather_agent_v4_stateful' using stateful session service.
--- Testing State: Temp Unit Conversion & output_key ---
>>> User Query to weather_agent_v4_stateful: What's the weather in London?
Warning: there are non-text parts in the response: ['function_call'],returning concatenated text result from text parts,check out the non text parts for full response from model.
❌ Error during run for agent weather_agent_v4_stateful: 'ToolContext' object has no attribute 'session'
<<< weather_agent_v4_stateful Response: Error occurred while running agent weather_agent_v4_stateful.
--- Manually Updating State: Setting unit to Fahrenheit ---
--- Session state updated. Current 'user_preference_temperature_unit': Fahrenheit ---
>>> User Query to weather_agent_v4_stateful: Tell me the weather in New York.
Warning: there are non-text parts in the response: ['function_call'],returning concatenated text result from text parts,check out the non text parts for full response from model.
❌ Error during run for agent weather_agent_v4_stateful: 'ToolContext' object has no attribute 'session'
<<< weather_agent_v4_stateful Response: Error occurred while running agent weather_agent_v4_stateful.
>>> User Query to weather_agent_v4_stateful: Hi!
Warning: there are non-text parts in the response: ['function_call'],returning concatenated text result from text parts,check out the non text parts for full response from model.
Default value is not supported in function declaration schema for Google AI.
Warning: there are non-text parts in the response: ['function_call'],returning concatenated text result from text parts,check out the non text parts for full response from model.
--- Tool: say_hello called with name: there ---
Default value is not supported in function declaration schema for Google AI.
<<< weather_agent_v4_stateful Response: Hello, there!
--- Final Session State ---
Preference: Celsius
Last Weather Report (from output_key): Hello, there!
Last City Checked (by tool): None
Full State: {'user_preference_temperature_unit': 'Celsius', 'last_weather_report': 'Hello, there
```!\n'}
I'm not able to access session id from 'tool_context.session.id. Here is the output if running the script when reaching the end of Step 4.