1010 keeping token usage constant regardless of catalog size.
1111
1212This example demonstrates approach 2 with two patterns:
13- - Raw client (Gemini ): manual agent loop with ``toolset.execute()``
13+ - Raw client (OpenAI ): manual agent loop with ``toolset.execute()``
1414- LangChain: framework handles tool execution automatically
1515
1616Prerequisites:
1717 - STACKONE_API_KEY environment variable
1818 - STACKONE_ACCOUNT_ID environment variable
19- - GOOGLE_API_KEY environment variable (for Gemini/LangChain)
19+ - OPENAI_API_KEY environment variable
2020
2121Run with:
2222 uv run python examples/agent_tool_search.py
3737from stackone_ai import StackOneToolSet
3838
3939
40- def example_gemini () -> None :
41- """Raw client: Gemini via OpenAI-compatible API .
40+ def example_openai () -> None :
41+ """Raw client: OpenAI.
4242
4343 Shows: init toolset -> get OpenAI tools -> manual agent loop with toolset.execute().
4444 """
4545 print ("=" * 60 )
46- print ("Example 1: Raw client (Gemini ) — manual execution" )
46+ print ("Example 1: Raw client (OpenAI ) — manual execution" )
4747 print ("=" * 60 )
4848 print ()
4949
@@ -54,9 +54,8 @@ def example_gemini() -> None:
5454 print ()
5555 return
5656
57- google_key = os .getenv ("GOOGLE_API_KEY" )
58- if not google_key :
59- print ("Skipped: Set GOOGLE_API_KEY to run this example." )
57+ if not os .getenv ("OPENAI_API_KEY" ):
58+ print ("Skipped: Set OPENAI_API_KEY to run this example." )
6059 print ()
6160 return
6261
@@ -71,18 +70,25 @@ def example_gemini() -> None:
7170 # 2. Get tools in OpenAI format
7271 openai_tools = toolset .openai (mode = "search_and_execute" )
7372
74- # 3. Create Gemini client (OpenAI-compatible) and run agent loop
75- client = OpenAI (
76- api_key = google_key ,
77- base_url = "https://generativelanguage.googleapis.com/v1beta/openai/" ,
78- )
73+ # 3. Create OpenAI client and run agent loop
74+ client = OpenAI ()
7975 messages : list [dict ] = [
76+ {
77+ "role" : "system" ,
78+ "content" : (
79+ "You are a helpful scheduling assistant. Use tool_search to find relevant tools, "
80+ "then tool_execute to run them. Always read the parameter schemas from tool_search "
81+ "results carefully. If a tool needs a user URI, first search for and call a "
82+ '"get current user" tool to obtain it. If a tool execution fails, try different '
83+ "parameters or a different tool."
84+ ),
85+ },
8086 {"role" : "user" , "content" : "List my upcoming Calendly events for the next week." },
8187 ]
8288
8389 for _step in range (10 ):
8490 response = client .chat .completions .create (
85- model = "gemini-3-pro-preview " ,
91+ model = "gpt-5.4 " ,
8692 messages = messages ,
8793 tools = openai_tools ,
8894 tool_choice = "auto" ,
@@ -123,15 +129,15 @@ def example_langchain() -> None:
123129 print ()
124130
125131 try :
126- from langchain_core .messages import AIMessage , HumanMessage , ToolMessage
127- from langchain_google_genai import ChatGoogleGenerativeAI
132+ from langchain_core .messages import AIMessage , HumanMessage , SystemMessage , ToolMessage
133+ from langchain_openai import ChatOpenAI
128134 except ImportError :
129- print ("Skipped: pip install langchain-google-genai " )
135+ print ("Skipped: pip install langchain-openai " )
130136 print ()
131137 return
132138
133- if not os .getenv ("GOOGLE_API_KEY " ):
134- print ("Skipped: Set GOOGLE_API_KEY to run this example." )
139+ if not os .getenv ("OPENAI_API_KEY " ):
140+ print ("Skipped: Set OPENAI_API_KEY to run this example." )
135141 print ()
136142 return
137143
@@ -146,10 +152,21 @@ def example_langchain() -> None:
146152 # 2. Get tools in LangChain format and bind to model
147153 langchain_tools = toolset .langchain (mode = "search_and_execute" )
148154 tools_by_name = {tool .name : tool for tool in langchain_tools }
149- model = ChatGoogleGenerativeAI (model = "gemini-3-pro-preview " ).bind_tools (langchain_tools )
155+ model = ChatOpenAI (model = "gpt-5.4 " ).bind_tools (langchain_tools )
150156
151157 # 3. Run agent loop
152- messages = [HumanMessage (content = "List my upcoming Calendly events for the next week." )]
158+ messages = [
159+ SystemMessage (
160+ content = (
161+ "You are a helpful scheduling assistant. Use tool_search to find relevant tools, "
162+ "then tool_execute to run them. Always read the parameter schemas from tool_search "
163+ "results carefully. If a tool needs a user URI, first search for and call a "
164+ '"get current user" tool to obtain it. If a tool execution fails, try different '
165+ "parameters or a different tool."
166+ ),
167+ ),
168+ HumanMessage (content = "List my upcoming Calendly events for the next week." ),
169+ ]
153170
154171 for _step in range (10 ):
155172 response : AIMessage = model .invoke (messages )
@@ -177,7 +194,7 @@ def main() -> None:
177194 print ("Set STACKONE_API_KEY to run these examples." )
178195 return
179196
180- example_gemini ()
197+ example_openai ()
181198 example_langchain ()
182199
183200
0 commit comments