Skip to content

Commit 85db80f

Browse files
Example Cleanup - Python
1 parent 54dadde commit 85db80f

19 files changed

Lines changed: 496 additions & 1104 deletions

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Required for all examples
2+
STACKONE_API_KEY=your-stackone-api-key
3+
STACKONE_ACCOUNT_ID=your-account-id
4+
5+
# Required for OpenAI-based examples (openai_integration, langchain_integration, crewai_integration, search_tools)
6+
OPENAI_API_KEY=your-openai-api-key

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.env
22
.env.*
3+
!.env.example
34
.venv
45

56
.pytest_cache

README.md

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@ uv add 'stackone-ai[mcp,examples]'
5252
## Quick Start
5353

5454
```python
55+
import os
5556
from stackone_ai import StackOneToolSet
5657

57-
# Initialize with API key
58-
toolset = StackOneToolSet() # Uses STACKONE_API_KEY env var
59-
# Or explicitly: toolset = StackOneToolSet(api_key="your-api-key")
58+
# Initialize — reads STACKONE_API_KEY from environment
59+
toolset = StackOneToolSet()
6060

61-
# Get HRIS-related tools with glob patterns
62-
tools = toolset.fetch_tools(actions=["bamboohr_*"], account_ids=["your-account-id"])
61+
# Fetch tools — pass account ID from STACKONE_ACCOUNT_ID env var
62+
account_id = os.getenv("STACKONE_ACCOUNT_ID")
63+
tools = toolset.fetch_tools(actions=["workday_*"], account_ids=[account_id])
6364

6465
# Use a specific tool with the call method
65-
employee_tool = tools.get_tool("bamboohr_get_employee")
66+
employee_tool = tools.get_tool("workday_get_worker")
6667
# Call with keyword arguments
6768
employee = employee_tool.call(id="employee-id")
6869
# Or with traditional execute method
@@ -86,7 +87,7 @@ toolset = StackOneToolSet()
8687
tools = toolset.fetch_tools(account_ids=["acc-123", "acc-456"])
8788

8889
# Filter by providers (case-insensitive)
89-
tools = toolset.fetch_tools(providers=["hibob", "bamboohr"])
90+
tools = toolset.fetch_tools(providers=["hibob", "workday"])
9091

9192
# Filter by action patterns with glob support
9293
tools = toolset.fetch_tools(actions=["*_list_employees"])
@@ -106,11 +107,11 @@ tools = toolset.fetch_tools(providers=["hibob"])
106107
**Filtering Options:**
107108

108109
- **`account_ids`**: Filter tools by account IDs. Tools will be loaded for each specified account.
109-
- **`providers`**: Filter by provider names (e.g., `["hibob", "bamboohr"]`). Case-insensitive matching.
110+
- **`providers`**: Filter by provider names (e.g., `["hibob", "workday"]`). Case-insensitive matching.
110111
- **`actions`**: Filter by action patterns with glob support:
111-
- Exact match: `["bamboohr_list_employees"]`
112+
- Exact match: `["workday_list_workers"]`
112113
- Glob pattern: `["*_list_employees"]` matches all tools ending with `_list_employees`
113-
- Provider prefix: `["bamboohr_*"]` matches all BambooHR tools
114+
- Provider prefix: `["workday_*"]` matches all Workday tools
114115

115116
## Implicit Feedback (Beta)
116117

@@ -165,12 +166,14 @@ When two calls for the same session happen within a few seconds, the SDK emits a
165166
StackOne tools work seamlessly with LangChain, enabling powerful AI agent workflows:
166167

167168
```python
169+
import os
168170
from langchain_openai import ChatOpenAI
169171
from stackone_ai import StackOneToolSet
170172

171173
# Initialize StackOne tools
172174
toolset = StackOneToolSet()
173-
tools = toolset.fetch_tools(actions=["bamboohr_*"], account_ids=["your-account-id"])
175+
account_id = os.getenv("STACKONE_ACCOUNT_ID")
176+
tools = toolset.fetch_tools(actions=["workday_*"], account_ids=[account_id])
174177

175178
# Convert to LangChain format
176179
langchain_tools = tools.to_langchain()
@@ -204,6 +207,7 @@ pip install langgraph langchain-openai
204207
```
205208

206209
```python
210+
import os
207211
from langchain_openai import ChatOpenAI
208212
from typing import Annotated
209213
from typing_extensions import TypedDict
@@ -217,7 +221,8 @@ from stackone_ai.integrations.langgraph import to_tool_node, bind_model_with_too
217221

218222
# Prepare tools
219223
toolset = StackOneToolSet()
220-
tools = toolset.fetch_tools(actions=["bamboohr_*"], account_ids=["your-account-id"])
224+
account_id = os.getenv("STACKONE_ACCOUNT_ID")
225+
tools = toolset.fetch_tools(actions=["workday_*"], account_ids=[account_id])
221226
langchain_tools = tools.to_langchain()
222227

223228
class State(TypedDict):
@@ -250,12 +255,14 @@ _ = app.invoke({"messages": [("user", "Get employee with id emp123") ]})
250255
CrewAI uses LangChain tools natively, making integration seamless:
251256

