AttributeError: 'VertexAI' object has no attribute 'bind_tools' #24779
Replies: 2 comments
-
The
Here's the updated code: from langchain_core.tools import tool
from langchain_community.llms import VertexAI
from google.cloud import aiplatform
# Initialize Google Cloud AI Platform
aiplatform.init(
project='your_project_id',
location="your_preferred_location"
)
# Create a VertexAI model instance
model = VertexAI(model_name="gemini-pro", seed=123, max_output_tokens=8192, temperature=0)
# Define a tool using the tool decorator
@tool
def magic_function(input: int) -> int:
"""Applies a magic function to an input."""
return input + 2
# List of tools
tools = [magic_function]
# Query to be processed
query = "what is the value of magic_function(3)?"
# Import the create_react_agent function
from langgraph.prebuilt import create_react_agent
# Create the agent using the model and tools
app = create_react_agent(model, tools)
# Invoke the agent with the query
messages = app.invoke({"messages": [("human", query)]})
# Print the output
print({
"input": query,
"output": messages["messages"][-1].content,
}) This setup ensures that |
Beta Was this translation helpful? Give feedback.
-
So ChatVertexAI from langchain_google_vertexai lib has a bind_tools method...using that instead |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
When i run the above code, which is a slight modification of the LangGraph example code for migrating from Agent Executor to LangGraph (https://python.langchain.com/v0.2/docs/how_to/migrate_agent/) i get the error:
AttributeError: 'VertexAI' object has no attribute 'bind_tools'
Is there a way around this?
System Info
System Information
Package Information
Beta Was this translation helpful? Give feedback.
All reactions