mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
fix: Fix Pydantic Schema Generation Error for ClientSession
Problem: The test test_openapi_json_schema_accessible was failing because Pydantic couldn't generate a JSON schema for mcp.client.session.ClientSession, which is part of genai_types.ToolListUnion. Root Cause: The AgentDetails model in src/google/adk/evaluation/app_details.py:37 had tool_declarations: genai_types.ToolListUnion, and ToolListUnion includes mcp.client.session.ClientSession which doesn't have Pydantic core schema support. This model is used in the FastAPI app through EvalCase → Invocation → AppDetails → AgentDetails, causing OpenAPI schema generation to fail. Solution: Changed the type annotation from genai_types.ToolListUnion to list[Any] in two places: AgentDetails.tool_declarations _ToolDeclarations.tool_declarations This allows Pydantic to generate the OpenAPI schema while maintaining runtime compatibility (the field still accepts the same values). Co-authored-by: Xiang (Sean) Zhou <seanzhougoogle@google.com> PiperOrigin-RevId: 863765002
This commit is contained in:
committed by
Copybara-Service
parent
798f65df86
commit
131fbd3948
@@ -14,6 +14,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from google.genai import types as genai_types
|
||||
from pydantic import Field
|
||||
|
||||
@@ -32,8 +34,12 @@ class AgentDetails(EvalBaseModel):
|
||||
instructions: str = Field(default="")
|
||||
"""The instructions set on the Agent."""
|
||||
|
||||
tool_declarations: genai_types.ToolListUnion = Field(default_factory=list)
|
||||
"""A list of tools available to the Agent."""
|
||||
tool_declarations: list[Any] = Field(default_factory=list)
|
||||
"""A list of tools available to the Agent.
|
||||
|
||||
At runtime, this contains elements of type genai_types.ToolListUnion.
|
||||
We use list[Any] for Pydantic schema generation compatibility.
|
||||
"""
|
||||
|
||||
|
||||
class AppDetails(EvalBaseModel):
|
||||
|
||||
@@ -16,6 +16,7 @@ from __future__ import annotations
|
||||
|
||||
import enum
|
||||
import statistics
|
||||
from typing import Any
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
@@ -78,7 +79,7 @@ def get_average_rubric_score(
|
||||
class _ToolDeclarations(EvalBaseModel):
|
||||
"""Internal data model used for serializing Tool declarations."""
|
||||
|
||||
tool_declarations: dict[str, genai_types.ToolListUnion]
|
||||
tool_declarations: dict[str, list[Any]]
|
||||
|
||||
|
||||
def get_tool_declarations_as_json_str(
|
||||
|
||||
Reference in New Issue
Block a user