Skip to content

Agent() doesn't accept tools in list[FunctionTool] #1803

Open
@jokester

Description

@jokester

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Describe the bug

from google.adk import Agent
from google.adk.tools import FunctionTool

tools: list[FunctionTool] = ...
Agent(..., tools=tools)

Will fail to type check (like in Pylance) like:

Argument of type "list[FunctionTool]" cannot be assigned to parameter "tools" of type "list[ToolUnion]" in function "__init__"
  "list[FunctionTool]" is not assignable to "list[ToolUnion]"
    Type parameter "_T@list" is invariant, but "FunctionTool" is not the same as "ToolUnion"
    Consider switching from "list" to "Sequence" which is covariantPylance[reportArgumentType](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportArgumentType.md)

Because ADK had class Agent like:

class Agent(BaseModel)
  ...
  tools: list[ToolUnion] = Field(default_factory=list)

and list[T] seems to be invariant on T in Python.

Expected behavior

Passing a list[FunctionTool] should type check.

Screenshots

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bot_triagedcoreIssues related to the core interface and implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions