Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand All @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 "
Expand All @@ -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"]

Expand Down
10 changes: 5 additions & 5 deletions samples/langchain_on_vertexai/retriever_chain_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]


Expand Down
2 changes: 1 addition & 1 deletion samples/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading