-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Summary
The HITL documentation page and the guessing_game_with_human_input.py sample use model_validate_json() to parse structured agent output inside workflow executors:
text = result.agent_response.text
last_guess = GuessOutput.model_validate_json(text).guessSince the agent is configured with response_format=GuessOutput, the AgentResponse object already has a .value property that returns the parsed Pydantic model directly:
last_guess = result.agent_response.value.guessUsing .value is more idiomatic and avoids redundant parsing. It also better communicates that structured outputs are a first-class feature — the framework already handles the JSON parsing when response_format is set.
Affected files
- Docs: https://learn.microsoft.com/en-us/agent-framework/workflows/human-in-the-loop?pivots=programming-language-python
- Sample:
python/samples/03-workflows/human-in-the-loop/guessing_game_with_human_input.py(link)
Context
It's possible model_validate_json was used because .value wasn't available on AgentResponse when the sample was originally written, or because .value support inside AgentExecutorResponse.agent_response was added later. Either way, .value is available today and would be the cleaner approach.
This also applies to other workflow samples that use model_validate_json with structured response_format agents (e.g. agents_with_approval_requests.py, checkpoint samples, etc.).
Metadata
Metadata
Assignees
Labels
Type
Projects
Status