builder / lib /llm /agent.ts
Leon4gr45's picture
Upload folder using huggingface_hub (part 2)
391c43e verified
Raw
History Blame Contribute Delete
2.54 kB
/**
* Agent System - Defines different agent types and their capabilities
*/
export type AgentType = 'orchestrator' | 'explore' | 'task' | 'plan' | 'setup' | 'interview';
interface AgentConfig {
type: AgentType;
tools: string[]; // Tool IDs from registry
maxIterations: number;
isReadOnly?: boolean; // If true, only allow read operations
writeScope?: string; // If set, writes are restricted to this directory prefix (reads unrestricted)
}
/**
* Agent class - Represents a specialized AI agent with specific capabilities
*/
export class Agent {
public readonly type: AgentType;
public readonly tools: string[];
public readonly maxIterations: number;
public readonly isReadOnly: boolean;
public readonly writeScope?: string;
constructor(config: AgentConfig) {
this.type = config.type;
this.tools = config.tools;
this.maxIterations = config.maxIterations;
this.isReadOnly = config.isReadOnly ?? false;
this.writeScope = config.writeScope;
}
/**
* Check if this agent has access to a specific tool
*/
hasTool(toolId: string): boolean {
return this.tools.includes(toolId);
}
}
/**
* Agent Registry - Manages available agent types
*/
export class AgentRegistry {
private agents: Map<AgentType, Agent> = new Map();
constructor() {
this.registerBuiltInAgents();
}
/**
* Register all built-in agent types
*/
private registerBuiltInAgents(): void {
this.register(new Agent({
type: 'orchestrator',
tools: ['bash'],
maxIterations: 100
}));
this.register(new Agent({
type: 'explore',
tools: ['bash'],
maxIterations: 5,
isReadOnly: true
}));
this.register(new Agent({
type: 'task',
tools: ['bash'],
maxIterations: 30
}));
this.register(new Agent({
type: 'plan',
tools: ['bash'],
maxIterations: 10,
isReadOnly: true
}));
this.register(new Agent({
type: 'setup',
tools: ['bash'],
maxIterations: 20
}));
// Interview agent: reads the project freely, writes only into /.interviews/
// (enforced by writeScope).
this.register(new Agent({
type: 'interview',
tools: ['bash'],
maxIterations: 30,
writeScope: '/.interviews/',
}));
}
private register(agent: Agent): void {
this.agents.set(agent.type, agent);
}
get(type: AgentType): Agent | undefined {
return this.agents.get(type);
}
}
// Singleton instance
export const agentRegistry = new AgentRegistry();