Skip to content
Merged
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
12 changes: 7 additions & 5 deletions examples/auth_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def single_account(account_id: str) -> None:

toolset = StackOneToolSet()
tools = toolset.fetch_tools(actions=["*_list_*"], account_ids=[account_id])
if not tools:
raise SystemExit(f"Account {account_id} served no list tools, so the example would prove nothing.")
print(f"Fetched {len(tools)} tools for configured account")


Expand All @@ -56,6 +58,8 @@ def set_accounts_globally(account_id: str) -> None:
print("Set global accounts via set_accounts()")

tools = toolset.fetch_tools(actions=["*_list_*"])
if not tools:
raise SystemExit(f"Account {account_id} served no list tools, so the example would prove nothing.")
print(f"Fetched {len(tools)} tools (account inherited from toolset)")


Expand All @@ -66,7 +70,7 @@ def per_tool_override(account_id: str) -> None:
toolset = StackOneToolSet()
tools = toolset.fetch_tools(actions=["*_list_*"], account_ids=[account_id])
if not tools:
raise SystemExit(f"Account {account_id} served no list tools — nothing to demonstrate.")
raise SystemExit(f"Account {account_id} served no list tools, so the example would prove nothing.")

# Override on the entire tools collection
tools.set_account_id("overridden-account")
Expand All @@ -81,13 +85,11 @@ def per_tool_override(account_id: str) -> None:
def main() -> None:
api_key = os.getenv("STACKONE_API_KEY")
if not api_key:
print("STACKONE_API_KEY is not set. Please export it or add it to .env")
return
raise SystemExit("STACKONE_API_KEY is not set. Please export it or add it to .env")

account_id = os.getenv("STACKONE_ACCOUNT_ID")
if not account_id:
print("Set STACKONE_ACCOUNT_ID to run this example.")
return
raise SystemExit("Set STACKONE_ACCOUNT_ID to run this example.")

api_key_setup()
single_account(account_id)
Expand Down
33 changes: 19 additions & 14 deletions examples/langchain_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import annotations

import os
import sys

try:
from dotenv import load_dotenv
Expand All @@ -20,25 +21,23 @@
from langchain_openai import ChatOpenAI

from stackone_ai import StackOneToolSet
from stackone_ai.types import StackOneError, ToolsetError


def langchain_integration() -> None:
account_id = os.getenv("STACKONE_ACCOUNT_ID")
if not os.getenv("STACKONE_API_KEY"):
print("Set STACKONE_API_KEY to run this example.")
return
if not account_id:
print("Set STACKONE_ACCOUNT_ID to run this example.")
return
if not os.getenv("OPENAI_API_KEY"):
print("Set OPENAI_API_KEY to run this example.")
return
for var in ["STACKONE_API_KEY", "STACKONE_ACCOUNT_ID", "OPENAI_API_KEY"]:
if not os.getenv(var):
raise SystemExit(f"Set {var} to run this example.")

account_id = os.environ["STACKONE_ACCOUNT_ID"]

toolset = StackOneToolSet()
tools = toolset.fetch_tools(
actions=["*_list_*"],
account_ids=[account_id],
)
if not tools:
raise SystemExit(f"Account {account_id} served no list tools, so the example would prove nothing.")

# Convert to LangChain format
langchain_tools = tools.to_langchain()
Expand All @@ -58,12 +57,18 @@ def langchain_integration() -> None:
for tool_call in result.tool_calls:
print(f" - {tool_call['name']}({tool_call['args']})")
tool = tools.get_tool(tool_call["name"])
if tool:
call_result = tool.execute(tool_call["args"])
print(f" Result: {str(call_result)[:200]}...")
if tool is None:
raise SystemExit(f"The model called {tool_call['name']}, which is not a fetched tool.")
call_result = tool.execute(tool_call["args"])
print(f" Result: {str(call_result)[:200]}...")
else:
print("No tool calls were made by the model.")


if __name__ == "__main__":
langchain_integration()
try:
langchain_integration()
except ToolsetError as exc:
sys.exit(f"Could not load tools: {exc}")
except StackOneError as exc:
sys.exit(f"StackOne API error: {exc}")
23 changes: 10 additions & 13 deletions examples/langgraph_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,23 @@
from langchain_openai import ChatOpenAI

from stackone_ai import StackOneToolSet
from stackone_ai.types import StackOneAPIError, ToolsetError
from stackone_ai.types import StackOneError, ToolsetError


