Skip to content

FunctionDeclaration doesn't support dicts #5364

@pp-eyushin

Description

@pp-eyushin

Describe the Bug:
Python methods with dicts in signature raises issues when FunctionTool tries to come up with schema.
Complex types as list/dict are handled in fallback branch relying on pydantic.TypeAdapter.json_schema(), that emits additionalProperties for typed dicts.

Follow-up for #4798

Steps to Reproduce:
Please provide a numbered list of steps to reproduce the behavior:

import asyncio
import os
from datetime import datetime, timezone

from google.adk import Agent, Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types as genai_types

APP_NAME = "repro"
USER_ID = "u1"
MODEL = "gemini-2.5-flash"


async def get_utc_timestamp(
    options: dict[str, str] | None = None,
    # options: list[str] | None = None,
) -> str:
    _ = options
    return datetime.now(timezone.utc).isoformat()


async def main() -> None:
    agent = Agent(
        name="time_agent",
        model=MODEL,
        instruction="You are a helpful assistant. Use tools when asked for the time.",
        tools=[get_utc_timestamp],
    )

    session_service = InMemorySessionService()
    session = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID)
    runner = Runner(app_name=APP_NAME, agent=agent, session_service=session_service)

    user_msg = genai_types.Content(
        role="user",
        parts=[genai_types.Part(text="What's the current UTC timestamp?")],
    )

    async for event in runner.run_async(
        user_id=USER_ID, session_id=session.id, new_message=user_msg
    ):
        if event.content and event.content.parts and event.is_final_response():
            for part in event.content.parts:
                print(part.text)


if __name__ == "__main__":
    os.environ.setdefault("GOOGLE_API_KEY", "<your key here>")
    asyncio.run(main())

Expected Behavior:
dict should be recognized in Schema.

Observed Behavior:

google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Invalid JSON payload received. Unknown name "additional_properties" at \'tools[0].function_declarations[0].parameters.properties[0].value.any_of[0]\': Cannot find field.', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'tools[0].function_declarations[0].parameters.properties[0].value.any_of[0]', 'description': 'Invalid JSON payload received. Unknown name "additional_properties" at \'tools[0].function_declarations[0].parameters.properties[0].value.any_of[0]\': Cannot find field.'}]}]}}

Environment Details:

  • ADK Library Version (pip show google-adk): 1.31.0
  • Desktop OS: macOS
  • Python Version (python -V): Python 3.11.14

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: gemini-2.5-flash

How often has this issue occurred?:

  • Always (100%)

Metadata

Metadata

Assignees

Labels

tools[Component] This issue is related to tools

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions