From 1b7875342178721f85559e1133093b7dd04a47d6 Mon Sep 17 00:00:00 2001 From: "L. Elaine Dazzio" Date: Mon, 2 Mar 2026 17:44:51 -0500 Subject: [PATCH 1/2] fix(python): use AgentResponse.value instead of model_validate_json in HITL sample Since the agent is configured with response_format=GuessOutput, the AgentResponse already provides .value with the parsed Pydantic model. Using .value is more idiomatic and avoids redundant JSON parsing. Fixes #4396 --- .../human-in-the-loop/guessing_game_with_human_input.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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..02f45e8bab 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,13 @@ 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. + last_guess = result.agent_response.value.guess # Craft a precise human prompt that defines higher and lower relative to the agent's guess. prompt = ( From a76092dea64822a123884fef89d5e8e9b3be3187 Mon Sep 17 00:00:00 2001 From: "L. Elaine Dazzio" Date: Mon, 2 Mar 2026 17:52:00 -0500 Subject: [PATCH 2/2] fix: add safety guard for AgentResponse.value being None Address Copilot review feedback: .value is optional and may be None if response_format isn't propagated through the streaming path. Add an explicit None check with a clear error message. --- .../human-in-the-loop/guessing_game_with_human_input.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 02f45e8bab..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 @@ -108,7 +108,13 @@ async def on_agent_response( # Access the parsed structured model output via .value. # Since the agent is configured with response_format=GuessOutput, # .value returns the parsed GuessOutput instance directly. - last_guess = result.agent_response.value.guess + 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 = (