diff --git a/python/samples/03-workflows/human-in-the-loop/guessing_game_with_human_input.py b/python/samples/03-workflows/human-in-the-loop/guessing_game_with_human_input.py index 06e9a738f5..f764de6cb7 100644 --- a/python/samples/03-workflows/human-in-the-loop/guessing_game_with_human_input.py +++ b/python/samples/03-workflows/human-in-the-loop/guessing_game_with_human_input.py @@ -102,12 +102,19 @@ async def on_agent_response( """Handle the agent's guess and request human guidance. Steps: - 1) Parse the agent's JSON into GuessOutput for robustness. + 1) Use .value to access the parsed structured output directly. 2) Request info with a HumanFeedbackRequest as the payload. """ - # Parse structured model output - text = result.agent_response.text - last_guess = GuessOutput.model_validate_json(text).guess + # Access the parsed structured model output via .value. + # Since the agent is configured with response_format=GuessOutput, + # .value returns the parsed GuessOutput instance directly. + agent_value = result.agent_response.value + if agent_value is None: + raise RuntimeError( + "AgentResponse.value is None. Ensure that the agent is invoked with " + "options={'response_format': GuessOutput} so structured output is available." + ) + last_guess = agent_value.guess # Craft a precise human prompt that defines higher and lower relative to the agent's guess. prompt = (