adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Swagger documentation fails to load in google-adk v1.16 due to FastAPI version conflict

Open natansalvadorligabo opened this issue 1 year ago • 18 comments

Describe the bug When installing google-adk v1.16, the Swagger documentation page (accessed via adk web /docs) does not appear. Instead, the following error is displayed:

Failed to load API definition. Errors Hide Fetch error Internal Server Error /openapi.json

I resolved the issue by downgrading FastAPI to version 0.115.0.

To Reproduce

  1. Install google-adk v1.16
  2. Run adk web
  3. Open the Swagger documentation page
  4. Observe the error above

Expected behavior The Swagger documentation page should load normally after running adk web.

Screenshots http://127.0.0.1:8000/docs Image

Desktop:

  • OS: Windows 11
  • Python version (python -V): 3.13/3.14
  • ADK version (pip show google-adk): 1.16

Model Information:

  • Which model is being used: gemini-2.5-flash

Additional context Downgrading FastAPI to 0.115.0 restored the documentation route.

natansalvadorligabo avatar Oct 14 '25 22:10 natansalvadorligabo

@natansalvadorligabo I downgraded FastAPI to version 0.118.3 because the newer version introduces support for both Pydantic v1 and v2, which can sometimes cause issues when generating API documentation.

https://github.com/fastapi/fastapi/releases/tag/0.119.0

lifnaja avatar Oct 15 '25 03:10 lifnaja

@lifnaja Thanks for recommending the latest, most compatible version of FastAPI. I tested it and it also fixed the issue with the Swagger documentation.

natansalvadorligabo avatar Oct 15 '25 11:10 natansalvadorligabo

I have a same problem.

python : 3.13 adk : 1.16.0 and 1.17.0

I downgraded FAST API version to 0.118.3, but the problem persists.

  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/json_schema.py", line 1109, in default_schema
    json_schema = self.generate_inner(schema['schema'])
  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/json_schema.py", line 563, in generate_inner
    json_schema = current_handler(schema)
  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/_internal/_schema_generation_shared.py", line 37, in __call__
    return self.handler(core_schema)
           ~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/json_schema.py", line 495, in handler_func
    json_schema = generate_for_schema_type(schema_or_field)
  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/json_schema.py", line 1179, in nullable_schema
    inner_json_schema = self.generate_inner(schema['schema'])
  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/json_schema.py", line 563, in generate_inner
    json_schema = current_handler(schema)
  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/_internal/_schema_generation_shared.py", line 37, in __call__
    return self.handler(core_schema)
           ~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/json_schema.py", line 495, in handler_func
    json_schema = generate_for_schema_type(schema_or_field)
  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/json_schema.py", line 855, in is_instance_schema
    return self.handle_invalid_for_json_schema(schema, f'core_schema.IsInstanceSchema ({schema["cls"]})')
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/frodo/Documents/project/app/agents/data_science/.venv/lib/python3.13/site-packages/pydantic/json_schema.py", line 2318, in handle_invalid_for_json_schema
    raise PydanticInvalidForJsonSchema(f'Cannot generate a JsonSchema for {error_info}')
pydantic.errors.PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.IsInstanceSchema (<class 'httpx.Client'>)

For further information visit https://errors.pydantic.dev/2.11/u/invalid-for-json-schema

leebaro avatar Oct 23 '25 03:10 leebaro

These set of dependencies are compatible for the Swagger documentation page

dependencies = [
    "google-cloud-aiplatform[adk,agent-engines]>=1.93.0",
    "fastapi==0.118.3",
    "pydantic==2.10.6",
    "python-dotenv>=1.0.1",
    "google-genai>=1.16.1",
    "google-adk>=1.0.0",
]

ryanthomas8 avatar Oct 23 '25 18:10 ryanthomas8

There's a dependency issues with pydantic==2.10.6 with mcp 1.19.0 requires pydantic<3.0.0,>=2.11.0

AlfredoJF avatar Oct 24 '25 02:10 AlfredoJF

Same problem here. Even with fastapi 0.118.3 or 0.115.0 . The error is always the same pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'mcp.client.session.ClientSession'>. Set arbitrary_types_allowed=Truein the model_config to ignore this error or implementget_pydantic_core_schema on your type to fully support it.

I also tried @ryanthomas8 configuration, but i receive google-cloud-aiplatform[adk,agent-engines] (1.93.0) depends on pydantic (>=2.11.1,<3)

erickleal-azos avatar Oct 24 '25 12:10 erickleal-azos

no amount of tweaking the pydantic version or anything works for me either --

Here's what I found as a workaround for now:

tag:

"google-adk<1.16.0",                    # <1.16.0 for compat with /api/docs for now..
"fastapi<0.119",                         # for /api/docs compat

Then generate the openapi.json for later use, then upgrade adk to latest (yay!) and then I have a python server which handles all the redirects and loads our openapi.json as a statically generated schema

