SDK de Plugins

Construye plugins potentes para Adverant Nexus con nuestro SDK completo

Instalación

TypeScript/JavaScript

npm install @adverant-nexus/sdk

El SDK es compatible con Node.js 18+ e incluye definiciones TypeScript.

Python

pip install adverant-nexus-sdk

El SDK de Python requiere Python 3.9 o superior.

Conceptos Fundamentales

Arquitectura de Plugins

Los plugins extienden Nexus a través del Model Context Protocol (MCP), proporcionando herramientas, recursos y prompts que los agentes de IA pueden descubrir y usar.

  • Herramientas: Funciones que realizan acciones (ej., analizar datos, enviar emails)
  • Recursos: Fuentes de datos que los plugins exponen (ej., bases de datos, APIs)
  • Prompts: Prompts pre-configurados para flujos de trabajo comunes

Cliente Nexus

El Cliente Nexus proporciona acceso a los servicios centrales de la plataforma:

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']
})

Referencia API

Crear un Servidor de Plugin

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

Acceder a Servicios de 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 })

Ejemplos

Ejemplo de Plugin Simple

Un plugin básico que proporciona una herramienta de saludo:

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

Próximos Pasos