-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
need attention[Status] This issue is important but the maintainers haven't started working on it[Status] This issue is important but the maintainers haven't started working on ittools[Component] This issue is related to tools[Component] This issue is related to tools
Milestone
Description
Describe the bug
When running an agent using google-adk
that utilizes tools wrapped by LangchainTool
(specifically from GmailToolkit
in this case), a pydantic_core._pydantic_core.ValidationError
occurs related to properties.resource.$ref
. This seems to happen during the function declaration building process for the LLM.
To Reproduce
Steps to reproduce the behavior:
- Set up a project using
google-adk
. - Implement an agent that uses
langchain_community.agent_toolkits.GmailToolkit
wrapped withgoogle.adk.tools.langchain_tool.LangchainTool
. See the relevant code snippet below. - Run the agent using the ADK CLI or relevant execution method.
- Observe the error during the agent's execution flow, specifically when the agent attempts to process the wrapped Langchain tools.
Relevant Code Snippet (gmail_agent/agent.py
)
# ... (imports and other setup)
from google.adk import Agent
from google.adk.tools.langchain_tool import LangchainTool
from langchain_community.agent_toolkits import GmailToolkit
from langchain_community.tools.gmail.utils import (
build_resource_service,
get_gmail_credentials,
)
# ...
# Gmail setup
# Assuming credentials and api_resource are correctly set up
# credentials = get_gmail_credentials(...)
# api_resource = build_resource_service(credentials=credentials)
toolkit = GmailToolkit(api_resource=api_resource)
# Wrap with LangchainTool
gmail_tools = toolkit.get_tools()
adk_gmail_tools = [LangchainTool(tool=tool) for tool in gmail_tools]
try:
# Define Agent with the wrapped tool
gmail_root_agent = Agent(
model="gemini-1.5-pro-latest", # Or your specific model
# name=...,
# description=...,
# instruction=...,
tools=adk_gmail_tools # Error seems to occur when processing these tools
)
# ... (Runner setup and execution)
except Exception as e:
print(f"Error during agent initialization or execution: {e}")
raise
Expected behavior
The agent should initialize and run without encountering the Pydantic validation error when processing LangchainTool
-wrapped tools.
Error Message/Traceback
2025-04-21 12:24:29,847 - ERROR - fast_api.py:637 - Error in event_generator: 1 validation error for Schema
properties.resource.$ref
Extra inputs are not permitted [type=extra_forbidden, input_value='#/$defs/Resource', input_type=str]
For further information visit https://errors.pydantic.dev/2.10/v/extra_forbidden
Traceback (most recent call last):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/cli/fast_api.py", line 626, in event_generator
async for event in runner.run_async(
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/runners.py", line 197, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 141, in run_async
async for event in self._run_async_impl(ctx):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 232, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 231, in run_async
async for event in self._run_one_step_async(invocation_context):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 261, in _run_one_step_async
async for event in self._postprocess_async(
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 329, in _postprocess_async
async for event in self._postprocess_handle_function_calls_async(
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 419, in _postprocess_handle_function_calls_async
async for event in agent_to_run.run_async(invocation_context):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 141, in run_async
async for event in self._run_async_impl(ctx):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 232, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 231, in run_async
async for event in self._run_one_step_async(invocation_context):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 245, in _run_one_step_async
async for event in self._preprocess_async(invocation_context, llm_request):
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 283, in _preprocess_async
await tool.process_llm_request(
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/tools/base_tool.py", line 96, in process_llm_request
if (function_declaration := self._get_declaration()) is None:
^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/tools/langchain_tool.py", line 69, in _get_declaration
function_declaration = _automatic_function_calling_util.build_function_declaration_for_langchain(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/tools/_automatic_function_calling_util.py", line 250, in build_function_declaration_for_langchain
return build_function_declaration_util(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/user/home/.local/lib/python3.12/site-packages/google/adk/tools/_automatic_function_calling_util.py", line 273, in build_function_declaration_util
parameters=types.Schema(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/pydantic/main.py", line 214, in __init__
validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Schema
properties.resource.$ref
Extra inputs are not permitted [type=extra_forbidden, input_value='#/$defs/Resource', input_type=str]
For further information visit https://errors.pydantic.dev/2.10/v/extra_forbidden
Environment (please complete the following information):
- OS: Linux 6.6
- Python version: 3.12
google-adk
version: 0.2.0langchain-community
version: 0.3.21pydantic
version: 2.11.3- Other relevant libraries and versions from
requirements.txt
:google-adk>=0.2.0 litellm>=1.67.0 nest_asyncio>=1.6.0 langchain_community>=0.3.21 python-dotenv>=1.0.0 google-generativeai>=0.4.0 google-auth-oauthlib>=1.2.1
Metadata
Metadata
Assignees
Labels
need attention[Status] This issue is important but the maintainers haven't started working on it[Status] This issue is important but the maintainers haven't started working on ittools[Component] This issue is related to tools[Component] This issue is related to tools