diff --git a/samples/langchain_on_vertexai/prebuilt_langchain_agent_template.py b/samples/langchain_on_vertexai/prebuilt_langchain_agent_template.py index f4a14675..6dbffc33 100644 --- a/samples/langchain_on_vertexai/prebuilt_langchain_agent_template.py +++ b/samples/langchain_on_vertexai/prebuilt_langchain_agent_template.py @@ -92,7 +92,7 @@ def similarity_search(query: str) -> list[Document]: DISPLAY_NAME = os.getenv("DISPLAY_NAME") or "PrebuiltAgent" remote_app = reasoning_engines.ReasoningEngine.create( - reasoning_engines.LangchainAgent( + reasoning_engines.LangchainAgent( # type: ignore[arg-type] model="gemini-2.0-flash-001", tools=[similarity_search], # type: ignore[list-item] model_kwargs={ @@ -103,6 +103,6 @@ def similarity_search(query: str) -> list[Document]: display_name="PrebuiltAgent", sys_version="3.11", extra_packages=["config.py"], -) # type: ignore[arg-type] +) print(remote_app.query(input="movies about engineers")) # type: ignore[attr-defined] diff --git a/samples/langchain_on_vertexai/retriever_agent_with_history_template.py b/samples/langchain_on_vertexai/retriever_agent_with_history_template.py index e2eea8d6..ff4de53b 100644 --- a/samples/langchain_on_vertexai/retriever_agent_with_history_template.py +++ b/samples/langchain_on_vertexai/retriever_agent_with_history_template.py @@ -27,11 +27,11 @@ TABLE_NAME, USER, ) -from langchain import hub from langchain.agents import AgentExecutor, create_react_agent from langchain.tools.retriever import create_retriever_tool from langchain_core.runnables.history import RunnableWithMessageHistory from langchain_google_vertexai import ChatVertexAI, VertexAIEmbeddings +from langsmith import Client from vertexai.preview import reasoning_engines # type: ignore from langchain_google_alloydb_pg import ( @@ -109,7 +109,12 @@ def set_up(self): # Initialize the LLM and prompt llm = ChatVertexAI(model_name=self.model_name, project=self.project) - base_prompt = hub.pull("langchain-ai/react-agent-template") + # ``react-agent-template`` is an official, trusted LangChain prompt. + # langsmith disables pulling public prompts by default, so explicitly + # acknowledge the source with ``dangerously_pull_public_prompt``. + base_prompt = Client().pull_prompt( + "langchain-ai/react-agent-template", dangerously_pull_public_prompt=True + ) instructions = ( "You are an assistant for question-answering tasks. " "Use the following pieces of retrieved context to answer " @@ -135,19 +140,20 @@ def set_up(self): history_messages_key="chat_history", ) - def query(self, input: str, session_id: str, **kwargs: Any) -> str: + def query(self, **kwargs: Any) -> Any: """Query the application. Args: - input: The user query. - session_id: The user's session id. + **kwargs: Keyword arguments forwarded from the reasoning engine. + Expects ``input`` (the user query) and ``session_id`` + (the user's session id). Returns: - The LLM response dictionary. + The LLM response. """ response = self.agent.invoke( - {"input": input}, - config={"configurable": {"session_id": session_id}}, + {"input": kwargs["input"]}, + config={"configurable": {"session_id": kwargs["session_id"]}}, ) return response["output"] diff --git a/samples/langchain_on_vertexai/retriever_chain_template.py b/samples/langchain_on_vertexai/retriever_chain_template.py index 905c41dd..55854736 100644 --- a/samples/langchain_on_vertexai/retriever_chain_template.py +++ b/samples/langchain_on_vertexai/retriever_chain_template.py @@ -109,18 +109,18 @@ def set_up(self): # an LLM to generate a response self.chain = create_retrieval_chain(retriever, combine_docs_chain) - def query(self, input: str, **kwargs: Any) -> str: + def query(self, **kwargs: Any) -> Any: """Query the application. Args: - input: The user query. - **kwargs: Additional arguments for Protocol compliance. + **kwargs: Keyword arguments forwarded from the reasoning engine. + Expects an ``input`` key containing the user query. Returns: - The LLM response dictionary. + The LLM response. """ # Define the runtime logic that serves user queries - response = self.chain.invoke({"input": input}) + response = self.chain.invoke({"input": kwargs["input"]}) return response["answer"] diff --git a/samples/requirements.txt b/samples/requirements.txt index 55ca38fb..a7feb5db 100644 --- a/samples/requirements.txt +++ b/samples/requirements.txt @@ -1,4 +1,4 @@ -google-cloud-aiplatform[reasoningengine,langchain]==1.97.0 +google-cloud-aiplatform[reasoningengine,langchain]==1.133.0 google-cloud-resource-manager==1.15.0 langchain-community==0.3.31 langchain-google-alloydb-pg==0.13.0