SmythOS SDK
    Preparing search index...

    SmythOS SDK

    Welcome to the SmythOS SDK! This powerful toolkit allows you to build, manage, and deploy sophisticated AI agents with ease. Whether you're creating a simple chatbot or a complex multi-agent system, the SmythOS SDK provides the tools you need to bring your ideas to life.

    The SDK is a lightweight wrapper around the Smyth Runtime Environment. It lets you create and run agents with minimal setup while still allowing advanced customisation when needed.

    • Fluent Agent API: A clean and intuitive API for creating and interacting with agents.
    • Extensible Skills: Easily add new capabilities to your agents, from calling APIs to running custom code.
    • Streaming Support: Get real-time responses from your agents for dynamic and interactive experiences.
    • Integrated AI Components: Seamlessly connect to LLMs, Vector Databases, and Storage solutions.
    • Agent Serialization: Save and load your agent's state, including skills and memory.
    • Team Management: Orchestrate multiple agents to work together in teams.
    • Document Parsing: Built-in support for parsing various document types like PDF, DOCX, and Markdown.

    Let's build your first agent in just a few lines of code. This example creates a simple agent that can fetch cryptocurrency prices.

    The easiest way to get started is by using the scaffolding command from the SmythOS CLI.

    Install the cli using your preferred package manager

    # install the cli using your preferred package manager
    npm i -g @smythos/cli

    this will install "sre" command in your system.

    Create a new project

    Run the following command, and follow the instructions to create a new project.

    sre create "My Awesome Agent"
    

    Select Empty Project template when asked.

    Edit index.ts file and add the following code:

    import { Agent } from '@smythos/sdk';

    async function main() {
    // Create a new agent
    const agent = new Agent({
    name: 'Book Assistant',
    model: 'gpt-4o',
    behavior: 'You are a helpful assistant that can answer questions about the books.',
    });

    // Add a skill to the agent that uses the openlibrary api to get information about a book
    agent.addSkill({
    name: 'get_book_info',
    description: 'Use this skill to get information about a book',
    process: async ({ book_name }) => {
    const url = `https://openlibrary.org/search.json?q=${book_name}`;

    const response = await fetch(url);
    const data = await response.json();

    return data.docs[0];
    },
    });

    // Prompt the agent and let it use the skill
    const promptResult = await agent.prompt('What is the author of the book "The Great Gatsby" ?');

    //get the result
    console.log(promptResult);
    }

    main();

    first you need to build the project

    npm run build
    

    then you can run the agent

    npm start
    

    You should see your agent respond with the author of the book "The Great Gatsby"!

    If you face any issues with the CLI or the code, set environment variable LOG_LEVEL="debug" and run your code again. Then share the logs with us, it will help diagnose the problem. You can request help on our Discord or by creating an issue on GitHub

    The Agent is the fundamental building block of the SmythOS SDK. It encapsulates a model, a set of behaviors, and a collection of skills. You can interact with an agent by sending it prompts.

    import { Agent } from '@smythos/sdk';

    const agent = new Agent({
    name: 'Book Assistant',
    model: 'gpt-4o',
    behavior: 'You are a helpful assistant that can answer questions about the books.',
    });

    The prompt() method is the primary way to interact with an agent. It returns a special AgentCommand object which can be awaited directly for a simple response, or used to stream the response for real-time applications.

    Promise-based response:

    const response = await agent.prompt('What is the author of the book "The Great Gatsby" ?');
    console.log(response);

    Streaming response:

    const stream = await agent.prompt('Tell me a story.').stream();
    stream.on(TLLMEvent.Content, (chunk) => process.stdout.write(chunk));

    //other events are available
    //TLLMEvent.Content : Generated response chunks
    //TLLMEvent.Thinking : Thinking blocks/chunks
    //TLLMEvent.End : End of the response
    //TLLMEvent.Error : Error
    //TLLMEvent.ToolInfo : Tool information : emitted by the LLM determines the next tool call
    //TLLMEvent.ToolCall : Tool call : emitted before the tool call
    //TLLMEvent.ToolResult : Tool result : emitted after the tool call
    //TLLMEvent.Usage : Tokens usage information
    //TLLMEvent.Interrupted : Interrupted : emitted when the response is interrupted before completion

    Skills are functions that you can add to your agent to extend its capabilities. The agent's LLM can intelligently decide which skill to use based on the user's prompt.

    A code skill, is a skill where the logic is defined in the skill "process" function. This is the classic way of implementing skills via SDK

    agent.addSkill({
    name: 'calculator',
    description: 'Perform mathematical calculations.',
    process: async ({ operation, a, b }) => {
    if (operation === 'add') return a + b;
    if (operation === 'subtract') return a - b;
    // ...
    },
    });

    A workflow skill, is a skill where the logic is defined in a workflow. This is the internal mode used by the visual designer, but can also be implemented programmatically. (Will be covered in a separate documentation)

    You can also call a skill directly using agent.call():

    const sum = await agent.call('calculator', { operation: 'add', a: 5, b: 3 });
    console.log(sum); // 8

    For a detailed breakdown of all classes and methods, please refer to our full API documentation.

    We welcome contributions! Please see our Contributing Guide for more details.