Skip to main content

Documentation Index

Fetch the complete documentation index at: https://0g.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Quickstart

Get started with the Nebula SDK in just a few minutes.

Installation

npm install nebula-sdk

Basic Setup

First, import and initialize the SDK:
import { createAgent } from '@src/index';

// Create a pre-configured agent with 0G network
const agent = await createAgent({
  name: 'My Assistant',
  providerAddress: '0xf07240Efa67755B5311bc75784a061eDB47165Dd', // llama-3.3-70b-instruct
  memoryBucket: 'my-agent-memory',
  privateKey: 'your-private-key'
});

Your First Chat

Create a simple chat interaction:
async function basicChat() {
  // Set system prompt for the agent
  agent.setSystemPrompt('You are a helpful AI assistant.');
  
  const response = await agent.ask('Hello, how can you help me today?');
  console.log(response);
}

basicChat();

Streaming Chat

For real-time responses, use streaming:
async function streamingChat() {
  agent.setSystemPrompt('You are a creative storyteller.');
  
  const response = await agent.streamChat(
    'Tell me a story about AI',
    (chunk) => {
      process.stdout.write(chunk);
    }
  );
  
  console.log('\nComplete story:', response);
}

streamingChat();

Adding Memory

Enhance your chat with persistent memory:
async function chatWithMemory() {
  // Store user preferences in persistent memory
  await agent.remember('user_preferences', {
    language: 'English',
    tone: 'friendly'
  });
  
  // The agent automatically uses memory context in conversations
  const response = await agent.chatWithContext(
    'Remember my preferences and help me with a coding question'
  );
  
  console.log(response);
}

chatWithMemory();

Creating an Agent

Build an autonomous agent with tools:
// Agents in 0G AI SDK are conversation-based with persistent memory
async function runAgent() {
  // Set up the agent's behavior
  agent.setSystemPrompt(`You are a helpful assistant. When users ask for the time, 
                         tell them the current time is ${new Date().toISOString()}`);
  
  const response = await agent.chatWithContext('What time is it?');
  console.log(response);
  
  // Save the conversation for future reference
  const conversationId = await agent.saveConversation();
  console.log('Conversation saved with ID:', conversationId);
}

runAgent();

Next Steps

Now that you have the basics down, explore more advanced features:

Chat API

Learn about advanced chat features and configuration

Memory System

Dive deep into memory storage and retrieval

Agent Framework

Build sophisticated AI agents with custom tools

Storage Integration

Use decentralized storage for your data

Examples

Check out complete examples in our GitHub repository: