📒Using Dynamic Tools in Your Agents
UnifAI tools enable your agents to find and use tools dynamically. Below are code examples for initializing and using the tools. You will need an Agent API Key to use the tools, which you can get for
Initializing Tools
import { Tools } from 'unifai-sdk';
const tools = new Tools({ apiKey: 'YOUR_AGENT_API_KEY' });import unifai
tools = unifai.Tools(api_key='YOUR_AGENT_API_KEY')use unifai_sdk::tools::get_tools;
let (search_tools, call_tool) = get_tools("YOUR_AGENT_API_KEY");Integrating with LLM
You can pass the initialized tools to any OpenAI-compatible API. For LLM that are not OpenAI compatible, you can use libraries and services such as OpenRouter that gives you access to most LLMs through a single OpenAI compatible API.
const messages = [{ content: "What is trending on Google today?", role: "user" }];
while (true) {
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages,
tools: await tools.getTools(),
});
messages.push(response.choices[0].message);
const results = await tools.callTools(response.choices[0].message.tool_calls);
if (results.length === 0) break;
messages.push(...results);
}messages = [{"content": "What is trending on Google today?", "role": "user"}]
while True:
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=await tools.get_tools(),
)
messages.append(response.choices[0].message)
results = await tools.call_tools(response.choices[0].message.tool_calls)
if len(results) == 0:
break
messages.extend(results)System Prompt
Most models are good at searching and using UnifAI tools without any special instructions. But we find using a system prompt helps the model to search and use the tools more effectively.
An example system prompt:
Last updated