Skip to content

Commit c2dc5aa

Browse files
authored
feat: langchain tools (#2)
* feat: better docs * feat: stackone ids * feat: implement account ids * fix: error handling * fix: models, arg not defined * feat: langchain tools * fix: tools * fix: tests * fix: mypy * fix: linting gh actions * fis: env * fix: deploy docs ci * fix: ci * feat: add oas
1 parent 9186ec3 commit c2dc5aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+123025
-634
lines changed

.env_example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
STACKONE_API_KEY=your_stackone_api_key
2-
STACKONE_ACCOUNT_ID=your_stackone_account_id
32
OPENAI_API_KEY=your_openai_api_key

.github/workflows/docs.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
push:
55
branches:
66
- main
7-
pull_request:
8-
branches:
9-
- main
107

118
permissions:
129
contents: write

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
enable-cache: true
1919

2020
- name: Install dependencies
21-
run: uv sync
21+
run: uv sync --all-extras
2222

2323
- name: Run Ruff
2424
uses: astral-sh/ruff-action@v3

.github/workflows/test.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ on:
88
jobs:
99
test:
1010
runs-on: ubuntu-latest
11-
11+
env:
12+
STACKONE_API_KEY: ${{ secrets.STACKONE_API_KEY }}
13+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
1214
steps:
1315
- uses: actions/checkout@v4
1416

@@ -19,10 +21,7 @@ jobs:
1921
enable-cache: true
2022

2123
- name: Install dependencies
22-
run: uv sync
24+
run: uv sync --all-extras
2325

2426
- name: Run tests
2527
run: uv run pytest
26-
27-
- name: Run type checks
28-
run: uv run mypy packages/stackone-core/

examples/api_reference.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

examples/available_tools.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Get available tools from your StackOne organisation based on the account id.
3+
4+
```bash
5+
uv run examples/available_tools.py
6+
```
7+
"""
8+
9+
10+
# TODO: Add examples
11+
def get_available_tools():
12+
print("Getting available tools")
13+
14+
15+
if __name__ == "__main__":
16+
print(get_available_tools())

examples/basic_tool_usage.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

examples/crewai_integration.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
This example demonstrates how to use StackOne tools with CrewAI.
3+
4+
CrewAI uses LangChain tools natively.
5+
6+
```bash
7+
uv run examples/crewai_integration.py
8+
```
9+
"""
10+
11+
from crewai import Agent, Crew, Task
12+
from stackone_ai import StackOneToolSet
13+
14+
account_id = "45072196112816593343"
15+
employee_id = "c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA"
16+
17+
18+
def crewai_integration():
19+
toolset = StackOneToolSet()
20+
tools = toolset.get_tools(
21+
vertical="hris",
22+
account_id=account_id,
23+
)
24+
25+
# CrewAI uses LangChain tools natively
26+
langchain_tools = tools.to_langchain()
27+
28+
agent = Agent(
29+
role="HR Manager",
30+
goal=f"What is the employee with the id {employee_id}?",
31+
backstory="With over 10 years of experience in HR and employee management, "
32+
"you excel at finding patterns in complex datasets.",
33+
llm="gpt-4o-mini",
34+
tools=langchain_tools,
35+
max_iter=2,
36+
)
37+
38+
task = Task(
39+
description="What is the employee with the id c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA?",
40+
agent=agent,
41+
expected_output="A JSON object containing the employee's information",
42+
)
43+
44+
crew = Crew(agents=[agent], tasks=[task])
45+
print(crew.kickoff())
46+
47+
48+
if __name__ == "__main__":
49+
crewai_integration()

examples/error_handling.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,39 @@
1-
import os
2-
31
from dotenv import load_dotenv
42
from stackone_ai import StackOneToolSet
53

4+
load_dotenv()
65

7-
def demonstrate_error_handling():
8-
# Load environment variables from root .env
9-
load_dotenv()
10-
11-
api_key = os.getenv("STACKONE_API_KEY")
12-
account_id = os.getenv("STACKONE_ACCOUNT_ID")
136

14-
if not api_key:
15-
raise ValueError("STACKONE_API_KEY not found in .env file")
16-
17-
toolset = StackOneToolSet(api_key=api_key)
7+
def error_handling() -> None:
8+
toolset = StackOneToolSet()
189

1910
# Example 1: Handle unknown vertical
20-
try:
21-
tools = toolset.get_tools(vertical="unknown_vertical")
22-
print("Tools for unknown vertical:", tools) # Will print empty dict
23-
except Exception as e:
24-
print(f"Error getting tools: {e}")
11+
tools = toolset.get_tools(vertical="unknown_vertical")
12+
print("Tools for unknown vertical:", tools._tool_map)
13+
# {}
2514

2615
# Example 2: Handle API errors with account_id
27-
tools = toolset.get_tools(vertical="crm", account_id=account_id)
28-
29-
# Example of handling various API errors
16+
tools = toolset.get_tools(vertical="crm", account_id="test_id")
3017
try:
3118
# Try with invalid ID
32-
contacts_tool = tools.get_tool("get_contacts")
19+
contacts_tool = tools.get_tool("get_contact")
3320
if contacts_tool:
3421
result = contacts_tool.execute({"id": "invalid_id"})
3522
except Exception as e:
3623
print(f"API Error: {e}")
24+
# 400 Client Error: Bad Request for url: https://api.stackone.com/unified/crm/contacts/invalid_id
3725

3826
# Example 3: Handle missing account ID
39-
tools_no_account = toolset.get_tools(vertical="crm") # No account_id
27+
tools_no_account = toolset.get_tools(vertical="crm", account_id=None)
4028
try:
41-
contacts_tool = tools_no_account.get_tool("get_contacts")
42-
if contacts_tool:
43-
result = contacts_tool.execute({"id": "123"})
29+
list_contacts_tool = tools_no_account.get_tool("list_contacts")
30+
if list_contacts_tool:
31+
result = list_contacts_tool.execute()
4432
print("Result without account ID:", result)
4533
except Exception as e:
4634
print(f"Error when account ID is missing: {e}")
35+
# 501 Server Error: Not Implemented for url: https://api.stackone.com/unified/crm/contacts
4736

4837

4938
if __name__ == "__main__":
50-
demonstrate_error_handling()
39+
error_handling()

0 commit comments

Comments
 (0)