252257
```python
258+
import os
253259
from crewai import Agent, Crew, Task
254260
from stackone_ai import StackOneToolSet
255261

256262
# Get tools and convert to LangChain format
257263
toolset = StackOneToolSet()
258-
tools = toolset.fetch_tools(actions=["bamboohr_*"], account_ids=["your-account-id"])
264+
account_id = os.getenv("STACKONE_ACCOUNT_ID")
265+
tools = toolset.fetch_tools(actions=["workday_*"], account_ids=[account_id])
259266
langchain_tools = tools.to_langchain()
260267

261268
# Create CrewAI agent with StackOne tools
@@ -297,7 +304,7 @@ feedback_tool = tools.get_tool("tool_feedback")
297304
result = feedback_tool.call(
298305
feedback="The HRIS tools are working great! Very fast response times.",
299306
account_id="acc_123456",
300-
tool_names=["bamboohr_list_employees", "bamboohr_get_employee"]
307+
tool_names=["workday_list_workers", "workday_get_worker"]
301308
)
302309
```
303310

@@ -313,9 +320,12 @@ Search for tools using natural language queries. Works with both semantic (cloud
313320
### Basic Usage
314321

315322
```python
323+
import os
324+
316325
# Get a callable search tool
317326
toolset = StackOneToolSet()
318-
all_tools = toolset.fetch_tools(account_ids=["your-account-id"])
327+
account_id = os.getenv("STACKONE_ACCOUNT_ID")
328+
all_tools = toolset.fetch_tools(account_ids=[account_id])
319329
search_tool = toolset.get_search_tool()
320330

321331
# Search for relevant tools — returns a Tools collection
@@ -327,15 +337,17 @@ tools[0](limit=10)
327337

328338
## Semantic Search
329339

330-
Discover tools using natural language instead of exact names. Queries like "onboard new hire" resolve to the right actions even when the tool is called `bamboohr_create_employee`.
340+
Discover tools using natural language instead of exact names. Queries like "onboard new hire" resolve to the right actions even when the tool is called `workday_create_employee`.
331341

332342
```python
343+
import os
333344
from stackone_ai import StackOneToolSet
334345

335346
toolset = StackOneToolSet()
336347

337348
# Search by intent — returns Tools collection ready for any framework
338-
tools = toolset.search_tools("manage employee records", account_ids=["your-account-id"], top_k=5)
349+
account_id = os.getenv("STACKONE_ACCOUNT_ID")
350+
tools = toolset.search_tools("manage employee records", account_ids=[account_id], top_k=5)
339351
openai_tools = tools.to_openai()
340352

341353
# Lightweight: inspect results without fetching full tool definitions
@@ -357,19 +369,31 @@ tools = toolset.search_tools("manage employees", search="semantic")
357369
tools = toolset.search_tools("manage employees", search="local")
358370
```
359371

360-
Results are automatically scoped to connectors in your linked accounts. See [Semantic Search Example](examples/semantic_search_example.py) for `SearchTool` (`get_search_tool`) integration, OpenAI, and LangChain patterns.
372+
Results are automatically scoped to connectors in your linked accounts. See [Search Tools Example](examples/search_tools.py) for `SearchTool` (`get_search_tool`) integration, OpenAI, and LangChain patterns.
361373

362374
## Examples
363375

364376
For more examples, check out the [examples/](examples/) directory:
365377

366-
- [StackOne Account IDs](examples/stackone_account_ids.py)
367-
- [File Uploads](examples/file_uploads.py)
368-
- [OpenAI Integration](examples/openai_integration.py)
369-
- [LangChain Integration](examples/langchain_integration.py)
370-
- [CrewAI Integration](examples/crewai_integration.py)
371-
- [Search Tool](examples/search_tool_example.py)
372-
- [Semantic Search](examples/semantic_search_example.py)
378+
- [OpenAI Integration](examples/openai_integration.py) — OpenAI function calling
379+
- [LangChain Integration](examples/langchain_integration.py) — LangChain tools
380+
- [CrewAI Integration](examples/crewai_integration.py) — CrewAI agent
381+
- [Search Tools](examples/search_tools.py) — Tool discovery (semantic, local, auto search)
382+
- [Auth Management](examples/auth_management.py) — API key and account ID patterns
383+
384+
### Running Examples
385+
386+
```bash
387+
# 1. Set up credentials
388+
cp .env.example .env
389+
# Edit .env with your API keys
390+
391+
# 2. Install dependencies
392+
uv sync --all-extras
393+
394+
# 3. Run any example
395+
uv run examples/search_tools.py
396+
```
373397

374398
## Development
375399

examples/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# StackOne AI SDK Examples
2+
3+
## Setup
4+
5+
Install dependencies:
6+
7+
```bash
8+
uv sync --all-extras
9+
```
10+
11+
Set your credentials using either approach:
12+
13+
**Option A: Environment variables (shell)**
14+
15+
```bash
16+
export STACKONE_API_KEY=your-stackone-api-key
17+
export STACKONE_ACCOUNT_ID=your-account-id
18+
export OPENAI_API_KEY=your-openai-api-key # for OpenAI/LangChain/CrewAI examples
19+
```
20+
21+
**Option B: `.env` file**
22+
23+
```bash
24+
cp .env.example .env
25+
# Edit .env with your keys
26+
```
27+
28+
## Running Examples
29+
30+
```bash
31+
uv run examples/search_tools.py
32+
```
33+
34+
Test all examples (no API keys needed):
35+
36+
```bash
37+
uv run pytest examples
38+
```
39+
40+
## Examples
41+
42+
| File | Description |
43+
|------|-------------|
44+
| `openai_integration.py` | OpenAI function calling with Workday tools |
45+
| `langchain_integration.py` | LangChain tools integration |
46+
| `crewai_integration.py` | CrewAI agent with Workday tools |
47+
| `search_tools.py` | Tool discovery: direct fetch, semantic/local/auto search, search & execute |
48+
| `auth_management.py` | API key and account ID configuration patterns |
49+
50+
## Environment Variables
51+
52+
See `.env.example` in the project root for all required variables.

0 commit comments

Comments
 (0)