from google.adk.cli import fast_api
...
...
# server.py

app = fastapi.FastAPI(
    docs_url="/api/docs",  
    redoc_url="/api/redoc", 
    lifespan=lifespan,
)

py_static_files_dir = os.path.join(
    ".", "src", "nsha", "server", "static", "openapi.json"
)
with open(py_static_files_dir, "r") as openapi_file:
    api_spec = json.loads(openapi_file.read())
    app.openapi_schema = api_spec

# setup ADK
api = fast_api.get_fast_api_app(
    allow_origins=[
        "http://localhost",
        f"http://localhost:{VARS.PORT}",
        "*",
    ],
    agents_dir="./src/nsha/agents",
    session_service_uri=session_service_uri,
    session_db_kwargs=session_db_kwargs,
    web=False,
    trace_to_cloud=VARS.AF_TRACE_TO_CLOUD,
    reload_agents=reload,
    ....
)
app.mount("/api", api)

matthiasak avatar Oct 24 '25 19:10 matthiasak

Root Cause

The issue occurs due to incompatibility between ADK's Pydantic models and newer FastAPI/Pydantic versions:

  1. FastAPI 0.119.0+ and Pydantic 2.11+ are more aggressive when generating OpenAPI schemas, performing deep introspection of all Pydantic model fields
  2. ADK has Pydantic models (specifically BaseAgent and its subclasses like RemoteA2aAgent, plus tools like McpTool) that contain non-JSON-serializable types:
  3. When FastAPI generates the OpenAPI schema at startup, it traverses through Session → Event → EventActions → agent_state, eventually encountering these problematic types and failing with PydanticInvalidForJsonSchema

The addition of the agent_state field to EventActions in v1.16 increased exposure of agent/tool instances to schema generation.

Recommended Solution

Short-term workaround: Pin compatible versions as documented by users:

fastapi==0.118.3
pydantic>=2.11.1,<3  # or pydantic==2.10.6 if mcp compatibility allows

Proper fix: Update ADK code to mark non-serializable fields as private using Pydantic v2 patterns:

  1. Use __pydantic_private__ prefix for fields that shouldn't be serialized (requires Pydantic 2.x field declaration)
  2. Or use Field(exclude=True) for these fields
  3. Apply to RemoteA2aAgent._httpx_client, McpTool._mcp_session_manager, and similar fields

This prevents newer Pydantic/FastAPI from attempting to generate schemas for these internal implementation details.

Jacksunwei avatar Oct 26 '25 22:10 Jacksunwei

Got the same error. Need to improve it.

LiuYuWei avatar Nov 05 '25 05:11 LiuYuWei

Same error still on ADK 1.18.0. If I force pydantic 2.10.6 through my dependency graph it works, but I'd really rather not do that.

allenli873 avatar Nov 06 '25 17:11 allenli873

Upgrade to 1.18.0 and also still have the same problem.

TD-4242 avatar Nov 06 '25 21:11 TD-4242

TL;DR latest mcp cannot be compatible with the previous working versions, so we'll need to look into resolving it through code, now.

I think now after mcp 1.13.0, it bumps min pyndatic version over 2.11, which makes deps unresolvable anymore.

With these deps, the page can show:

pip install mcp==1.12.0
pip install pydantic==2.10.6
pip install fastapi==0.118.3

Jacksunwei avatar Nov 07 '25 21:11 Jacksunwei

My repo: https://github.com/prashantkul/a2a-space-agent

I see this issue in A2A agent creation as well. A2A agent card doesn't get generated. I've tested the workaround suggested in https://github.com/google/adk-python/issues/3173#issuecomment-3444660877 with the following specific package versions:

google-adk[a2a]==1.16.0
mcp==1.12.0
pydantic==2.10.6
fastapi==0.118.3

Test Results

Partial Success: PydanticSchemaGenerationError Resolved

The specific package combination successfully resolves the PydanticSchemaGenerationError. The server starts without crashing and OpenAPI documentation is generated successfully.

Critical Issue: A2A Endpoints Not Created

Despite the server starting successfully, the A2A endpoints are not being created. The agent card endpoint returns 404:

$ curl http://localhost:8009/.well-known/agent-card.json {"detail":"Not Found"}

Additional Testing

To isolate the issue, I tested with MCP tools completely removed from the agent:

  root_agent = LlmAgent(
      name="space_explorer",
      model="gemini-2.5-flash",
      instruction="...",
      tools=[
          # get_mcp_toolset(),  # Completely removed
          save_conversation
      ],
  )

Result: The agent card endpoint still returns 404, indicating this is not solely an MCP compatibility issue.

Root Cause Analysis

The issue appears to be twofold:

  1. MCP Compatibility: MCP's ClientSession class lacks Pydantic schema generation support (addressed by the version downgrade)
  2. A2A Flag Issue: The --a2a flag in ADK 1.16.0 does not properly create A2A endpoints, even without MCP tools

