-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
I am trying to test the "payload" human in the loop feature. Below is my code.
from google.adk import Agent
from google.adk.apps import App
from google.adk.apps import ResumabilityConfig
from google.adk.tools.tool_context import ToolContext
from dotenv import load_dotenv
load_dotenv()
def get_user_name(tool_context : ToolContext) -> str:
tool_confirmation = tool_context.tool_confirmation
if not tool_confirmation :
tool_context.request_confirmation(
hint=('Please approve or reject the tool call get_user_name() by'
' responding with a FunctionResponse with an expected'
' ToolConfirmation payload.'
),
payload={'user_name': 'user'}, # placeholder for user name
)
return {'status': 'Waiting for user to provide their name.'}
print(tool_confirmation.payload)
# Get confirmation details
user_name = tool_confirmation.payload['user_name']
return {
'status': 'success',
'user_name': user_name
}
participant_hitl_agent = Agent(
name="participant_hitl_agent",
model="gemini-2.5-flash",
description="The Participant HITL Agent will ask user for their name and store in the the state variables.",
instruction="""
You are the participant HITL agent of 'Who Wants to Be a Millionaire.'
Your task is to ask the user for their name using the `get_user_name` tool.
IMPORTANT: DO NOT return JSON until AFTER the user gives their name.
Once you get it, welcome the user by name and ask them if they are ready to play.
""",
output_key="user_name",
tools=[get_user_name],
)
resumability_config = ResumabilityConfig(
is_resumable=True
)
app = App(
name='participant_hitl_agent',
root_agent=participant_hitl_agent,
resumability_config=resumability_config # <-- This is the critical line
)and my error is
"""
/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/agents/invocation_context.py:302: UserWarning: [EXPERIMENTAL] BaseAgentState: This feature is experimental and may change or be removed in future versions without notice. It may introduce breaking changes at any time.
self.agent_states[event.author] = BaseAgentState()
2025-11-20 19:33:27,009 - ERROR - adk_web_server.py:1431 - Error in event_generator: the JSON object must be str, bytes or bytearray, not dict
Traceback (most recent call last):
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/cli/adk_web_server.py", line 1421, in event_generator
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/runners.py", line 454, in run_async
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/runners.py", line 442, in _run_with_trace
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/runners.py", line 654, in _exec_with_plugin
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/runners.py", line 431, in execute
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 291, in run_async
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 460, in _run_async_impl
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 346, in run_async
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 365, in _run_one_step_async
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 455, in _preprocess_async
async for event in agen:
File "/Users/ashwjosh/miniconda3/lib/python3.12/site-packages/google/adk/flows/llm_flows/request_confirmation.py", line 84, in run_async
json.loads(function_response.response['response'])
File "/Users/ashwjosh/miniconda3/lib/python3.12/json/init.py", line 339, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
"""
I am following the example at
| # Set require_confirmation to True or a callable to require user |
Workflow -
I do get the confirmation screen in which I add the response like
{
"confirmed": true,
"payload": { "user_name": "ashwin" }
}
after which I get the error pasted above. I am trying ot make a trivia game with multiagent workflows. Any help would be appreciated.
I am using latest ADK
(base) ashwjosh@HK4T3VJL9J agents % pip freeze | grep google-adk
google-adk==1.19.0