From 07919c5e8c4046e0c3ef7e66b5677435fec6e9c4 Mon Sep 17 00:00:00 2001 From: S2D2 Date: Thu, 19 Nov 2026 03:46:54 +0000 Subject: [PATCH 1/5] docs(examples): move examples to gpt-6.2-sol and the Responses API The examples and README pinned gpt-5.4. GPT-6 models refuse function tools on Chat Completions unless reasoning is off ("Function tools with reasoning_effort are not supported ... use /v1/responses"), so a plain model rename would break openai_integration.py. - openai_integration.py now uses the Responses API: it unwraps to_openai()'s Chat Completions tools, runs calls through execute_openai_tool_calls(), and loops (bounded at 5 turns) until the model answers, since GPT-6.2 often calls a tool twice before answering. - LangChain and LangGraph examples print message.text: langchain-openai switches to the Responses API for these models and .content becomes a list of blocks, including encrypted reasoning. - Pydantic AI examples and README snippets move to gpt-6.2-sol. Co-Authored-By: Claude Opus 5.5 Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com> --- README.md | 38 +++++++++---- examples/langchain_integration.py | 4 +- examples/langgraph_integration.py | 4 +- examples/openai_integration.py | 88 +++++++++++++++++------------ examples/pydantic_ai_integration.py | 4 +- 5 files changed, 85 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 25c9b40..c26b839 100644 --- a/README.md +++ b/README.md @@ -121,24 +121,38 @@ toolset = StackOneToolSet() tools = toolset.fetch_tools(actions=["*_list_*"]) openai_tools = tools.to_openai()[:20] # keep the catalog inside the context window +# to_openai() emits Chat Completions tools; the Responses API wants the function one level up +openai_tools = [{"type": "function", **t["function"]} for t in openai_tools] + client = OpenAI() -messages = [{"role": "user", "content": "Use a tool to list a few records, then summarise them."}] -response = client.chat.completions.create( - model="gpt-5.4", messages=messages, tools=openai_tools, tool_choice="auto" +response = client.responses.create( + model="gpt-6.2-sol", + input="Use a tool to list a few records, then summarise them.", + tools=openai_tools, ) -message = response.choices[0].message -messages.append(message.model_dump(exclude_none=True)) # the assistant turn comes first -messages.extend(tools.execute_openai_tool_calls(message.tool_calls)) +outputs = [] +for call in (item for item in response.output if item.type == "function_call"): + [message] = tools.execute_openai_tool_calls( + [{"id": call.call_id, "function": {"name": call.name, "arguments": call.arguments}}] + ) + outputs.append({"type": "function_call_output", "call_id": call.call_id, "output": message["content"]}) + +# Send `outputs` back with previous_response_id=response.id, and repeat while the model +# keeps calling tools: examples/openai_integration.py has the loop. ``` `to_openai()` emits Chat Completions function tools, and `execute_openai_tool_calls()` runs the calls the model makes and returns the `tool` messages to send back. A failed call becomes an error message the model can read and -retry from, rather than an exception. Chat Completions accepts at +retry from, rather than an exception. GPT-6 models accept function tools only on the +Responses API (Chat Completions refuses them unless reasoning is off), so the snippet +above unwraps each tool and passes the calls through in the Chat Completions shape. +Older models work with `client.chat.completions.create(..., tools=tools.to_openai())` +and `execute_openai_tool_calls(message.tool_calls)` directly. OpenAI accepts at most **128 tools**, so filter before binding. See [examples/openai_integration.py](https://github.com/StackOneHQ/stackone-ai-python/blob/main/examples/openai_integration.py) for the full -round trip, including feeding results back for a final answer. +round trip, including the loop that feeds results back until the model answers. @@ -156,7 +170,7 @@ from stackone_ai import StackOneToolSet toolset = StackOneToolSet() tools = toolset.fetch_tools(actions=["*_list_*"]) -model = ChatOpenAI(model="gpt-5.4").bind_tools(tools.to_langchain()) +model = ChatOpenAI(model="gpt-6.2-sol").bind_tools(tools.to_langchain()) response = model.invoke("Use a tool to list a few records.") for call in response.tool_calls: @@ -180,7 +194,7 @@ from stackone_ai import StackOneToolSet toolset = StackOneToolSet() tools = toolset.fetch_tools(actions=["*_list_*"]).to_pydantic_ai() -agent = Agent("openai:gpt-5.4", tools=tools) +agent = Agent("openai:gpt-6.2-sol", tools=tools) print(agent.run_sync("Use a tool to list a few records, then summarise them.").output) ``` @@ -206,9 +220,9 @@ from stackone_ai import StackOneToolSet toolset = StackOneToolSet() tools = toolset.fetch_tools(actions=["*_list_*"]).to_langchain() -agent = create_agent(ChatOpenAI(model="gpt-5.4"), tools) +agent = create_agent(ChatOpenAI(model="gpt-6.2-sol"), tools) result = agent.invoke({"messages": [("user", "Use a tool to list a few records.")]}) -print(result["messages"][-1].content) +print(result["messages"][-1].text) ``` diff --git a/examples/langchain_integration.py b/examples/langchain_integration.py index 1fbd9a4..a8875a0 100644 --- a/examples/langchain_integration.py +++ b/examples/langchain_integration.py @@ -46,11 +46,11 @@ def langchain_integration() -> None: print(f" - {tool.name}") # Create model with tools - model = ChatOpenAI(model="gpt-5.4") + model = ChatOpenAI(model="gpt-6.2-sol") model_with_tools = model.bind_tools(langchain_tools) result = model_with_tools.invoke("Use one of your tools to list a few records, then summarise them.") - print(f"LLM response: {result.content}") + print(f"LLM response: {result.text}") if result.tool_calls: print(f"LLM made {len(result.tool_calls)} tool call(s).") diff --git a/examples/langgraph_integration.py b/examples/langgraph_integration.py index 000d56b..bf6aa5a 100644 --- a/examples/langgraph_integration.py +++ b/examples/langgraph_integration.py @@ -55,7 +55,7 @@ def langgraph_integration() -> None: print(f" - {tool.name}") # Create a ReAct agent with LangGraph - model = ChatOpenAI(model="gpt-5.4") + model = ChatOpenAI(model="gpt-6.2-sol") agent = create_agent(model, langchain_tools) result = agent.invoke( @@ -69,7 +69,7 @@ def langgraph_integration() -> None: } ) final_message = result["messages"][-1] - print(f"Agent response:\n{final_message.content}") + print(f"Agent response:\n{final_message.text}") if __name__ == "__main__": diff --git a/examples/openai_integration.py b/examples/openai_integration.py index 4470c66..636a8dd 100644 --- a/examples/openai_integration.py +++ b/examples/openai_integration.py @@ -14,8 +14,8 @@ result of running it, and the model's final answer. It exits non-zero if your key reaches no tools, rather than pretending to succeed with an empty toolbox. -You can find out more about the OpenAI Function Calling API format -[here](https://platform.openai.com/docs/guides/function-calling). +It uses the Responses API, which GPT-6 models need for function tools. More on +the format [here](https://platform.openai.com/docs/guides/function-calling). """ from __future__ import annotations @@ -35,6 +35,9 @@ from stackone_ai import StackOneToolSet from stackone_ai.types import StackOneError, ToolsetError +MODEL = "gpt-6.2-sol" +MAX_TURNS = 5 + def openai_integration() -> None: client = OpenAI() @@ -50,43 +53,58 @@ def openai_integration() -> None: "an empty catalog here means the example would prove nothing." ) - openai_tools: list[Any] = tools.to_openai()[:20] - names = {t["function"]["name"] for t in openai_tools} + # to_openai() returns Chat Completions tools. The Responses API takes the same + # function definition one level up, so unwrap it. GPT-6 models need the Responses + # API for function tools; Chat Completions refuses them unless reasoning is off. + openai_tools: list[Any] = [{"type": "function", **t["function"]} for t in tools.to_openai()[:20]] + names = {t["name"] for t in openai_tools} print(f"Loaded {len(openai_tools)} tools, e.g. {sorted(names)[:3]}") - messages: list[Any] = [ - {"role": "system", "content": "You answer questions by calling the tools you are given."}, - { - "role": "user", - "content": "Use one of your tools to list a few records, then summarise them.", - }, - ] - - response = client.chat.completions.create( - model="gpt-5.4", messages=messages, tools=openai_tools, tool_choice="auto" + instructions = "You answer questions by calling the tools you are given." + response = client.responses.create( + model=MODEL, + instructions=instructions, + input="Use one of your tools to list a few records, then summarise them.", + tools=openai_tools, ) - tool_calls = response.choices[0].message.tool_calls - if not tool_calls: - print("No tool calls were made by the model.") - return - - print(f"LLM made {len(tool_calls)} tool call(s):") - for tc in tool_calls: - if tc.type == "function": - print(f" - {tc.function.name}({tc.function.arguments})") - - # The assistant turn must come before its tool results, or OpenAI returns a 400. - messages.append(response.choices[0].message.model_dump(exclude_none=True)) - tool_messages = tools.execute_openai_tool_calls(tool_calls) - for message in tool_messages: - print(f" Result: {message['content'][:200]}...") - messages.extend(tool_messages) - - final_response = client.chat.completions.create( - model="gpt-5.4", messages=messages, tools=openai_tools, tool_choice="auto" - ) - print(f"Final response:\n{final_response.choices[0].message.content}") + # The model may call tools more than once (paging, say), so loop until it answers. + # Bounded, so a model that keeps calling tools cannot run up a bill. + calls_made = 0 + for _ in range(MAX_TURNS): + function_calls = [item for item in response.output if item.type == "function_call"] + if not function_calls: + break + outputs: list[Any] = [] + for call in function_calls: + calls_made += 1 + print(f"Tool call: {call.name}({call.arguments})") + # execute_openai_tool_calls() reads the Chat Completions shape; give it that + # shape and send its content back as the Responses API's function_call_output. + [message] = tools.execute_openai_tool_calls( + [{"id": call.call_id, "function": {"name": call.name, "arguments": call.arguments}}] + ) + print(f" Result: {message['content'][:200]}...") + outputs.append( + {"type": "function_call_output", "call_id": call.call_id, "output": message["content"]} + ) + + # previous_response_id carries the model's turn, reasoning included, so only the + # tool results need sending. + response = client.responses.create( + model=MODEL, + instructions=instructions, + previous_response_id=response.id, + input=outputs, + tools=openai_tools, + ) + else: + raise SystemExit(f"The model was still calling tools after {MAX_TURNS} turns.") + + if calls_made == 0: + raise SystemExit("The model answered without calling a tool, so the example proved nothing.") + print(f"LLM made {calls_made} tool call(s).") + print(f"Final response:\n{response.output_text}") if __name__ == "__main__": diff --git a/examples/pydantic_ai_integration.py b/examples/pydantic_ai_integration.py index eee9c90..31b61d6 100644 --- a/examples/pydantic_ai_integration.py +++ b/examples/pydantic_ai_integration.py @@ -37,7 +37,7 @@ def individual_tools(account_id: str) -> None: raise SystemExit(f"Account {account_id} served no list tools, so the example would prove nothing.") agent = Agent( - "openai:gpt-5.4", + "openai:gpt-6.2-sol", system_prompt="You are a helpful assistant that answers by calling tools.", tools=tools.to_pydantic_ai(), ) @@ -53,7 +53,7 @@ def search_and_execute(account_id: str) -> None: raise SystemExit(f"Account {account_id} served no search and execute tools.") agent = Agent( - "openai:gpt-5.4", + "openai:gpt-6.2-sol", system_prompt=( "You answer by calling tools. First call stackone_search_actions to find an action, " "then call stackone_execute_action with its action_id and arguments built from its " From 46196518730d6f7d87d009bb6c020bd2fa281ac1 Mon Sep 17 00:00:00 2001 From: S2D2 Date: Thu, 19 Nov 2026 03:52:02 +0000 Subject: [PATCH 2/5] fix(examples): select the Responses API explicitly and fix the turn bound Codex review findings on the previous commit: - At the supported minimum langchain-openai (1.1.14) and pydantic-ai (1.83.0), `ChatOpenAI(model=...)` and `openai:` can route through Chat Completions, which GPT-6 refuses for function tools. Pass use_responses_api=True and use the openai-responses: prefix so every supported version takes the Responses API. Verified at the minimum versions and at the locked ones. - openai_integration.py raised "still calling tools" after the fifth round even when that round's response was the final answer. Check the response first, then stop. Co-Authored-By: Claude Opus 5.5 Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com> --- README.md | 6 +++--- examples/langchain_integration.py | 2 +- examples/langgraph_integration.py | 2 +- examples/openai_integration.py | 6 +++--- examples/pydantic_ai_integration.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c26b839..9fc5fbe 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ from stackone_ai import StackOneToolSet toolset = StackOneToolSet() tools = toolset.fetch_tools(actions=["*_list_*"]) -model = ChatOpenAI(model="gpt-6.2-sol").bind_tools(tools.to_langchain()) +model = ChatOpenAI(model="gpt-6.2-sol", use_responses_api=True).bind_tools(tools.to_langchain()) response = model.invoke("Use a tool to list a few records.") for call in response.tool_calls: @@ -194,7 +194,7 @@ from stackone_ai import StackOneToolSet toolset = StackOneToolSet() tools = toolset.fetch_tools(actions=["*_list_*"]).to_pydantic_ai() -agent = Agent("openai:gpt-6.2-sol", tools=tools) +agent = Agent("openai-responses:gpt-6.2-sol", tools=tools) print(agent.run_sync("Use a tool to list a few records, then summarise them.").output) ``` @@ -220,7 +220,7 @@ from stackone_ai import StackOneToolSet toolset = StackOneToolSet() tools = toolset.fetch_tools(actions=["*_list_*"]).to_langchain() -agent = create_agent(ChatOpenAI(model="gpt-6.2-sol"), tools) +agent = create_agent(ChatOpenAI(model="gpt-6.2-sol", use_responses_api=True), tools) result = agent.invoke({"messages": [("user", "Use a tool to list a few records.")]}) print(result["messages"][-1].text) ``` diff --git a/examples/langchain_integration.py b/examples/langchain_integration.py index a8875a0..175943c 100644 --- a/examples/langchain_integration.py +++ b/examples/langchain_integration.py @@ -46,7 +46,7 @@ def langchain_integration() -> None: print(f" - {tool.name}") # Create model with tools - model = ChatOpenAI(model="gpt-6.2-sol") + model = ChatOpenAI(model="gpt-6.2-sol", use_responses_api=True) model_with_tools = model.bind_tools(langchain_tools) result = model_with_tools.invoke("Use one of your tools to list a few records, then summarise them.") diff --git a/examples/langgraph_integration.py b/examples/langgraph_integration.py index bf6aa5a..c935d27 100644 --- a/examples/langgraph_integration.py +++ b/examples/langgraph_integration.py @@ -55,7 +55,7 @@ def langgraph_integration() -> None: print(f" - {tool.name}") # Create a ReAct agent with LangGraph - model = ChatOpenAI(model="gpt-6.2-sol") + model = ChatOpenAI(model="gpt-6.2-sol", use_responses_api=True) agent = create_agent(model, langchain_tools) result = agent.invoke( diff --git a/examples/openai_integration.py b/examples/openai_integration.py index 636a8dd..ca95b83 100644 --- a/examples/openai_integration.py +++ b/examples/openai_integration.py @@ -71,10 +71,12 @@ def openai_integration() -> None: # The model may call tools more than once (paging, say), so loop until it answers. # Bounded, so a model that keeps calling tools cannot run up a bill. calls_made = 0 - for _ in range(MAX_TURNS): + for turn in range(MAX_TURNS + 1): function_calls = [item for item in response.output if item.type == "function_call"] if not function_calls: break + if turn == MAX_TURNS: + raise SystemExit(f"The model was still calling tools after {MAX_TURNS} turns.") outputs: list[Any] = [] for call in function_calls: calls_made += 1 @@ -98,8 +100,6 @@ def openai_integration() -> None: input=outputs, tools=openai_tools, ) - else: - raise SystemExit(f"The model was still calling tools after {MAX_TURNS} turns.") if calls_made == 0: raise SystemExit("The model answered without calling a tool, so the example proved nothing.") diff --git a/examples/pydantic_ai_integration.py b/examples/pydantic_ai_integration.py index 31b61d6..0229636 100644 --- a/examples/pydantic_ai_integration.py +++ b/examples/pydantic_ai_integration.py @@ -37,7 +37,7 @@ def individual_tools(account_id: str) -> None: raise SystemExit(f"Account {account_id} served no list tools, so the example would prove nothing.") agent = Agent( - "openai:gpt-6.2-sol", + "openai-responses:gpt-6.2-sol", system_prompt="You are a helpful assistant that answers by calling tools.", tools=tools.to_pydantic_ai(), ) @@ -53,7 +53,7 @@ def search_and_execute(account_id: str) -> None: raise SystemExit(f"Account {account_id} served no search and execute tools.") agent = Agent( - "openai:gpt-6.2-sol", + "openai-responses:gpt-6.2-sol", system_prompt=( "You answer by calling tools. First call stackone_search_actions to find an action, " "then call stackone_execute_action with its action_id and arguments built from its " From ef9f0dbb8af63f9e64cbc99281cf6e2048a84abf Mon Sep 17 00:00:00 2001 From: S2D2 Date: Thu, 19 Nov 2026 04:11:28 +0000 Subject: [PATCH 3/5] docs(readme): send tool results back in the Responses snippet Co-Authored-By: Claude Opus 5.5 Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com> --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9fc5fbe..dccbb22 100644 --- a/README.md +++ b/README.md @@ -131,15 +131,21 @@ response = client.responses.create( tools=openai_tools, ) -outputs = [] -for call in (item for item in response.output if item.type == "function_call"): - [message] = tools.execute_openai_tool_calls( - [{"id": call.call_id, "function": {"name": call.name, "arguments": call.arguments}}] +for _ in range(5): # bounded: the model may call tools more than once before answering + calls = [item for item in response.output if item.type == "function_call"] + if not calls: + break + outputs = [] + for call in calls: + [message] = tools.execute_openai_tool_calls( + [{"id": call.call_id, "function": {"name": call.name, "arguments": call.arguments}}] + ) + outputs.append({"type": "function_call_output", "call_id": call.call_id, "output": message["content"]}) + response = client.responses.create( + model="gpt-6.2-sol", previous_response_id=response.id, input=outputs, tools=openai_tools ) - outputs.append({"type": "function_call_output", "call_id": call.call_id, "output": message["content"]}) -# Send `outputs` back with previous_response_id=response.id, and repeat while the model -# keeps calling tools: examples/openai_integration.py has the loop. +print(response.output_text) ``` `to_openai()` emits Chat Completions function tools, and @@ -152,7 +158,7 @@ Older models work with `client.chat.completions.create(..., tools=tools.to_opena and `execute_openai_tool_calls(message.tool_calls)` directly. OpenAI accepts at most **128 tools**, so filter before binding. See [examples/openai_integration.py](https://github.com/StackOneHQ/stackone-ai-python/blob/main/examples/openai_integration.py) for the full -round trip, including the loop that feeds results back until the model answers. +round trip, with error handling and a check that the model called a tool at all. From 41c834838657a3b778951e02d74cb584f34871b9 Mon Sep 17 00:00:00 2001 From: S2D2 Date: Thu, 19 Nov 2026 04:13:57 +0000 Subject: [PATCH 4/5] style(readme): ruff format the Responses snippet Co-Authored-By: Claude Opus 5.5 Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com> --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dccbb22..f04def2 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,9 @@ for _ in range(5): # bounded: the model may call tools more than once before an [message] = tools.execute_openai_tool_calls( [{"id": call.call_id, "function": {"name": call.name, "arguments": call.arguments}}] ) - outputs.append({"type": "function_call_output", "call_id": call.call_id, "output": message["content"]}) + outputs.append( + {"type": "function_call_output", "call_id": call.call_id, "output": message["content"]} + ) response = client.responses.create( model="gpt-6.2-sol", previous_response_id=response.id, input=outputs, tools=openai_tools ) From e7f0e4919f3c80fe04abfec8eaef92aab23e7a6a Mon Sep 17 00:00:00 2001 From: S2D2 Date: Thu, 19 Nov 2026 04:16:35 +0000 Subject: [PATCH 5/5] docs(readme): fail loudly when the Responses loop runs out of rounds Co-Authored-By: Claude Opus 5.5 Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com> --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f04def2..7c1de4f 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,8 @@ for _ in range(5): # bounded: the model may call tools more than once before an model="gpt-6.2-sol", previous_response_id=response.id, input=outputs, tools=openai_tools ) +if any(item.type == "function_call" for item in response.output): + raise SystemExit("The model was still calling tools after 5 rounds.") print(response.output_text) ```