mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: fix(python): Use AgentResponse.value instead of model_validate_json in HITL sample (#4405)
* 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 * 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.
This commit is contained in:
committed by
GitHub
Unverified
parent
d7abfcd444
commit
ef8e18fb85
@@ -102,12 +102,19 @@ class TurnManager(Executor):
|
||||
"""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 = (
|
||||
|
||||
Reference in New Issue
Block a user