Plugins Personalizados

Crie e registre plugins personalizados com ferramentas para agentes.

Início Rápido#

Clonar o Exemplo Completo#

A forma mais fácil de começar é clonar o repositório do exemplo completo:

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

Ou Instalar Apenas o Pacote#

Se preferir construir do zero:

bash
npm install @astreus-ai/astreus

Configuração do Ambiente#

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

Plugin Personalizado de Clima#

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

// Definir uma ferramenta personalizada
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) => {
    // Simular chamada a uma API de clima
    const weather = {
      temperature: 22,
      conditions: 'sunny',
      location: params.location as string
    };

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

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

// Criar agente e registrar o plugin
const agent = await Agent.create({
  name: 'WeatherAgent',
  model: 'gpt-6-astra'
});

await agent.registerPlugin(weatherPlugin);

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

Executando o Exemplo#

Se você clonou o repositório:

bash
npm run dev

Se você construiu do zero, crie um arquivo index.ts com o código acima e execute:

bash
npx tsx index.ts

Repositório#

O exemplo completo está disponível no GitHub: examples/custom-plugins