StackOne tools integrate seamlessly with OpenAI’s function calling to build AI agents that can access business data.

Overview

  • Convert tools to OpenAI function schemas automatically
  • Execute functions with built-in handling
  • Build agents with conversational context
  • Multi-step workflows for complex tasks
import OpenAI from 'openai';
import { StackOneToolSet } from '@stackone/ai';

// Initialize clients
const openai = new OpenAI();
const toolset = new StackOneToolSet();

// Get StackOne tools and convert to OpenAI format
const tools = toolset.getStackOneTools('hris_get_*', accountId);
const openAITools = tools.toOpenAI();

// Create completion with function calling
const completion = await openai.chat.completions.create({
  model: 'gpt-4',
  messages: [
    {
      role: 'system',
      content: 'You are an HR assistant with access to employee data.'
    },
    {
      role: 'user',
      content: 'How many employees do we have?'
    }
  ],
  tools: openAITools,
  tool_choice: 'auto'
});

// Execute any tool calls
const message = completion.choices[0].message;
if (message.tool_calls) {
  for (const toolCall of message.tool_calls) {
    const tool = tools.getTool(toolCall.function.name);
    if (tool) {
      const result = await tool.execute(
        JSON.parse(toolCall.function.arguments)
      );
      console.log('Result:', result.data);
    }
  }
}

Complete Examples

GitHub Examples: For complete implementations including error handling, streaming, and conversational agents:→ View OpenAI Integration ExamplesFor OpenAI function calling patterns and best practices, see the OpenAI documentation.