#tool #safe #shinkai #runner #ai #data-exchange

shinkai_tools_runner

Rust library to execute shinkai-tools in a safe and performant environment

35 releases

new 0.7.12 Sep 7, 2024
0.7.11 Sep 7, 2024
0.7.5 Aug 29, 2024
0.7.1-dev.17 Jul 27, 2024
0.0.0 Aug 23, 2024

#87 in Machine learning

Download history 758/week @ 2024-06-29 179/week @ 2024-07-06 152/week @ 2024-07-13 132/week @ 2024-07-20 117/week @ 2024-07-27 238/week @ 2024-08-03 106/week @ 2024-08-10 436/week @ 2024-08-17 603/week @ 2024-08-24 379/week @ 2024-08-31

1,639 downloads per month

Custom license

8.5MB
1K SLoC

Shinkai Tools

Mutable.ai Auto Wiki

Shinkai Tools serves as the ecosystem to execute Shinkai tools, provided by the Shinkai team or third-party developers, in a secure environment. It provides a sandboxed space for executing these tools, ensuring that they run safely and efficiently, while also allowing for seamless integration with Rust code.

This repository is a comprehensive collection of tools and utilities designed to facilitate the integration of JavaScript and Rust code. It provides a framework for executing JavaScript scripts within a Rust environment, allowing for seamless communication and data exchange between the two languages.

The primary components of this repository include:

  • apps/shinkai-tool-* These are small JavaScript tools designed to perform specific tasks. Each tool is a self-contained project with its own configuration and build process, allowing for easy maintenance and updates.
  • libs/shinkai-tools-builder is a TypeScript library that provides the necessary classes and types to build new tools, making it easier to create and integrate new tools into the Shinkai ecosystem.
  • libs/shinkai-tools-runner is a Rust library used to execute a tool in a secured and performant JavaScript environment, providing a safe and efficient way to run tools within the Shinkai ecosystem.

Documentation

General Documentation: https://docs.shinkai.com

More In Depth Codebase Documentation (Mutable.ai): https://wiki.mutable.ai/dcSpark/shinkai-tools

Getting started

Init Typescript side

# In windows admin privileges is required because rquickjs-sys uses a git patch
npm ci
npx nx run-many -t lint
npx nx run-many -t build
npx nx run-many -t test

How to use a tool from Rust side (using shinkai_tools_runner)

To execute a tool from the Rust side, you can follow these steps:

  1. First, ensure that the tool's JavaScript file is located in the correct directory as specified in the Cargo.toml file.
  2. In your Rust code, import the necessary modules and create a new instance of the Tool struct.
  3. Load the tool's JavaScript file using the load method, passing the path to the file as an argument.
  4. Once the tool is loaded, you can call its functions using the run method, passing any required arguments as JSON strings.

Here's an example:

use shinkai_tools_runner::built_in_tools::get_tool;
use shinkai_tools_runner::tools::tool::Tool;

#[tokio::main]
async fn main() {
    let tool_definition = get_tool("shinkai-tool-echo").unwrap();
    let mut tool = Tool::new();
    let _ = tool
        .load_from_code(&tool_definition.code.clone().unwrap(), "")
        .await;
    let run_result = tool.run("{ \"message\": \"new york\" }").await.unwrap();
    assert_eq!(run_result.data["message"], "echoing: new york");
}

Adding a New Shinkai Tool

To add a new Shinkai tool to this project, follow these simple steps:

  1. Run the Hygen command: Run npx hygen shinkai-tool new to create a new tool. This command will guide you through the process of creating a new tool, including setting up the directory structure and generating the necessary files.

That's it! With this single command, you'll have a new Shinkai tool set up and ready to go.

Dependencies

~14–27MB
~422K SLoC