Files

214 lines
6.3 KiB
Markdown
Raw Permalink Normal View History

feat: Complete Phase 2.5-2.7 - Intelligent LLM-Powered Workflow Analysis This commit implements three major architectural improvements to transform Atomizer from static pattern matching to intelligent AI-powered analysis. ## Phase 2.5: Intelligent Codebase-Aware Gap Detection ✅ Created intelligent system that understands existing capabilities before requesting examples: **New Files:** - optimization_engine/codebase_analyzer.py (379 lines) Scans Atomizer codebase for existing FEA/CAE capabilities - optimization_engine/workflow_decomposer.py (507 lines, v0.2.0) Breaks user requests into atomic workflow steps Complete rewrite with multi-objective, constraints, subcase targeting - optimization_engine/capability_matcher.py (312 lines) Matches workflow steps to existing code implementations - optimization_engine/targeted_research_planner.py (259 lines) Creates focused research plans for only missing capabilities **Results:** - 80-90% coverage on complex optimization requests - 87-93% confidence in capability matching - Fixed expression reading misclassification (geometry vs result_extraction) ## Phase 2.6: Intelligent Step Classification ✅ Distinguishes engineering features from simple math operations: **New Files:** - optimization_engine/step_classifier.py (335 lines) **Classification Types:** 1. Engineering Features - Complex FEA/CAE needing research 2. Inline Calculations - Simple math to auto-generate 3. Post-Processing Hooks - Middleware between FEA steps ## Phase 2.7: LLM-Powered Workflow Intelligence ✅ Replaces static regex patterns with Claude AI analysis: **New Files:** - optimization_engine/llm_workflow_analyzer.py (395 lines) Uses Claude API for intelligent request analysis Supports both Claude Code (dev) and API (production) modes - .claude/skills/analyze-workflow.md Skill template for LLM workflow analysis integration **Key Breakthrough:** - Detects ALL intermediate steps (avg, min, normalization, etc.) - Understands engineering context (CBUSH vs CBAR, directions, metrics) - Distinguishes OP2 extraction from part expression reading - Expected 95%+ accuracy with full nuance detection ## Test Coverage **New Test Files:** - tests/test_phase_2_5_intelligent_gap_detection.py (335 lines) - tests/test_complex_multiobj_request.py (130 lines) - tests/test_cbush_optimization.py (130 lines) - tests/test_cbar_genetic_algorithm.py (150 lines) - tests/test_step_classifier.py (140 lines) - tests/test_llm_complex_request.py (387 lines) All tests include: - UTF-8 encoding for Windows console - atomizer environment (not test_env) - Comprehensive validation checks ## Documentation **New Documentation:** - docs/PHASE_2_5_INTELLIGENT_GAP_DETECTION.md (254 lines) - docs/PHASE_2_7_LLM_INTEGRATION.md (227 lines) - docs/SESSION_SUMMARY_PHASE_2_5_TO_2_7.md (252 lines) **Updated:** - README.md - Added Phase 2.5-2.7 completion status - DEVELOPMENT_ROADMAP.md - Updated phase progress ## Critical Fixes 1. **Expression Reading Misclassification** (lines cited in session summary) - Updated codebase_analyzer.py pattern detection - Fixed workflow_decomposer.py domain classification - Added capability_matcher.py read_expression mapping 2. **Environment Standardization** - All code now uses 'atomizer' conda environment - Removed test_env references throughout 3. **Multi-Objective Support** - WorkflowDecomposer v0.2.0 handles multiple objectives - Constraint extraction and validation - Subcase and direction targeting ## Architecture Evolution **Before (Static & Dumb):** User Request → Regex Patterns → Hardcoded Rules → Missed Steps ❌ **After (LLM-Powered & Intelligent):** User Request → Claude AI Analysis → Structured JSON → ├─ Engineering (research needed) ├─ Inline (auto-generate Python) ├─ Hooks (middleware scripts) └─ Optimization (config) ✅ ## LLM Integration Strategy **Development Mode (Current):** - Use Claude Code directly for interactive analysis - No API consumption or costs - Perfect for iterative development **Production Mode (Future):** - Optional Anthropic API integration - Falls back to heuristics if no API key - For standalone batch processing ## Next Steps - Phase 2.8: Inline Code Generation - Phase 2.9: Post-Processing Hook Generation - Phase 3: MCP Integration for automated documentation research 🚀 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-16 13:35:41 -05:00
# Knowledge Base
> Persistent storage of learned patterns, schemas, and research findings for autonomous feature generation
**Purpose**: Enable Atomizer to learn from user examples, documentation, and research sessions, building a growing repository of knowledge that makes future feature generation faster and more accurate.
---
## Folder Structure
```
knowledge_base/
├── nx_research/ # NX-specific learned patterns and schemas
│ ├── material_xml_schema.md
│ ├── journal_script_patterns.md
│ ├── load_bc_patterns.md
│ └── best_practices.md
├── research_sessions/ # Detailed logs of each research session
│ └── [YYYY-MM-DD]_[topic]/
│ ├── user_question.txt # Original user request
│ ├── sources_consulted.txt # Where information came from
│ ├── findings.md # What was learned
│ └── decision_rationale.md # Why this approach was chosen
└── templates/ # Reusable code patterns learned from research
├── xml_generation_template.py
├── journal_script_template.py
└── custom_extractor_template.py
```
---
## Research Workflow
### 1. Knowledge Gap Detection
When an LLM encounters a request it cannot fulfill:
```python
# Search feature registry
gap = research_agent.identify_knowledge_gap("Create NX material XML")
# Returns: {'missing_features': ['material_generator'], 'confidence': 0.2}
```
### 2. Research Plan Creation
Prioritize sources: **User Examples** > **NX MCP** > **Web Documentation**
```python
plan = research_agent.create_research_plan(gap)
# Returns: [
# {'step': 1, 'action': 'ask_user_for_example', 'priority': 'high'},
# {'step': 2, 'action': 'query_nx_mcp', 'priority': 'medium'},
# {'step': 3, 'action': 'web_search', 'query': 'NX material XML', 'priority': 'low'}
# ]
```
### 3. Interactive Research
Ask user first for concrete examples:
```
LLM: "I don't have a feature for NX material XMLs yet.
Do you have an example .xml file I can learn from?"
User: [uploads steel_material.xml]
LLM: [Analyzes structure, extracts schema, identifies patterns]
```
### 4. Knowledge Synthesis
Combine findings from multiple sources:
```python
findings = {
'user_example': 'steel_material.xml',
'nx_mcp_docs': 'PhysicalMaterial schema',
'web_docs': 'NXOpen material properties API'
}
knowledge = research_agent.synthesize_knowledge(findings)
# Returns: {
# 'schema': {...},
# 'patterns': [...],
# 'confidence': 0.85
# }
```
### 5. Feature Generation
Create new feature following learned patterns:
```python
feature_spec = research_agent.design_feature(knowledge)
# Generates:
# - optimization_engine/custom_functions/nx_material_generator.py
# - knowledge_base/nx_research/material_xml_schema.md
# - knowledge_base/templates/xml_generation_template.py
```
### 6. Documentation & Integration
Save research session and update registries:
```python
research_agent.document_session(
topic='nx_materials',
findings=findings,
generated_files=['nx_material_generator.py'],
confidence=0.85
)
# Creates: knowledge_base/research_sessions/2025-01-16_nx_materials/
```
---
## Confidence Tracking
Knowledge is tagged with confidence scores based on source:
| Source | Confidence | Reliability |
|--------|-----------|-------------|
| User-validated example | 0.95 | Highest - user confirmed it works |
| NX MCP (official docs) | 0.85 | High - authoritative source |
| NXOpenTSE (community) | 0.70 | Medium - community-verified |
| Web search (generic) | 0.50 | Low - needs validation |
**Rule**: Only generate code if combined confidence > 0.70
---
## Knowledge Retrieval
Before starting new research, search existing knowledge base:
```python
# Check if we already know about this topic
existing = research_agent.search_knowledge_base("material XML")
if existing and existing['confidence'] > 0.8:
# Use existing template
template = load_template(existing['template_path'])
else:
# Start new research session
research_agent.execute_research(topic="material XML")
```
---
## Best Practices
### For NX Research
- Always save journal script patterns with comments explaining NXOpen API calls
- Document version compatibility (e.g., "Tested on NX 2412")
- Include error handling patterns (common NX exceptions)
- Store unit conversion patterns (mm/m, MPa/Pa, etc.)
### For Research Sessions
- Save user's original question verbatim
- Document ALL sources consulted (with URLs or file paths)
- Explain decision rationale (why this approach over alternatives)
- Include confidence assessment with justification
### For Templates
- Make templates parameterizable (use Jinja2 or similar)
- Include type hints and docstrings
- Add validation logic (check inputs before execution)
- Document expected inputs/outputs
---
## Example Research Session
### Session: `2025-01-16_nx_materials`
**User Question**:
```
"Please create a new material XML for NX with titanium Ti-6Al-4V properties"
```
**Sources Consulted**:
1. User provided: `steel_material.xml` (existing NX material)
2. NX MCP query: "PhysicalMaterial XML schema"
3. Web search: "Titanium Ti-6Al-4V material properties"
**Findings**:
- XML schema learned from user example
- Material properties from web search
- Validation: User confirmed generated XML loads in NX
**Generated Files**:
1. `optimization_engine/custom_functions/nx_material_generator.py`
2. `knowledge_base/nx_research/material_xml_schema.md`
3. `knowledge_base/templates/xml_generation_template.py`
**Confidence**: 0.90 (user-validated)
**Decision Rationale**:
Chose XML generation over direct NXOpen API because:
- XML is version-agnostic (works across NX versions)
- User already had XML workflow established
- Easier for user to inspect/validate generated files
---
## Future Enhancements
### Phase 2 (Current)
- Interactive research workflow
- Knowledge base structure
- Basic pattern learning
### Phase 3-4
- Multi-source synthesis (combine user + MCP + web)
- Automatic template extraction from code
- Pattern recognition across sessions
### Phase 7-8
- Community knowledge sharing
- Pattern evolution (refine templates based on usage)
- Predictive research (anticipate knowledge gaps)
---
**Last Updated**: 2025-01-16
**Related Docs**: [DEVELOPMENT_ROADMAP.md](../DEVELOPMENT_ROADMAP.md), [FEATURE_REGISTRY_ARCHITECTURE.md](../docs/FEATURE_REGISTRY_ARCHITECTURE.md)