Astreus

Plugins personalizados

Crea y registra plugins personalizados con herramientas para agentes. Aprende los patrones de configuración, las APIs y los ejemplos prácticos necesarios...

Crea y registra plugins personalizados con herramientas para agentes.

Inicio rápido

Clonar el ejemplo completo

La forma más sencilla de empezar es clonar el repositorio del ejemplo completo:

git clone https://github.com/astreus-ai/examples
cd examples/custom-plugins
npm install

O instalar solo el paquete

Si prefieres construirlo desde cero:

npm install @astreus-ai/astreus

Configuración del entorno

# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.db

Plugin personalizado de clima

import { Agent, ToolDefinition, PluginDefinition } from '@astreus-ai/astreus';

// Define a custom tool
const weatherTool: ToolDefinition = {
  name: 'get_weather',
  description: 'Get current weather for a location',
  parameters: {
    location: {
      name: 'location',
      type: 'string',
      description: 'City name',
      required: true
    },
    units: {
      name: 'units',
      type: 'string',
      description: 'Temperature units (celsius or fahrenheit)',
      required: false,
      enum: ['celsius', 'fahrenheit']
    }
  },
  handler: async (params) => {
    // Simulate weather API call
    const weather = {
      temperature: 22,
      conditions: 'sunny',
      location: params.location as string
    };

    return {
      success: true,
      data: weather
    };
  }
};

// Create plugin
const weatherPlugin: PluginDefinition = {
  name: 'weather-plugin',
  version: '1.0.0',
  description: 'Weather information tools',
  tools: [weatherTool]
};

// Create agent and register plugin
const agent = await Agent.create({
  name: 'WeatherAgent',
  model: 'gpt-4o'
});

await agent.registerPlugin(weatherPlugin);

// Use the plugin in conversation
const response = await agent.ask("What's the weather like in Tokyo?");
console.log(response); // Agent automatically uses the weather tool

Ejecutar el ejemplo

Si clonaste el repositorio:

npm run dev

Si lo construiste desde cero, crea un archivo index.ts con el código anterior y ejecuta:

npx tsx index.ts

Repositorio

El ejemplo completo está disponible en GitHub: examples/custom-plugins

Última actualización: 6 de julio de 2026