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:
git clone https://github.com/astreus-ai/examples
cd examples/custom-plugins
npm installOu Instalar Apenas o Pacote#
Se preferir construir do zero:
npm install @astreus-ai/astreusConfiguração do Ambiente#
# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.dbPlugin Personalizado de Clima#
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 toolExecutando o Exemplo#
Se você clonou o repositório:
npm run devSe você construiu do zero, crie um arquivo index.ts com o código acima e execute:
npx tsx index.tsRepositório#
O exemplo completo está disponível no GitHub: examples/custom-plugins