Knit LangGraph SDK Guide
Currently in Beta
Welcome to the Knit's LangGraph SDK, a powerful toolkit designed to integrate AI-powered agents built using LangGraph with a wide range of SaaS applications.
As an embedded integration platform, Knit provides a white-labeled solution empowering SaaS companies to effortlessly scale integrations within their own products, enriching customer experiences with dynamic, out-of-the-box functionality.
The Knit LangGraph SDK is designed to facilitate seamless integration between LLM agents and SaaS applications by leveraging Knit's platform and its wide range of connectors.
Installation
Kickstart your journey with the Knit LangGraph SDK by installing it via pip:
pip install knit-langgraph
Quick Start
First, get your Knit API Key by signing up at https://dashboard.getknit.dev/signup
Now, we're ready to start using the SDK. Here's a simple guide to help you start integrating with the Knit LangGraph SDK:
import logging
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from knit_langgraph import KnitLangGraph, ToolFilter
# Initialize the Knit SDK with your API key
knit = KnitLangGraph(api_key="YOUR_KNIT_API_KEY")
# Initialize your LLM
model = ChatOpenAI(
api_key="YOUR_OPENAI_API_KEY",
model="gpt-4o", # or another model of your choice
temperature=0,
)
# Discover available tools from a specific app.
# You can then select which tools to pass to the LLM model from these
tools = knit.find_tools(app_id="charliehr")
# Get specific tools you want to pass to the LLM model.
tool_defs = knit.get_tools(tools=[ToolFilter(app_id="charliehr", tool_ids=[tool.tool_id for tool in tools])])
# Create a ReAct agent with the tools
graph = create_react_agent(model, tools=tool_defs)
# Prepare inputs for the agent
inputs = {
"messages": [
(
"user",
"I want to get the list of offices of the company.",
)
]
}
# Configuration with integration ID
config = {"knit_integration_id": "YOUR_USER's_INTEGRATION_ID"}
# Stream the agent's responses
for response in graph.stream(inputs, {"configurable": config}, stream_mode="values"):
message = response["messages"][-1]
if isinstance(message, tuple):
print(message)
else:
message.pretty_print()
That's it! It's that easy to get started and add hundreds of SaaS applications to your AI Agent.
How to use Tools
After discovering tools using find_tools
, use get_tools
to fetch the actual tool definitions that will be passed to your LLM model. This function converts the tool summaries into usable tool objects that your LangGraph agents can interact with.
-
Find Tools First: Typically, you'll first use
find_tools
to discover available tools. -
Create Tool Filters: Use the
ToolFilter
class to specify which tools you want to retrieve. -
Call
get_tools
: Pass your filters to retrieve the actual tool definitions. -
Use with Your LLM Agent: These tool definitions can be directly passed to your LangGraph agent.
Let's break each step down:
Discover Tools for an App or Unified Tools for a Category
You can discover and filter tools on the basis of the App ID, Category ID, Entities, Operation, or Usecase. To read more about it in depth, refer to the detailed guide here
The find_tools
function in the Knit LangGraph SDK allows you to discover tools that are available for integration with a specific app.
The function will return a list of tools. You can then select and use these tools in your AI agents.
Here's a quick example to demonstrate how you can use the find_tools
function:
# You can discover and filter tools on the basis of the App ID, Category ID, Entities, Operation, or
# Usecase. To read more about it in depth, refer to the detailed guide:
# https://developers.getknit.dev/docs/find-and-discover-tools-langgraph
from knit_langgraph import KnitLangGraph
# Initialize the Knit SDK with your API key
knit = KnitLangGraph(api_key="YOUR_KNIT_API_KEY")
# Find tools related to a specific app and operation
tools = knit.find_tools(app_id="charliehr", operation="read", usecase="I want to fetch the list of employees")
# Display tool information
for tool in tools:
print(f"Tool ID: {tool.tool_id}")
print(f"Title: {tool.title}")
print(f"Description: {tool.description}")
To read more about it in depth, refer to the detailed guide here
Get Tools and Use with Your LLM Agent
The get_tools
function in the Knit LangGraph SDK allows you to retrieve specific tools based on your filtering criteria. This guide explains how to use this function to fetch the exact tools you need for your LLM agent integrations.
The function returns a list of tool definitions that can be directly used with LangGraph agents. These are fully functional tool objects that your LLM can use to interact with external applications.
Here's a quick example to demonstrate how you can use the get_tools
function:
from knit_langgraph import KnitLangGraph, ToolFilter
# Initialize the Knit SDK with your API key
knit = KnitLangGraph(api_key="YOUR_KNIT_API_KEY")
# First, discover available tools
discovered_tools = knit.find_tools(app_id="charliehr")
# Create a filter to get specific tools
tool_filter = ToolFilter(
app_id="charliehr",
tool_ids=[tool.tool_id for tool in discovered_tools[:3]] # Get the first 3 tools
)
# Get the actual tool definitions
tool_definitions = knit.get_tools(tools=[tool_filter])
# These tool definitions can now be passed to your LLM agent
# For example:
# graph = create_react_agent(model, tools=tool_definitions)
To read more about it in depth, refer to the detailed guide here
That's it! With just a few lines of code, you've unlocked the ability to add hundreds of SaaS integrations to your AI agents. The possibilities are endless - from automating workflows across multiple platforms to creating seamless experiences for your users.
We can't wait to see what you build with the Knit LangGraph SDK! 🚀 As you explore and create, remember we're here to help - reach out anytime at [email protected].
Updated 2 days ago