Content-Length: 245542 | pFad | https://github.com/googleapis/python-aiplatform/issues/5319

C7 Error in importing langchain_google_vertexai on Agent engine · Issue #5319 · googleapis/python-aiplatform · GitHub
Skip to content

Error in importing langchain_google_vertexai on Agent engine #5319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kiljag opened this issue May 14, 2025 · 1 comment
Open

Error in importing langchain_google_vertexai on Agent engine #5319

kiljag opened this issue May 14, 2025 · 1 comment
Assignees
Labels
api: vertex-ai Issues related to the googleapis/python-aiplatform API.

Comments

@kiljag
Copy link

kiljag commented May 14, 2025

Environment details

  • OS type and version: Apple M1 Pro
  • Python version: Python 3.12.9
  • pip version: pip 25.1
  • google-cloud-aiplatform version: 1.92.0

requirements.txt

google-cloud-aiplatform[agent_engines,langchain,langgraph]==1.92.0
langchain-google-vertexai==2.0.23
langgraph>=0.2.6
langchain-openai>=0.1.22
langchain>=0.2.14
langchain-fireworks>=0.1.7
python-dotenv>=1.0.1
langchain-community>=0.2.17
tavily-python>=0.4.0

Stack trace

Hi,
This is the stack trace I am seeing while deploying a sample langgraph agent on Agent Engine.

These are the local deployment logs.

Extra packages: ['agent_engine_main.py', 'deployment_response.json', 'LICENSE', 'requirements.txt', 'agent.json', '__pycache__', 'requirements.txt.old', 'tracing.json', 'react_agent', 'main.py']
Reading requirements from requirements='./requirements.txt'
Read the following lines: ['google-cloud-aiplatform[agent_engines,langchain,langgraph]==1.92.0', 'langchain-google-vertexai==2.0.23', 'langgraph>=0.2.6', 'langchain-openai>=0.1.22', 'langchain>=0.2.14', 'langchain-fireworks>=0.1.7', 'python-dotenv>=1.0.1', 'langchain-community>=0.2.17', 'tavily-python>=0.4.0']
Identified the following requirements: {'cloudpickle': '3.1.1', 'google-cloud-aiplatform': '1.92.0', 'pydantic': '2.11.4'}
The following requirements are missing: {'cloudpickle', 'pydantic'}
The following requirements are appended: {'pydantic==2.11.4', 'cloudpickle==3.1.1'}
The final list of requirements: ['google-cloud-aiplatform[agent_engines,langchain,langgraph]==1.92.0', 'langchain-google-vertexai==2.0.23', 'langgraph>=0.2.6', 'langchain-openai>=0.1.22', 'langchain>=0.2.14', 'langchain-fireworks>=0.1.7', 'python-dotenv>=1.0.1', 'langchain-community>=0.2.17', 'tavily-python>=0.4.0', 'pydantic==2.11.4', 'cloudpickle==3.1.1']

I can see this requirement langchain-google-vertexai==2.0.23 getting added.
But on the Agent Engine logs, I am seeing this


