커스텀 플러그인

에이전트를 위한 도구가 포함된 커스텀 플러그인을 만들고 등록합니다.

빠른 시작#

전체 예제 클론하기#

가장 쉬운 시작 방법은 전체 예제 저장소를 클론하는 것입니다:

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

또는 패키지만 설치하기#

처음부터 직접 구축하려면:

bash
npm install @astreus-ai/astreus

환경 설정#

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

커스텀 날씨 플러그인#

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

// 커스텀 도구 정의
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) => {
    // 날씨 API 호출 시뮬레이션
    const weather = {
      temperature: 22,
      conditions: 'sunny',
      location: params.location as string
    };

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

// 플러그인 생성
const weatherPlugin: PluginDefinition = {
  name: 'weather-plugin',
  version: '1.0.0',
  description: 'Weather information tools',
  tools: [weatherTool]
};

// 에이전트 생성 및 플러그인 등록
const agent = await Agent.create({
  name: 'WeatherAgent',
  model: 'gpt-6-astra'
});

await agent.registerPlugin(weatherPlugin);

// 대화에서 플러그인 사용
const response = await agent.ask("What's the weather like in Tokyo?");
console.log(response); // Agent automatically uses the weather tool

예제 실행하기#

저장소를 클론했다면:

bash
npm run dev

처음부터 구축했다면, 위 코드로 index.ts 파일을 만들고 다음을 실행하세요:

bash
npx tsx index.ts

저장소#

전체 예제는 GitHub에서 확인할 수 있습니다: examples/custom-plugins