mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Make response_format validation errors visible to users (#3274)
* Make response_format validation errors visible to users * Small fix * Addressed comments
This commit is contained in:
committed by
GitHub
Unverified
parent
3c1be2a713
commit
83e8965c8e
@@ -20,7 +20,11 @@ async def main():
|
||||
agent = AgentFactory(client_kwargs={"credential": AzureCliCredential()}).create_agent_from_yaml(yaml_str)
|
||||
# use the agent
|
||||
response = await agent.run("Why is the sky blue, answer in Dutch?")
|
||||
print("Agent response:", response.value.model_dump_json(indent=2))
|
||||
# Use try_parse_value() for safe parsing - returns None if no response_format or parsing fails
|
||||
if parsed := response.try_parse_value():
|
||||
print("Agent response:", parsed.model_dump_json(indent=2))
|
||||
else:
|
||||
print("Agent response:", response.text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -19,7 +19,11 @@ async def main():
|
||||
agent = AgentFactory().create_agent_from_yaml(yaml_str)
|
||||
# use the agent
|
||||
response = await agent.run("Why is the sky blue, answer in Dutch?")
|
||||
print("Agent response:", response.value)
|
||||
# Use try_parse_value() for safe parsing - returns None if no response_format or parsing fails
|
||||
if parsed := response.try_parse_value():
|
||||
print("Agent response:", parsed)
|
||||
else:
|
||||
print("Agent response:", response.text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user