-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlangchain_integration.py
More file actions
51 lines (37 loc) · 1.58 KB
/
langchain_integration.py
File metadata and controls
51 lines (37 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
This example demonstrates how to use StackOne tools with LangChain.
```bash
uv run examples/langchain_integration.py
```
"""
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from stackone_ai import StackOneToolSet
load_dotenv()
account_id = "45072196112816593343"
employee_id = "c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA"
def langchain_integration() -> None:
toolset = StackOneToolSet()
tools = toolset.fetch_tools(actions=["bamboohr_*"], account_ids=[account_id])
# Convert to LangChain format and verify
langchain_tools = tools.to_langchain()
assert len(langchain_tools) > 0, "Expected at least one LangChain tool"
# Verify tool structure
for tool in langchain_tools:
assert hasattr(tool, "name"), "Expected tool to have name"
assert hasattr(tool, "description"), "Expected tool to have description"
assert hasattr(tool, "_run"), "Expected tool to have _run method"
assert hasattr(tool, "args_schema"), "Expected tool to have args_schema"
# Create model with tools
model = ChatOpenAI(model="gpt-5.4")
model_with_tools = model.bind_tools(langchain_tools)
result = model_with_tools.invoke(f"Can you get me information about employee with ID: {employee_id}?")
assert result.tool_calls is not None
for tool_call in result.tool_calls:
tool = tools.get_tool(tool_call["name"])
if tool:
result = tool.execute(tool_call["args"])
assert result is not None
assert result.get("data") is not None
if __name__ == "__main__":
langchain_integration()