Frameworks → Client → TypeScript | Python (soon)
Note
This is a low-level client, you will need to handle mapping of function definitions & tool calling manually. For framework specific use, please refer to supported frameworks.
Superface SDK lets you integrate external apps with your AI agent using function calling.
This client is optimized for manual handling of tools and is framework agnostic. It allows you to fetch tool definitions, run tools, and manage user connections.
npm install superface
Obtain your agent's secret key and connect tools you want your agent to have access to in Superface dashboard.
import Superface from 'superface/client';
const superface = new Superface({
apiKey: process.env.SUPERFACE_API_KEY,
});
const tools = await superface.getTools();
const response = await callLLM({
tools: tools.map(tool => ({ ... })),
prompt: '...'
});
- Iterate through tool calls as returned from LLM
- Pass the tool call object from the LLM into
runTool()
method on Superface Client - Add the tool call response to the original chain of messages
// ...
const messages = [{ role: 'user', content: '...' } ];
const response = await callLLm({ ... });
// Handle tool calls
for (const toolCall of toolCalls) {
const toolRun = await superface.runTool({
userId: 'example_user',
name: toolCall.function.name,
args: JSON.parse(toolCall.function.arguments),
});
const toolMessage = {
role: 'tool',
content: toolRun.result || toolRun.error
}
messages.push(toolMessage);
}
const link = await superface.linkToUserConnections({ userId: 'example_user' });
redirect(link.url);
SUPERFACE_API_KEY
: This value is used to authenticate clients to the Superface API.SUPERFACE_CACHE_TIMEOUT
: Set in milliseconds to change the cache timeout for tool definitions. The default is 60000ms.SUPERFACE_MAX_RETRIES
: Maximum number of retries to communicate with Superface servers. This affectsgetTools
andrunTool
functions.
For more information, refer to the Superface Documentation.