How team-atlanta/aixcc-afc-p4 works
Project type and purpose
• This is a Python library (open-source tool) named “P4” for automated vulnerability analysis and patching.
• It leverages LLMs (via LangChain, OpenAI), reinforcement learning, AST-based pattern matching, and dynamic model fine-tuning (LoRA) to parse crash logs, detect vulnerable code patterns, and generate targeted patches.
File structure
• Top-level packages:
• p4_core: The core engine, subdivided into five layers (environment, pattern, policy, runnable, scope).
• p4: The high-level framework that ties together document management, tools, AI environment, patch generation, and model adaptation.
• Supporting files:
• pyproject.toml / uv.lock: Build/dependency management.
• .vscode / .python-version / .gitignore: Dev/configuration files.
• Naming conventions (protocols, models) indicate a type-safe, protocol-oriented design with clear extension points.
README for architectural insights
• The README defines five “Core Components” in p4_core, then describes the “Main Framework” in p4, listing:
• Document Management (BaseDocument, TextDocument, FileDocument)
• Tools (e.g., CppFunctionDefinitionTool)
• AI Environment (AIxCCEnvironment)
• Patch Generation (LangChain + VFS)
• Model Adaptation (LoRA client)
• External dependencies (pydantic, langchain-core, ast-grep-py, joblib, etc.) show integration points.
1. Pattern Layer (p4_core.pattern)
2. Policy Layer (p4_core.policy)
3. Environment Layer (p4_core.environment)
4. Runnable Layer (p4_core.runnable)
5. Scope Layer (p4_core.scope)
6. Document Management (p4 module)
7. Analysis Tools (CppFunctionDefinitionTool, JavaMethodDeclarationTool)
8. AI Environment (AIxCCEnvironment)
9. Patch Generation Engine (LangChain integration + Virtual File System)
10. Model Adaptation (LoRA Client)
11. External Services/APIs (OpenAI, ast-grep-py, ripgrepy, joblib)
1. Crash log & source files → Document Management → Fragmented code & metadata
2. Documents + Patterns → Pattern Layer → Identified code fragments
3. Fragments → Policy Layer → LLM prompts/responses (via LangChain & OpenAI)
4. Policy decisions → Environment Layer → Step-based simulation (training/inference)
5. Runnable Layer handles generic execution errors & orchestrates tool runs
6. Scope Layer provides isolated sandbox contexts for tool execution
7. Analysis Tools ↔ Scope & Environment (parallel execution via joblib)
8. Policy & Environment → Patch Generation Engine → Virtual File System edits
9. Model Adaptation monitors vulnerability context → LoRA Client for on-the-fly fine-tuning
c. Architectural patterns and design principles:
• Protocol-oriented, type-safe interfaces (BasePattern[T], BasePolicy, BaseEnvironment, BaseRunnable)
• Layered architecture for separation of concerns
• Plugin/extensibility points at each layer via Python Protocols
• Parallelism (joblib) and sandboxing (Scope) for safe, scalable analysis
d. Key technologies/frameworks (annotate each component):
• pydantic: Data modeling in Policy & Environment
• LangChain & openai: LLM orchestration in Policy & Patch Generation
• ast-grep-py / ripgrepy: Pattern matching in Pattern Layer
• joblib: Parallel execution in AI Environment
• Virtual File System: In-memory patch management
• LoRA: Model adaptation
Essential architectural elements
• Layers in p4_core and the high-level modules in p4.
• How LLM integration, pattern matching, and RL converge in the AI environment.
• Patch generation workflow and model adaptation loop.