mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-14 01:41:25 -06:00
feat:support Langchain tools that has run_manager in _run args and don't have args_schema populated
PiperOrigin-RevId: 765405793
This commit is contained in:
parent
e06e6753ad
commit
3616bb5fc4
@ -0,0 +1,8 @@
|
||||
# Langchain Youtube Search Agent
|
||||
|
||||
This agent utilize the Lanchain YoutubeSearchTool to search youtubes.
|
||||
You need to install below dependencies:
|
||||
|
||||
```python
|
||||
uv pip install youtube_search
|
||||
```
|
@ -0,0 +1,15 @@
|
||||
# Copyright 2025 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from . import agent
|
36
contributing/samples/langchain_youtube_search_agent/agent.py
Normal file
36
contributing/samples/langchain_youtube_search_agent/agent.py
Normal file
@ -0,0 +1,36 @@
|
||||
# Copyright 2025 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from google.adk.agents import LlmAgent
|
||||
from google.adk.tools.langchain_tool import LangchainTool
|
||||
from langchain_community.tools import YouTubeSearchTool
|
||||
|
||||
# Instantiate the tool
|
||||
langchain_yt_tool = YouTubeSearchTool()
|
||||
|
||||
# Wrap the tool in the LangchainTool class from ADK
|
||||
adk_yt_tool = LangchainTool(
|
||||
tool=langchain_yt_tool,
|
||||
)
|
||||
|
||||
root_agent = LlmAgent(
|
||||
name="youtube_search_agent",
|
||||
model="gemini-2.0-flash", # Replace with the actual model name
|
||||
instruction="""
|
||||
Ask customer to provide singer name, and the number of videos to search.
|
||||
""",
|
||||
description="Help customer to search for a video on Youtube.",
|
||||
tools=[adk_yt_tool],
|
||||
output_key="youtube_search_output",
|
||||
)
|
@ -70,7 +70,8 @@ class LangchainTool(FunctionTool):
|
||||
else:
|
||||
func = tool._run if hasattr(tool, '_run') else tool.run
|
||||
super().__init__(func)
|
||||
|
||||
# run_manager is a special parameter for langchain tool
|
||||
self._ignore_params.append('run_manager')
|
||||
self._langchain_tool = tool
|
||||
|
||||
# Set name: priority is 1) explicitly provided name, 2) tool's name, 3) default
|
||||
@ -117,20 +118,21 @@ class LangchainTool(FunctionTool):
|
||||
):
|
||||
tool_wrapper.args_schema = self._langchain_tool.args_schema
|
||||
|
||||
return _automatic_function_calling_util.build_function_declaration_for_langchain(
|
||||
False,
|
||||
self.name,
|
||||
self.description,
|
||||
tool_wrapper.func,
|
||||
getattr(tool_wrapper, 'args', None),
|
||||
)
|
||||
return _automatic_function_calling_util.build_function_declaration_for_langchain(
|
||||
False,
|
||||
self.name,
|
||||
self.description,
|
||||
tool_wrapper.func,
|
||||
tool_wrapper.args,
|
||||
)
|
||||
|
||||
# Need to provide a way to override the function names and descriptions
|
||||
# as the original function names are mostly ".run" and the descriptions
|
||||
# may not meet users' needs
|
||||
return _automatic_function_calling_util.build_function_declaration(
|
||||
func=self._langchain_tool.run,
|
||||
)
|
||||
function_decl = super()._get_declaration()
|
||||
function_decl.name = self.name
|
||||
function_decl.description = self.description
|
||||
return function_decl
|
||||
|
||||
except Exception as e:
|
||||
raise ValueError(
|
||||
|
Loading…
Reference in New Issue
Block a user