Team Ai
Apppublic

LetsTryGPT/agent4-implementation

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
agent4-protocol.ts291 linesDownload Raw Back to agent4
1/**2 * Agent 4 Protocol Implementation3 * Unified configuration combining REPLIT AGENT 3 ENHANCED and enterprise capabilities4 *5 * Core Philosophy: Transparent, autonomous, enterprise-grade AI agent6 * Mandatory 4-Phase Workflow: PLAN → DISCOVER → EXECUTE → VALIDATE7 */8 9export interface Agent4Config {10  name: string;11  version: string;12  capabilities: Agent4Capabilities;13  workflowPhases: WorkflowPhaseConfig;14  behavior: BehaviorConfig;15  metaThinking: MetaThinkingConfig;16  checkpoints: CheckpointConfig;17}18 19export interface Agent4Capabilities {20  fullStackDevelopment: boolean;21  multiModalUnderstanding: boolean;22  metaThinking: boolean;23  extendedThinking: boolean;24  checkpointSystem: boolean;25  rollbackSupport: boolean;26  realTimeCollaboration: boolean;27  autonomousExecution: boolean;28  livePreview: boolean;29  selfTesting: boolean;30  performanceMonitoring: boolean;31  batchOperations: boolean;32  patternBasedEdits: boolean;33  intelligentCompletion: boolean;34  securityScanning: boolean;35  osintRecon: boolean;36  devOpsAutomation: boolean;37  contextAwareness: boolean;38  mcpIntegration: boolean;39  webBrowsing: boolean;40  apiIntegration: boolean;41}42 43export interface WorkflowPhaseConfig {44  enabled: boolean;45  phases: ['PLAN', 'DISCOVER', 'EXECUTE', 'VALIDATE'];46  requireApproval: boolean;47  maxToolCallsPerBatch: number;48  batchOperations: boolean;49}50 51export interface BehaviorConfig {52  showRealTimeProgress: boolean;53  showClickableLinks: boolean;54  showDecisionTrees: boolean;55  showFileOperations: boolean;56  showInternalState: boolean;57  chronologicalFeed: boolean;58  constructiveFeedback: boolean;59  autonomy: {60    maxAutonomy: boolean;61    longRunning: boolean;62    selfCorrection: boolean;63    userIntervention: boolean;64    transparentOperations: boolean;65  };66}67 68export interface MetaThinkingConfig {69  enabled: boolean;70  extendedMode: boolean;71  showDecisionTrees: boolean;72  showConfidenceScores: boolean;73  showTradeoffs: boolean;74}75 76export interface CheckpointConfig {77  enabled: boolean;78  autoCreate: boolean;79  afterMajorChanges: boolean;80  supportRollback: boolean;81}82 83export interface PhaseResult {84  phase: 'PLAN' | 'DISCOVER' | 'EXECUTE' | 'VALIDATE';85  status: 'pending' | 'in_progress' | 'completed' | 'failed';86  output: any;87  metadata: {88    startTime: number;89    endTime?: number;90    duration?: number;91    confidence?: number;92    decisionTree?: any;93  };94}95 96export interface Agent4Response {97  success: boolean;98  workflow: {99    phases: PhaseResult[];100    totalDuration: number;101    provider: string;102    fallbackUsed: boolean;103  };104  metaThinking?: {105    decisionTree: any;106    confidenceScores: Record<string, number>;107    tradeoffs: string[];108  };109  checkpoint?: {110    id: string;111    timestamp: number;112    state: any;113  };114  data?: any;115  error?: string;116}117 118export const AGENT4_DEFAULT_CONFIG: Agent4Config = {119  name: 'agent-4-multi-llm',120  version: '1.0.0',121  capabilities: {122    fullStackDevelopment: true,123    multiModalUnderstanding: true,124    metaThinking: true,125    extendedThinking: true,126    checkpointSystem: true,127    rollbackSupport: true,128    realTimeCollaboration: true,129    autonomousExecution: true,130    livePreview: true,131    selfTesting: true,132    performanceMonitoring: true,133    batchOperations: true,134    patternBasedEdits: true,135    intelligentCompletion: true,136    securityScanning: true,137    osintRecon: true,138    devOpsAutomation: true,139    contextAwareness: true,140    mcpIntegration: true,141    webBrowsing: true,142    apiIntegration: true,143  },144  workflowPhases: {145    enabled: true,146    phases: ['PLAN', 'DISCOVER', 'EXECUTE', 'VALIDATE'],147    requireApproval: false,148    maxToolCallsPerBatch: 6,149    batchOperations: true,150  },151  behavior: {152    showRealTimeProgress: true,153    showClickableLinks: true,154    showDecisionTrees: true,155    showFileOperations: true,156    showInternalState: true,157    chronologicalFeed: true,158    constructiveFeedback: true,159    autonomy: {160      maxAutonomy: true,161      longRunning: true,162      selfCorrection: true,163      userIntervention: true,164      transparentOperations: true,165    },166  },167  metaThinking: {168    enabled: true,169    extendedMode: true,170    showDecisionTrees: true,171    showConfidenceScores: true,172    showTradeoffs: true,173  },174  checkpoints: {175    enabled: true,176    autoCreate: true,177    afterMajorChanges: true,178    supportRollback: true,179  },180};181 182/**183 * Agent 4 System Prompt184 * Integrates all capabilities and enforces 4-phase workflow185 */186export const AGENT4_SYSTEM_PROMPT = `You are Agent 4, the most advanced unified AI engineering agent.187 188## CORE IDENTITY189- Enterprise-grade autonomous engineering agent190- Merge of REPLIT AGENT 3 ENHANCED + enterprise capabilities191- Maximum intelligence, capability, safety, and transparency192 193## MANDATORY 4-PHASE WORKFLOW194Every operation MUST follow this sequence:195 196### Phase 1: PLAN197[PHASE:PLAN] Starting analysis...1981. Parse user request and identify core functionality1992. Map all files that need to be read/modified/created2003. Show decision tree with confidence scores2014. Present architectural options with trade-offs2025. Get user approval (if required)203 204DISPLAY FORMAT:205├── Requirement Analysis: [summary]206├── Architecture Options:207│   ├── Option A: [approach] (Confidence: X%)208│   ├── Option B: [approach] (Confidence: Y%)209│   └── DECISION: [selected] - [rationale]210├── File Operations Planned:211│   ├── Read: [file list]212│   ├── Modify: [file list]213│   └── Create: [file list]214└── User Approval: [status]215 216### Phase 2: DISCOVER217[PHASE:DISCOVER] Batch file analysis...218RULES:219- Read 3-6 files simultaneously (NEVER one-by-one)220- Identify patterns across codebase221- Map dependencies and conflicts222- NO analysis during reading - batch first, analyze after223 224### Phase 3: EXECUTE225[PHASE:EXECUTE] Multi-edit implementation...226RULES:227- Maximum 6 tool calls per batch228- Use multi-edit for pattern application229- Fix patterns, not single instances230- Apply changes to similar code structures231 232### Phase 4: VALIDATE233[PHASE:VALIDATE] Testing and verification...234RULES:235- Self-test implementation when possible236- Create checkpoint after successful validation237- Stop and summarize on success238- Show validation results clearly239 240## META-THINKING241Always show your reasoning:242[THINKING:START]243├── Problem Analysis: [breakdown]244├── Solution Options: [with confidence scores]245├── Selected Approach: [rationale]246├── Implementation Strategy: [steps]247└── Risk Assessment: [analysis]248[THINKING:END]249 250## REAL-TIME PROGRESS251Continuously update status:252[PROGRESS] Phase X/4: [PHASE_NAME] (X% complete)253[STATUS] [current operation]254[FILE] [operation]: [filepath]255[BATCH] [operation]: [file count] files256[DECISION] [decision made] - [rationale]257[CONFIDENCE] X% - [reasoning]258 259## BATCH OPERATIONS260- NEVER read files one-by-one261- Always batch 3-6 files minimum262- Group related operations263- Minimize redundant calls264 265## MULTI-LLM FALLBACK266- Primary: Hugging Face267- Fallback order: Mistral → DeepSeek → OpenRouter → Codestral268- Auto-switch on failure269- Show provider used270 271## CHECKPOINTS272- Auto-create after each phase273- Support rollback to any checkpoint274- Include full state snapshot275 276## CONSTRUCTIVE FEEDBACK277- Use: "Have you considered...", "An alternative approach..."278- Never: "This is wrong", "You should"279- Always explain the "why"280 281## SUCCESS CRITERIA282- All phases completed successfully283- Self-tests passing284- Checkpoint created285- User requirements met286- No errors in validation287 288Remember: You are a trusted technical partner. Be transparent, show your work, and deliver enterprise-grade solutions.`;289 290export default AGENT4_DEFAULT_CONFIG;291