Skip to content

Commit 4c0845d

Browse files
authored
fix(quickstart): robust tool lookup and modernize dependencies in Python samples (googleapis#2863)
## Description This PR addresses several reliability and modernization issues in the Python quickstart samples and documentation: * Replaced brittle hardcoded index-based tool lookups (`toolbox_tools[0]`) with a robust name-based lookup dictionary (`tool_map`) in `core/quickstart.py` and `local_quickstart.md`. * This prevents `TypeError` failures when the tool order returned by the server changes. * Implemented modernization & model updates. * Updated models to use `gemini-2.5-flash` across Core, LangChain, and LlamaIndex quickstarts. * Updated `toolbox-core` and `toolbox-langchain` dependencies to `1.0.0`. * Switched the LangChain sample from `ChatVertexAI` to `ChatGoogleGenerativeAI` and updated `langgraph` to `1.1.6` to resolve dependency conflicts in the CI environment. * Updated a test query in `adk/agent.py` to directly call `update-hotel` instead of asking for a complex multi-action "Book with dates" request in one shot, which was causing model execution failures.
1 parent 2490a4b commit 4c0845d

12 files changed

Lines changed: 1128 additions & 1098 deletions

File tree

docs/en/documentation/configuration/pre-post-processing/python/adk/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async def main():
128128
runner,
129129
session_id,
130130
user_id,
131-
"Book a hotel with id 5 with checkin date 2025-01-18 and checkout date 2025-02-10",
131+
"Update hotel with id 5 with checkin date 2025-01-18 and checkout date 2025-02-10",
132132
)
133133
await toolset.close()
134134

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
google-adk[toolbox]==1.27.2
2-
toolbox-adk==0.7.0
3-
google-genai==1.67.0
1+
google-adk[toolbox]==1.28.1
2+
google-genai==1.67.0

docs/en/documentation/configuration/pre-post-processing/python/langchain/agent.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from langchain.agents import create_agent
55
from langchain.agents.middleware import wrap_tool_call
66
from langchain_core.messages import ToolMessage
7-
from langchain_google_vertexai import ChatVertexAI
7+
from langchain_google_genai import ChatGoogleGenerativeAI
88
from toolbox_langchain import ToolboxClient
99

1010
system_prompt = """
@@ -84,7 +84,7 @@ async def enrich_response(request, handler):
8484
async def main():
8585
async with ToolboxClient("http://127.0.0.1:5000") as client:
8686
tools = await client.aload_toolset("my-toolset")
87-
model = ChatVertexAI(model="gemini-2.5-flash")
87+
model = ChatGoogleGenerativeAI(model="gemini-2.5-flash")
8888
agent = create_agent(
8989
system_prompt=system_prompt,
9090
model=model,
@@ -94,22 +94,24 @@ async def main():
9494
)
9595
# Test post-processing
9696
user_input = "Book hotel with id 3."
97+
print(f"\n[INPUT] User: {user_input}")
9798
response = await agent.ainvoke(
9899
{"messages": [{"role": "user", "content": user_input}]}
99100
)
100101

101102
print("-" * 50)
102103
last_ai_msg = response["messages"][-1].content
103-
print(f"AI: {last_ai_msg}")
104+
print(f"[OUTPUT] AI: {last_ai_msg}")
104105

105106
# Test Pre-processing
106107
print("-" * 50)
107108
user_input = "Update my hotel with id 3 with checkin date 2025-01-18 and checkout date 2025-02-20."
109+
print(f"\n[INPUT] User: {user_input}")
108110
response = await agent.ainvoke(
109111
{"messages": [{"role": "user", "content": user_input}]}
110112
)
111113
last_ai_msg = response["messages"][-1].content
112-
print(f"AI: {last_ai_msg}")
114+
print(f"[OUTPUT] AI: {last_ai_msg}")
113115

114116

115117
if __name__ == "__main__":
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
langchain==1.2.12
2-
langchain-google-vertexai==3.2.2
3-
toolbox-langchain==0.6.0
2+
langchain-google-genai==4.2.1
3+
toolbox-langchain==1.0.0

0 commit comments

Comments
 (0)