From c850da3a07ec1441037ced1b654d8aacacd277ab Mon Sep 17 00:00:00 2001 From: Xuan Yang Date: Tue, 21 Oct 2025 14:29:58 -0700 Subject: [PATCH] fix: Fix the broken langchain importing caused their 1.0.0 release PiperOrigin-RevId: 822279014 --- .../langchain_structured_tool_agent/agent.py | 4 +++- pyproject.toml | 4 ++-- src/google/adk/tools/langchain_tool.py | 2 +- tests/unittests/tools/test_langchain_tool.py | 13 ++----------- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/contributing/samples/langchain_structured_tool_agent/agent.py b/contributing/samples/langchain_structured_tool_agent/agent.py index 5c4c5b9a..e83bc40b 100644 --- a/contributing/samples/langchain_structured_tool_agent/agent.py +++ b/contributing/samples/langchain_structured_tool_agent/agent.py @@ -17,17 +17,19 @@ This agent aims to test the Langchain tool with Langchain's StructuredTool """ from google.adk.agents.llm_agent import Agent from google.adk.tools.langchain_tool import LangchainTool -from langchain.tools import tool +from langchain_core.tools import tool from langchain_core.tools.structured import StructuredTool from pydantic import BaseModel async def add(x, y) -> int: + """Adds two numbers.""" return x + y @tool def minus(x, y) -> int: + """Subtracts two numbers.""" return x - y diff --git a/pyproject.toml b/pyproject.toml index bcb7dd10..6782f417 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -114,7 +114,7 @@ test = [ "anthropic>=0.43.0", # For anthropic model tests "kubernetes>=29.0.0", # For GkeCodeExecutor "langchain-community>=0.3.17", - "langgraph>=0.2.60, <= 0.4.10", # For LangGraphAgent + "langgraph>=0.2.60, <0.4.8", # For LangGraphAgent "litellm>=1.75.5, <2.0.0", # For LiteLLM tests "llama-index-readers-file>=0.4.0", # For retrieval tests "openai>=1.100.2", # For LiteLLM @@ -144,7 +144,7 @@ extensions = [ "crewai[tools];python_version>='3.10'", # For CrewaiTool "docker>=7.0.0", # For ContainerCodeExecutor "kubernetes>=29.0.0", # For GkeCodeExecutor - "langgraph>=0.2.60", # For LangGraphAgent + "langgraph>=0.2.60, <0.4.8", # For LangGraphAgent "litellm>=1.75.5", # For LiteLlm class. Currently has OpenAI limitations. TODO: once LiteLlm fix it "llama-index-readers-file>=0.4.0", # For retrieval using LlamaIndex. "llama-index-embeddings-google-genai>=0.3.0",# For files retrieval using LlamaIndex. diff --git a/src/google/adk/tools/langchain_tool.py b/src/google/adk/tools/langchain_tool.py index 44f884ff..33f52b95 100644 --- a/src/google/adk/tools/langchain_tool.py +++ b/src/google/adk/tools/langchain_tool.py @@ -18,8 +18,8 @@ from typing import Optional from typing import Union from google.genai import types -from langchain.agents import Tool from langchain_core.tools import BaseTool as LangchainBaseTool +from langchain_core.tools import Tool from langchain_core.tools.structured import StructuredTool from typing_extensions import override diff --git a/tests/unittests/tools/test_langchain_tool.py b/tests/unittests/tools/test_langchain_tool.py index b2c7b681..fdcadff8 100644 --- a/tests/unittests/tools/test_langchain_tool.py +++ b/tests/unittests/tools/test_langchain_tool.py @@ -12,22 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest - -# TODO: Re-enable this test after verifying LangchainTool and -# LangGraphAgent against langchain's 1.0.0 release. -pytest.skip( - allow_module_level=True, - reason="Langchain just made 1.0.0 release that breaks existing import.", -) - - from unittest.mock import MagicMock from google.adk.tools.langchain_tool import LangchainTool -from langchain.tools import tool +from langchain_core.tools import tool from langchain_core.tools.structured import StructuredTool from pydantic import BaseModel +import pytest @tool