Get Tools and pass them to OpenAI Agent
The get_tools
function in the Knit OpenAI 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.
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.
Get Tools for an App
Parameters Overview
tools
: A list ofToolFilter
objects that define which tools you want to retrieve. Each filter can specify:app_id
: The application ID to fetch tools fromtool_ids
: A list of specific tool IDs to retrieve
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.
Example Usage
from openai import OpenAI
from knit_openai import KnitOpenAI, ToolFilter
# Initialize OpenAI client
client = OpenAI()
# Initialize KnitOpenAI client
knit = KnitOpenAI()
# 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
# Create an assistant with the tool definitions
assistant = client.beta.assistants.create(
instructions="You are a bot for employee data in an HRIS system. Use the provided functions to answer questions",
model="gpt-4o",
tools=tool_defs,
)
Get Unified Tools for a Category
Parameters Overview
tools
: A list ofToolFilter
objects that define which tools you want to retrieve. Each filter can specify:category_id
: A specific category of toolstool_ids
: A list of specific tool IDs to retrieve
The function returns a list of tool definitions that can be directly used with OpenAI models. These are fully functional tool objects that your LLM can use to interact with external applications.
Example Usage
from openai import OpenAI
from knit_openai import KnitOpenAI, ToolFilter
# Initialize OpenAI client
client = OpenAI()
# Initialize KnitOpenAI client
knit = KnitOpenAI()
# First, discover available tools
discovered_tools = knit.find_tools(category_id="ticketing", include_unified_tools=True)
# Create a filter to get specific tools
tool_filter = ToolFilter(
category_id="ticketing",
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:
# Create an assistant with the tool definitions
assistant = client.beta.assistants.create(
instructions="You are a bot for employee data in an HRIS system. Use the provided functions to answer questions",
model="gpt-4o",
tools=tool_defs,
)
Advanced Usage
Multiple Filters
You can combine tools from different applications - including combining app and unified tools by passing multiple filters:
# Get tools from multiple applications
salesforce_filter = ToolFilter(app_id="salesforce", tool_ids=["list_accounts", "get_contact"])
hubspot_filter = ToolFilter(app_id="hubspot", tool_ids=["create_deal"])
crm_filter = ToolFilter(category_id="crm", tool_ids=["list_accounts", "get_contact"])
ticketing_filter = ToolFilter(app_id="ticketing", tool_ids=["create_deal"])
# Combine tools from both applications
combined_tools = knit.get_tools(tools=[salesforce_filter, hubspot_filter, crm_filter, ticketing_filter])
Updated 25 days ago