Verification Steps

  1. Start the A2A server: adk api_server --a2a --port 8009 space_agent_a2a

  2. Check OpenAPI (works): curl http://localhost:8009/openapi.json # Returns valid OpenAPI schema

  3. Check A2A agent card (fails): curl http://localhost:8009/.well-known/agent-card.json # Returns 404

  4. Search for A2A endpoints in OpenAPI: curl http://localhost:8009/openapi.json | grep -E '"/a2a|agent-card|"/.well-known"'

No A2A-specific endpoints found

prashantkul avatar Nov 07 '25 22:11 prashantkul

I tried with:

dependencies = [
    "fastapi==0.118.3",
    "google-adk>=1.18.0",
    "pydantic>=2.11.1,<3",
]

which failed

Then tried this:

uv add "mcp==1.12.0" "pydantic==2.10.6" "fastapi==0.118.3"

didn't work either:

➜  agent_repository git:(main) ✗ uv add "mcp==1.12.0" "pydantic==2.10.6" "fastapi==0.118.3"
  × No solution found when resolving dependencies for split (markers: python_full_version >= '3.14'):
  ╰─▶ Because google-cloud-aiplatform[agent-engines]>=1.125.0 depends on pydantic>=2.11.1 and pydantic>=2.11.1, we can conclude that
      google-cloud-aiplatform[agent-engines]>=1.125.0,<=1.126.0 depends on pydantic>=2.11.1.
      And because google-cloud-aiplatform[agent-engines]==1.127.0 depends on pydantic>=2.11.1, we can conclude that all of:
          google-cloud-aiplatform[agent-engines]>=1.125.0,<=1.126.0
          google-cloud-aiplatform[agent-engines]>=1.127.0
      depend on pydantic>=2.11.1.
      And because google-cloud-aiplatform[agent-engines]>=1.126.1 depends on pydantic>=2.11.1 and only the following versions of
      google-cloud-aiplatform[agent-engines] are available:
          google-cloud-aiplatform[agent-engines]<=1.125.0
          google-cloud-aiplatform[agent-engines]==1.126.0
          google-cloud-aiplatform[agent-engines]==1.126.1
          google-cloud-aiplatform[agent-engines]==1.127.0
      we can conclude that google-cloud-aiplatform[agent-engines]>=1.125.0 depends on pydantic>=2.11.1.
      And because google-adk==1.18.0 depends on google-cloud-aiplatform[agent-engines]>=1.125.0 and only google-adk<=1.18.0 is
      available, we can conclude that google-adk>=1.18.0 depends on pydantic>=2.11.1.
      And because your project depends on google-adk>=1.18.0 and pydantic==2.10.6, we can conclude that your project's requirements
      are unsatisfiable.

      hint: While the active Python version is 3.13, the resolution failed for other Python versions supported by your project.
      Consider limiting your project's supported Python versions using `requires-python`.
  help: If you want to add the package regardless of the failed resolution, provide the `--frozen` flag to skip locking and syncing.
➜  agent_repository git:(main) ✗ 

Anyone able to get around?

sedhha avatar Nov 14 '25 17:11 sedhha

@sedhha see https://docs.astral.sh/uv/reference/settings/#override-dependencies and use this to force pydantic==2.10.6 through your dependency graph

allenli873 avatar Nov 17 '25 16:11 allenli873

Hi @allenli873 thanks for the reply, I will look into this too!

GWeale avatar Nov 17 '25 19:11 GWeale

@sedhha see https://docs.astral.sh/uv/reference/settings/#override-dependencies and use this to force pydantic==2.10.6 through your dependency graph

Thanks! It solved for me.

dependencies = [
  "google-adk>=1.18.0",
  "fastapi==0.118.3",
  "pydantic==2.10.6",
]

adrianoresende avatar Nov 19 '25 00:11 adrianoresende

This isn't working.

      we can conclude that google-cloud-aiplatform[agent-engines]>=1.125.0 depends on
      pydantic>=2.11.1.
      And because google-adk==1.18.0 depends on google-cloud-aiplatform[agent-engines]>=1.125.0
      and only google-adk<=1.18.0 is available, we can conclude that google-adk>=1.18.0 depends
      on pydantic>=2.11.1.
      And because your project depends on google-adk>=1.18.0 and pydantic==2.10.6, we can
      conclude that your project's requirements are unsatisfiable.

You have to go all the way back to google-cloud-aiplatform[agent-engines]==1.89.0 to lower the pydantic requirement to <=2.11.0.

EDIT: I missed this part:

[tool.uv]
override-dependencies = ["pydantic==2.10.6"]

Hopefully trying to use VertexAI doesn't blow it up.

dcode avatar Nov 19 '25 19:11 dcode