INFO 2025-05-14T05:30:48.995667537Z Step #2: Removing intermediate container 7e4894812ebf
INFO 2025-05-14T05:30:48.995679940Z Step #2: ---> 031ff904a868
INFO 2025-05-14T05:30:48.995681364Z Step #2: Step 6/9 : COPY /$CODE_DIR/* ./user_code/
INFO 2025-05-14T05:30:49.301859384Z Step #2: ---> f5fa9502bd98
INFO 2025-05-14T05:30:49.301870669Z Step #2: Step 7/9 : RUN if [ -f "./user_code/dependencies.tar.gz" ]; then tar -xvf user_code/dependencies.tar.gz; else echo "dependencies.tar.gz not found"; fi
INFO 2025-05-14T05:30:49.329830261Z Step #2: ---> Running in 2afa59f6d342
DEFAULT 2025-05-14T05:30:49.722454Z [10] INFO: Finished server process [10]
DEFAULT 2025-05-14T05:30:49.722470Z [3] INFO: Application shutdown complete.
DEFAULT 2025-05-14T05:30:49.722477Z [9] INFO: Application shutdown complete.
DEFAULT 2025-05-14T05:30:50.303798Z [7] ERROR: Error when setting up the application. The service will be terminated. Please fix the error in `set_up()` and re-deploy the application.
DEFAULT 2025-05-14T05:30:50.303819Z Error: No module named 'langchain_google_vertexai'
ERROR 2025-05-14T05:30:50.303837Z Traceback (most recent call last): File "/code/app/api/factory/python_file_api_builder.py", line 793, in create_apis obj.set_up() File "/usr/local/lib/python3.12/site-packages/vertexai/agent_engines/templates/langgraph.py", line 499, in set_up self._tmpl_attrs["model"] = model_builder(
DEFAULT 2025-05-14T05:30:50.303841Z ^^^^^^^^^^^^^^
DEFAULT 2025-05-14T05:30:50.303847Z File "/usr/local/lib/python3.12/site-packages/vertexai/agent_engines/templates/langgraph.py", line 100, in _default_model_builder
DEFAULT 2025-05-14T05:30:50.303851Z from langchain_google_vertexai import ChatVertexAI
DEFAULT 2025-05-14T05:30:50.303867Z ModuleNotFoundError: No module named 'langchain_google_vertexai'

Is there any way to fix this?
Thank you.

@product-auto-label product-auto-label bot added the api: vertex-ai Issues related to the googleapis/python-aiplatform API. label May 14, 2025
@kiljag
Copy link
Author

kiljag commented May 14, 2025

Steps to reproduce the issue.

agent.py

from langchain_openai import ChatOpenAI
from langgraph.graph import StateGraph, add_messages, START, END
from typing import Annotated
from typing_extensions import TypedDict
from langgraph.graph.message import add_messages

import os
if os.environ.get("OPENAI_API_KEY", "") == "":
    os.environ["OPENAI_API_KEY"] = "sk-proj-1234"


# Define the state schema
class AgentState(TypedDict):
    messages: Annotated[list, add_messages]
        

# Initialize the LLM
llm = ChatOpenAI(model_name="gpt-4o-mini")


# Define the node function
def call_model(state: AgentState) -> AgentState:
    return {"messages": [llm.invoke(state["messages"])]}



# Build the graph
builder = StateGraph(AgentState)
builder.add_node("call_model", call_model)
builder.add_edge(START, "call_model")
builder.add_edge("call_model", END)

# Compile the graph
graph = builder.compile()

# Example usage
if __name__ == "__main__":
    initial_state = {
        "messages": [("user", "What is distance between Earth and Moon?")]
    }
    final_state = graph.invoke(initial_state)
    print(final_state["messages"][-1].content)

deploy.py

import os
import glob
import vertexai
from vertexai import agent_engines

from agent import graph


def runnable_builder(*, model, **kwargs):
    return graph


def get_langgraph_agent():
    local_agent = agent_engines.LanggraphAgent(
        model="google/gemini-2.0-flash",
        runnable_builder=runnable_builder
    )
    return local_agent


def get_extra_packages():
    extra_packages = glob.glob("*")
    print(f"Extra packages: {extra_packages}")
    return extra_packages


def initialize_vertxai():
    vertexai.init(
        project="devops-poc-447209",
        location="us-central1",
        staging_bucket="gs://raga-agent-engine-bucket",
    )


def deploy_agent():
    local_agent = get_langgraph_agent()
    extra_packages = get_extra_packages()
    initialize_vertxai()
    remote_agent = agent_engines.create(
        local_agent,
        requirements="./requirements.txt",
        extra_packages=extra_packages,
        env_vars={
            "OPENAI_API_KEY": "sk-proj-1234" # dummy value
        }
    )
    print(remote_agent.resource_name)


if __name__ == "__main__":
    deploy_agent()

Requirements.txt

google-cloud-aiplatform[agent_engines,langchain,langgraph]==1.92.0
langchain-google-vertexai==2.0.23
langgraph>=0.2.6
langchain-openai>=0.1.22
langchain>=0.2.14
langchain-fireworks>=0.1.7
python-dotenv>=1.0.1
langchain-community>=0.2.17
tavily-python>=0.4.0
conda create -n langgraph-agent python=3.12
pip install -r requirements.txt
python deploy.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: vertex-ai Issues related to the googleapis/python-aiplatform API.
Projects
None yet
Development

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/googleapis/python-aiplatform/issues/5319

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy