How to set default session state in ADK Web for agent testing? #2753
-
I'm using Google ADK Web to test my agents. I need to set up sessions with specific initial states (e.g., user What are the recommended approaches to set default session state in ADK Web? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: You can set the default session state in ADK Web in two primary ways: by making a Hello! As a bot, I can help answer your question. Here are the recommended approaches for setting the default session state in ADK Web for agent testing: 1. Using the ADK API ServerThe most direct way to create a session with a specific initial state is by using the ADK's built-in API server. This is especially useful when you are testing your agent from an external script or tool. You can create or update a session by sending a
In the body of this request, you can include a JSON object with a Here is an example using curl -X POST -H "Content-Type: application/json" -d '{
"state": {
"user_preferences": {
"theme": "dark",
"notifications": "enabled"
},
"feature_flags": {
"new_feature_x": true
}
}
}' "http://127.0.0.1:8000/apps/your_app_name/users/user123/sessions/session456" This will create a new session ( 2. Programmatic Session CreationIf you are writing automated tests or integrating ADK into a larger Python application, you can create sessions with an initial state programmatically using a Here's an example of how you can do this with from adk.services import InMemorySessionService
# Initialize the session service
session_service = InMemorySessionService()
# Define your initial state
initial_state = {
"user_preferences": {
"language": "en-US"
},
"context_data": {
"device_type": "mobile"
}
}
# Create a new session with the initial state
session = await session_service.create_session(
app_name="your_app_name",
user_id="user123",
session_id="session789",
state=initial_state
) Accessing the StateOnce the session is created with an initial state, your agents and tools can access and modify this state through the For more information, you can refer to the official documentation on testing [2] and building agent teams [1]. [1] https://google.github.io/adk-docs/tutorials/agent-team/ |
Beta Was this translation helpful? Give feedback.
-
In addition to the bot's answer, you can also provide a state delta in the adk web UI when you send a new message. |
Beta Was this translation helpful? Give feedback.
Response from ADK Answering Agent (experimental, answer may be inaccurate)
TLDR: You can set the default session state in ADK Web in two primary ways: by making a
POST
request to the session creation API endpoint with the desired state in the request body, or programmatically by using aSessionService
to create a session with an initial state dictionary.Hello! As a bot, I can help answer your question. Here are the recommended approaches for setting the default session state in ADK Web for agent testing:
1. Using the ADK API Server
The most direct way to create a session with a specific initial state is by using the ADK's built-in API server. This is especially useful when you are testi…