Benutzerdefinierte Plugins

Benutzerdefinierte Plugins mit Tools für Agenten erstellen und registrieren.

Schnellstart#

Das vollständige Beispiel klonen#

Der einfachste Weg zum Start ist das Klonen des vollständigen Beispiel-Repositorys:

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

Oder nur das Paket installieren#

Wenn du lieber von Grund auf neu aufbauen möchtest:

bash
npm install @astreus-ai/astreus

Umgebungseinrichtung#

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

Benutzerdefiniertes Wetter-Plugin#

typescript
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-6-astra'
});

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

Das Beispiel ausführen#

Falls du das Repository geklont hast:

bash
npm run dev

Falls du von Grund auf neu aufgebaut hast, erstelle eine index.ts-Datei mit dem obigen Code und führe aus:

bash
npx tsx index.ts

Repository#

Das vollständige Beispiel ist auf GitHub verfügbar: examples/custom-plugins