SmythOS SDK
    Preparing search index...

    Using Services Directly

    Beyond the agent-centric abstractions, the SmythOS SDK provides direct access to the underlying services for Language Models (LLMs), Storage, and Vector Databases. This allows you to leverage these powerful components independently, without needing an agent instance.

    This is useful for tasks like pre-populating a vector database, managing files in your application's storage, or performing a one-off LLM completion.

    You can find working examples in scripts like 10-llm-storage-vectors.ts and upsert-and-search.ts.

    You can access LLM providers directly to perform completions or other language tasks. An LLMInstance behaves much like an agent, supporting methods like .prompt() and .stream().

    When accessed via an agent, the LLM service is already configured.

    // 'agent' is an existing Agent instance
    const openai = agent.llm.OpenAI({ model: 'gpt-4o-mini' });
    const haiku = await openai.prompt('Write a haiku about sakura trees');
    console.log(haiku);

    You can also import and use LLM providers directly from the SDK.

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

    const anthropic = LLM.Anthropic({ model: 'claude-3-haiku' });
    const response = await anthropic.prompt('Why is the sky blue?');
    console.log(response);

    The Storage service provides a convenient abstraction over file systems, whether they are local or cloud-based like S3. This allows your application to handle file operations consistently across different environments.

    An agent provides access to its configured storage providers.

    // 'agent' is an existing Agent instance
    const storage = agent.storage.LocalStorage(); // Or agent.storage.S3() etc.
    const fileUri = await storage.write('my-file.txt', 'This is some important data.');
    console.log(`File written to: ${fileUri}`);
    const content = await storage.read(fileUri);
    console.log(`File content: ${content}`);

    You can use the Storage service directly for general-purpose file management.

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

    const localStore = Storage.LocalStorage();
    await localStore.write('config.json', JSON.stringify({ setting: 'enabled' }));

    The Vector Database service is essential for managing and searching high-dimensional vector embeddings, which are the cornerstone of semantic search and long-term agent memory.

    The agent provides configured access to Vector DBs.

    // 'agent' is an existing Agent instance
    const vectra = agent.vectorDB.Vectra({ indexName: 'agent-memory' });
    await vectra.insertDoc('fact-01', 'The agent was created today.');
    const results = await vectra.search('When was the agent made?', { topK: 1 });
    console.log(results);

    You can use the Vector DB service directly to build your own search applications or data processing pipelines.

    import { VectorDB, Model } from '@smythos/sdk';

    // Initialize a standalone Pinecone vector database instance
    const pinecone = VectorDB.Pinecone({
    indexName: 'my-app-docs',
    // We also need to specify which model to use for creating embeddings
    embeddings: Model.OpenAI({ model: 'text-embedding-3-large' }),
    });

    // Add documents to the index
    console.log('Upserting documents...');
    await pinecone.insertDoc('doc-1', 'The first rule of SmythOS is to build amazing agents.');
    await pinecone.insertDoc('doc-2', 'The second rule is to be creative and have fun.');

    // Perform a semantic search
    console.log("Searching for 'rules'...");
    const searchResults = await pinecone.search('What are the rules?', { topK: 2 });
    console.log(searchResults);

    You've now covered all the core components of the SDK. For more specific use cases and advanced configurations, check out the Advanced Topics.