def langgraph_integration() -> None:
account_id = os.getenv("STACKONE_ACCOUNT_ID")
if not os.getenv("STACKONE_API_KEY"):
print("Set STACKONE_API_KEY to run this example.")
return
if not account_id:
print("Set STACKONE_ACCOUNT_ID to run this example.")
return
if not os.getenv("OPENAI_API_KEY"):
print("Set OPENAI_API_KEY to run this example.")
return
for var in ["STACKONE_API_KEY", "STACKONE_ACCOUNT_ID", "OPENAI_API_KEY"]:
if not os.getenv(var):
raise SystemExit(f"Set {var} to run this example.")

account_id = os.environ["STACKONE_ACCOUNT_ID"]

toolset = StackOneToolSet()
tools = toolset.fetch_tools(
actions=["*_list_*"],
account_ids=[account_id],
)
if not tools:
raise SystemExit(f"Account {account_id} served no list tools, so the example would prove nothing.")

# LangGraph uses LangChain tools natively
langchain_tools = tools.to_langchain()
Expand Down Expand Up @@ -80,5 +77,5 @@ def langgraph_integration() -> None:
langgraph_integration()
except ToolsetError as exc:
sys.exit(f"Could not load tools: {exc}")
except StackOneAPIError as exc:
sys.exit(f"Tool call rejected with {exc.status_code}: {exc.response_body}")
except StackOneError as exc:
sys.exit(f"StackOne API error: {exc}")
24 changes: 17 additions & 7 deletions examples/pydantic_ai_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from __future__ import annotations

import os
import sys

try:
from dotenv import load_dotenv
Expand All @@ -26,16 +27,19 @@
raise SystemExit(1) from None

from stackone_ai import StackOneToolSet
from stackone_ai.types import StackOneError, ToolsetError


def individual_tools(account_id: str) -> None:
"""One Pydantic AI tool per action: suits a handful of actions."""
tools = StackOneToolSet().fetch_tools(actions=["*_list_*"], account_ids=[account_id]).to_pydantic_ai()
tools = StackOneToolSet().fetch_tools(actions=["*_list_*"], account_ids=[account_id])
if not tools:
raise SystemExit(f"Account {account_id} served no list tools, so the example would prove nothing.")

agent = Agent(
"openai:gpt-5.4",
system_prompt="You are a helpful assistant that answers by calling tools.",
tools=tools,
tools=tools.to_pydantic_ai(),
)
result = agent.run_sync("Use one of your tools to list a few records, then summarise them.")
print(f"Individual tools:\n{result.output}\n")
Expand All @@ -44,7 +48,9 @@ def individual_tools(account_id: str) -> None:
def search_and_execute(account_id: str) -> None:
"""StackOne's search and execute tools: the model finds an action, then runs it."""
toolset = StackOneToolSet(tool_mode="search_execute")
tools = toolset.fetch_tools(account_ids=[account_id]).to_pydantic_ai()
tools = toolset.fetch_tools(account_ids=[account_id])
if not tools:
raise SystemExit(f"Account {account_id} served no search and execute tools.")

agent = Agent(
"openai:gpt-5.4",
Expand All @@ -53,7 +59,7 @@ def search_and_execute(account_id: str) -> None:
"then call stackone_execute_action with its action_id and arguments built from its "
"example_request."
),
tools=tools,
tools=tools.to_pydantic_ai(),
)
result = agent.run_sync("List a few records from any of my connected apps, then summarise them.")
print(f"Search and execute:\n{result.output}")
Expand All @@ -62,13 +68,17 @@ def search_and_execute(account_id: str) -> None:
def pydantic_ai_integration() -> None:
for var in ["STACKONE_API_KEY", "STACKONE_ACCOUNT_ID", "OPENAI_API_KEY"]:
if not os.getenv(var):
print(f"Set {var} to run this example.")
return
raise SystemExit(f"Set {var} to run this example.")

account_id = os.environ["STACKONE_ACCOUNT_ID"]
individual_tools(account_id)
search_and_execute(account_id)


if __name__ == "__main__":
pydantic_ai_integration()
try:
pydantic_ai_integration()
except ToolsetError as exc:
sys.exit(f"Could not load tools: {exc}")
except StackOneError as exc:
sys.exit(f"StackOne API error: {exc}")
Loading