Custom Tools

Following the Function Calling schema, you can develop your own tools and functions and give your Unit access to them - as you'd do with a regular model - making the Unit forms usage memories with them.

The only actual limitation is that those tools are only in your code: outside of it, the Unit will still have memories of them but it will be impossible for it to recall the tools, leading to possible weird behavior.

Solution: Once you plug an Unit in your code, try to use it only there, especially if there it has access to specific functions not available in the Factory.

We're currently testing a couple of solutions to let users define Custom Tools directly in the factory and an update will soon come together with a Vault System where you can safely store your data and keys without compromising opsec.

Custom Tools Quickstart

const ReiCoreSdk = require('reicore-sdk');

// Initialize the SDK
const apiKey = 'your_unit_secret_token';
const reiAgent = new ReiCoreSdk({ agentSecretKey: apiKey });

// Define your custom functions
const getWeather = (location) => {
    // Implement your weather API call here
    return `Weather in ${location}: Sunny, 22°C`;
};

const searchDatabase = (query) => {
    // Implement your database search here
    return `Found 3 results for: ${query}`;
};

// Define function schemas
const functions = [
    {
        name: "get_weather",
        description: "Get the current weather for a location",
        parameters: {
            type: "object",
            properties: {
                location: {
                    type: "string",
                    description: "The city and state, e.g. San Francisco, CA"
                }
            },
            required: ["location"]
        }
    },
    {
        name: "search_database",
        description: "Search the database for specific information",
        parameters: {
            type: "object",
            properties: {
                query: {
                    type: "string",
                    description: "The search query"
                }
            },
            required: ["query"]
        }
    }
];

// Function mapping
const functionMap = {
    get_weather: getWeather,
    search_database: searchDatabase
};

async function processWithFunctions(query) {
    try {
        // First call to get function details
        const response = await reiAgent.chatCompletions(query, { functions });
        const message = response.choices[0].message;
        
        // Check if the agent wants to call a function
        if (message.function_call) {
            const functionName = message.function_call.name;
            const functionArgs = JSON.parse(message.function_call.arguments);
            
            // Call the function
            const functionResponse = functionMap[functionName](...Object.values(functionArgs));
            
            // Send the function response back to the agent
            const secondResponse = await reiAgent.chatCompletions([
                { role: "user", content: query },
                { role: "function", name: functionName, content: functionResponse }
            ], { functions });
            
            return secondResponse.choices[0].message.content;
        }
        
        return message.content;
        
    } catch (error) {
        console.error('Error:', error);
        return null;
    }
}

// Example usage
processWithFunctions("What's the weather in Tokyo?")
    .then(response => console.log(response))
    .catch(error => console.error(error));

Advanced Custom Tools

Multiple Function Calls

Function Calling with Context

Last updated