Plugin SDK

สร้างปลั๊กอินที่ทรงพลังสำหรับ Adverant Nexus ด้วย SDK ที่ครอบคลุมของเรา

การติดตั้ง

TypeScript/JavaScript

npm install @adverant-nexus/sdk

SDK เข้ากันได้กับ Node.js 18+ และรวม TypeScript definitions

Python

pip install adverant-nexus-sdk

Python SDK ต้องการ Python 3.9 ขึ้นไป

แนวคิดหลัก

สถาปัตยกรรมปลั๊กอิน

ปลั๊กอินขยาย Nexus ผ่าน Model Context Protocol (MCP) โดยให้เครื่องมือ ทรัพยากร และ prompts ที่ AI agents สามารถค้นพบและใช้งานได้

  • Tools: ฟังก์ชันที่ดำเนินการ (เช่น วิเคราะห์ข้อมูล ส่งอีเมล)
  • Resources: แหล่งข้อมูลที่ปลั๊กอินเปิดเผย (เช่น ฐานข้อมูล APIs)
  • Prompts: prompts ที่กำหนดค่าไว้ล่วงหน้าสำหรับเวิร์กโฟลว์ทั่วไป

Nexus Client

Nexus Client ให้การเข้าถึงบริการหลักของแพลตฟอร์ม:

import { NexusClient } from '@adverant-nexus/sdk'

const nexus = new NexusClient({
  apiKey: process.env.BRAIN_API_KEY
})

// Access GraphRAG memory
await nexus.graphrag.storeMemory({
  content: 'Important information',
  tags: ['customer', 'analysis']
})

// Orchestrate sub-agents
await nexus.agents.orchestrate({
  task: 'Analyze customer feedback',
  agents: ['sentiment', 'summarization']
})

อ้างอิง API

การสร้าง Plugin Server

import { NexusPluginServer, Tool } from '@adverant-nexus/sdk/server'

const server = new NexusPluginServer({
  name: 'my-plugin',
  version: '1.0.0',
  description: 'My awesome plugin'
})

// Define a tool
server.tool(new Tool({
  name: 'analyze_data',
  description: 'Analyzes data and returns insights',
  inputSchema: {
    type: 'object',
    properties: {
      data: { type: 'array' },
      options: { type: 'object' }
    },
    required: ['data']
  },
  execute: async (input) => {
    // Your implementation
    return { insights: [...] }
  }
}))

// Start the server
await server.start()

การเข้าถึงบริการ Nexus

// GraphRAG Memory
await nexus.graphrag.storeMemory({ content, tags })
await nexus.graphrag.query({ query, limit: 10 })

// Agent Orchestration
await nexus.agents.orchestrate({ task, agents })

// Learning System
await nexus.learning.recordPattern({ pattern, feedback })

ตัวอย่าง

ตัวอย่างปลั๊กอินอย่างง่าย

ปลั๊กอินพื้นฐานที่ให้เครื่องมือทักทาย:

import { NexusPluginServer, Tool } from '@adverant-nexus/sdk/server'

const server = new NexusPluginServer({
  name: 'greeter',
  version: '1.0.0'
})

server.tool(new Tool({
  name: 'greet',
  description: 'Greets a user by name',
  inputSchema: {
    type: 'object',
    properties: {
      name: { type: 'string' }
    },
    required: ['name']
  },
  execute: async ({ name }) => {
    return { message: `Hello, ${name}!` }
  }
}))

await server.start()

ขั้นตอนถัดไป