mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
93cbf6b3f0
* Parse structuredContent from MCP CallToolResult (#3313) The _parse_tool_result_from_mcp method only iterated over the content field from CallToolResult, ignoring the structuredContent field entirely. MCP servers that return JSON data via structuredContent (e.g., Power BI MCP) appeared to return None. Add handling for structuredContent: when present, serialize it as JSON text and append it to the result list. This preserves the data for the LLM while maintaining backward compatibility with existing behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Python: Parse MCP CallToolResult.structuredContent field to prevent tool results returning None Fixes #3313 * Address review feedback: add default=str to json.dumps and remove .checkpoints/ - Add default=str to json.dumps for structuredContent serialization so non-JSON-serializable values (e.g. bytes) degrade gracefully instead of raising TypeError - Remove all .checkpoints/ runtime artifacts from the repository - Add **/.checkpoints/ to .gitignore to prevent future accidental commits - Add test for non-serializable structuredContent values Fixes #3313 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address review feedback for #3313: Python: MCP CallToolResult.structuredContent field is not parsed, causing tool results to return None --------- Co-authored-by: Copilot <copilot@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
"""Pydantic models for structured planning output.
|
|
|
|
These models define the JSON schema that the agent produces when in planning
|
|
mode via `response_format`. The schema enables consistent rendering of
|
|
clarification questions and approval requests in the console UI.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from enum import Enum
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class PlanningResponseType(str, Enum):
|
|
"""Type of planning response from the agent."""
|
|
|
|
CLARIFICATION = "clarification"
|
|
"""The agent needs clarification and presents options for the user to choose from."""
|
|
|
|
APPROVAL = "approval"
|
|
"""The agent is seeking approval to proceed with execution."""
|
|
|
|
|
|
class PlanningQuestion(BaseModel):
|
|
"""A single question or item within a PlanningResponse.
|
|
|
|
For clarification: contains the question text and optional choices.
|
|
For approval: contains the plan summary for the user to approve.
|
|
"""
|
|
|
|
message: str = Field(
|
|
description=(
|
|
"For clarifications, this has the question that needs to be clarified "
|
|
"with the user. For approvals, this would contain a summary of the "
|
|
"execution plan that the user needs to approve."
|
|
),
|
|
)
|
|
choices: list[str] | None = Field(
|
|
default=None,
|
|
description=(
|
|
"For clarifications, this has a list of options that the user can choose from. null for approvals."
|
|
),
|
|
)
|
|
|
|
|
|
class PlanningResponse(BaseModel):
|
|
"""Structured response from the agent while in planning mode.
|
|
|
|
Used with structured output (`response_format`) to enable consistent
|
|
rendering of clarification questions and approval requests.
|
|
"""
|
|
|
|
type: PlanningResponseType = Field(
|
|
description=(
|
|
"Use 'clarification' when you need clarification around the user "
|
|
"request and you want to present the user with options to choose from. "
|
|
"Use 'approval' when you are ready to start execution, but need "
|
|
"approval to start executing."
|
|
),
|
|
)
|
|
questions: list[PlanningQuestion] = Field(
|
|
description=(
|
|
"For clarifications, this has one or more questions to ask the user "
|
|
"(each with choices). For approvals, this has exactly one item "
|
|
"containing the plan summary for the user to approve."
|
|
),
|
|
)
|