UNPKG

abyss-ai

Version:

Autonomous AI coding agent - enhanced OpenCode with autonomous capabilities

110 lines (94 loc) 2.96 kB
// Agent Generation and Management System - Integrated with OpenCode's config system import { Config } from "../config/config" import { App } from "../app/app" export namespace Agent { export interface GenerateParams { description: string } export interface GeneratedAgent { identifier: string whenToUse: string systemPrompt: string } export interface AgentInfo { name: string description: string model?: { modelID: string; providerID: string } prompt: string tools: Record<string, boolean> temperature?: number disable?: boolean } export async function generate(params: GenerateParams): Promise<GeneratedAgent> { // Simple agent generation based on description const identifier = generateIdentifier(params.description) const whenToUse = `Use this agent when: ${params.description}` const systemPrompt = generateSystemPrompt(params.description) return { identifier, whenToUse, systemPrompt } } export async function list(): Promise<AgentInfo[]> { try { const config = await Config.state() const agents: AgentInfo[] = [] if (config.agent) { for (const [name, agentConfig] of Object.entries(config.agent)) { agents.push({ name, description: agentConfig.description, model: agentConfig.model, prompt: agentConfig.prompt || '', tools: agentConfig.tools || {}, temperature: agentConfig.temperature, disable: agentConfig.disable }) } } return agents } catch (error) { console.warn('Failed to load agents from config:', error) return [] } } export async function get(name: string): Promise<AgentInfo | null> { try { const config = await Config.state() const agentConfig = config.agent?.[name] if (!agentConfig) { return null } return { name, description: agentConfig.description, model: agentConfig.model, prompt: agentConfig.prompt || '', tools: agentConfig.tools || {}, temperature: agentConfig.temperature, disable: agentConfig.disable } } catch (error) { console.warn(`Failed to load agent '${name}':`, error) return null } } function generateIdentifier(description: string): string { // Generate a simple identifier from description return description .toLowerCase() .replace(/[^a-z0-9\s]/g, '') .replace(/\s+/g, '-') .substring(0, 30) } function generateSystemPrompt(description: string): string { return `You are an AI agent designed to help with: ${description} Your primary responsibilities: - ${description} - Provide clear and helpful responses - Follow best practices - Be accurate and reliable Always be helpful, informative, and professional in your responses.` } }