插件SDK

使用我们全面的SDK为Adverant Nexus构建强大的插件

安装

TypeScript/JavaScript

npm install @adverant-nexus/sdk

SDK兼容Node.js 18+并包含TypeScript类型定义。

Python

pip install adverant-nexus-sdk

Python SDK需要Python 3.9或更高版本。

核心概念

插件架构

插件通过Model Context Protocol (MCP)扩展Nexus,提供AI代理可以发现和使用的工具、资源和提示词。

  • 工具:执行操作的函数(例如分析数据、发送邮件)
  • 资源:插件公开的数据源(例如数据库、API)
  • 提示词:常见工作流的预配置提示

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参考

创建插件服务器

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()

下一步