mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2025-09-15 04:17:22 +00:00
Merge branch 'main' of https://github.com/gejjech/system-prompts-and-models-of-ai-tools
This commit is contained in:
commit
98d265b163
@ -1,274 +0,0 @@
|
|||||||
# 🤖 AI Prompt Evolution Analysis Report
|
|
||||||
## Unveiling the Hidden Patterns in AI Assistant Design
|
|
||||||
|
|
||||||
*Generated from analysis of 20+ AI tool prompts across the industry*
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🎯 Executive Summary
|
|
||||||
|
|
||||||
After analyzing your comprehensive collection of AI prompts, I've discovered fascinating evolutionary patterns that reveal how different AI tools approach the same fundamental challenge: **making AI assistants more human-like and effective**. This report uncovers the hidden strategies, philosophical differences, and emerging best practices across the AI assistant landscape.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📊 The Great AI Assistant Divide
|
|
||||||
|
|
||||||
### **Autonomous Agents vs. Guided Assistants**
|
|
||||||
|
|
||||||
Your collection reveals two distinct philosophical approaches:
|
|
||||||
|
|
||||||
#### 🚀 **Autonomous Agents** (Cursor, Devin AI, Replit)
|
|
||||||
- **Philosophy**: "Do it yourself, don't ask permission"
|
|
||||||
- **Key Pattern**: Extensive tool catalogs with autonomous decision-making
|
|
||||||
- **Signature Trait**: Complex command structures with detailed parameter specifications
|
|
||||||
|
|
||||||
#### 🎯 **Guided Assistants** (Perplexity, Cluely, Lovable)
|
|
||||||
- **Philosophy**: "I'll help you find the answer, you make the decision"
|
|
||||||
- **Key Pattern**: Focused on information gathering and presentation
|
|
||||||
- **Signature Trait**: Structured response formats with clear citation systems
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🔍 Deep Pattern Analysis
|
|
||||||
|
|
||||||
### **1. The Tool Specification Evolution**
|
|
||||||
|
|
||||||
**Early Pattern** (v0 Prompts):
|
|
||||||
```
|
|
||||||
- Basic tool descriptions
|
|
||||||
- Simple parameter lists
|
|
||||||
- Limited error handling
|
|
||||||
```
|
|
||||||
|
|
||||||
**Modern Pattern** (Cursor v1.2):
|
|
||||||
```
|
|
||||||
- Detailed usage guidelines
|
|
||||||
- Extensive examples
|
|
||||||
- Context-aware tool selection
|
|
||||||
- Comprehensive error handling
|
|
||||||
```
|
|
||||||
|
|
||||||
### **2. The Communication Style Shift**
|
|
||||||
|
|
||||||
| Era | Style | Example |
|
|
||||||
|-----|--------|---------|
|
|
||||||
| **2019-2021** | Formal, verbose | "I will assist you with your programming task" |
|
|
||||||
| **2022-2023** | Conversational, helpful | "Let me help you with that!" |
|
|
||||||
| **2024+** | Autonomous, confident | "I'll handle this for you" |
|
|
||||||
|
|
||||||
### **3. The Memory Revolution**
|
|
||||||
|
|
||||||
**Pre-Memory Era**: Each conversation started fresh
|
|
||||||
**Post-Memory Era**: Persistent context across sessions
|
|
||||||
|
|
||||||
*Notable Implementation*: Cursor's memory system with citation format `[[memory:MEMORY_ID]]`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🧠 Cognitive Architecture Insights
|
|
||||||
|
|
||||||
### **The Planning vs. Execution Split**
|
|
||||||
|
|
||||||
**Devin AI's Approach**:
|
|
||||||
```
|
|
||||||
Planning Mode → Information Gathering → Plan Creation → Standard Mode → Execution
|
|
||||||
```
|
|
||||||
|
|
||||||
**Cursor's Approach**:
|
|
||||||
```
|
|
||||||
Immediate Context Analysis → Tool Selection → Autonomous Execution → Verification
|
|
||||||
```
|
|
||||||
|
|
||||||
### **The Context Understanding Hierarchy**
|
|
||||||
|
|
||||||
1. **File-Level Context** (basic)
|
|
||||||
2. **Codebase-Level Context** (intermediate)
|
|
||||||
3. **Project-Level Context** (advanced)
|
|
||||||
4. **User-Intent Context** (expert)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🎨 Response Format Evolution
|
|
||||||
|
|
||||||
### **The Markdown Revolution**
|
|
||||||
|
|
||||||
**Early AI**: Plain text responses
|
|
||||||
**Modern AI**: Rich markdown with:
|
|
||||||
- Code blocks with syntax highlighting
|
|
||||||
- Structured tables for comparisons
|
|
||||||
- Mathematical expressions in LaTeX
|
|
||||||
- Hierarchical headers for organization
|
|
||||||
|
|
||||||
### **Citation Systems**
|
|
||||||
|
|
||||||
**Perplexity's Innovation**:
|
|
||||||
```
|
|
||||||
"AI assistants are becoming more autonomous12."
|
|
||||||
```
|
|
||||||
|
|
||||||
**Cursor's Innovation**:
|
|
||||||
```
|
|
||||||
[[memory:MEMORY_ID]] for persistent context
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🔧 Tool Integration Patterns
|
|
||||||
|
|
||||||
### **The Tool Catalog Explosion**
|
|
||||||
|
|
||||||
**2019**: 3-5 basic tools
|
|
||||||
**2024**: 20+ specialized tools including:
|
|
||||||
- Semantic search
|
|
||||||
- LSP integration
|
|
||||||
- Browser automation
|
|
||||||
- Deployment systems
|
|
||||||
- Memory management
|
|
||||||
|
|
||||||
### **The Multi-Tool Paradigm**
|
|
||||||
|
|
||||||
Modern AI assistants use **parallel tool execution**:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"tool_uses": [
|
|
||||||
{"recipient_name": "codebase_search", "parameters": {...}},
|
|
||||||
{"recipient_name": "read_file", "parameters": {...}}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🌟 Emerging Best Practices
|
|
||||||
|
|
||||||
### **1. The Context Maximization Principle**
|
|
||||||
|
|
||||||
*"Be THOROUGH when gathering information"* - Cursor v1.2
|
|
||||||
|
|
||||||
**Implementation**: Multiple search strategies, comprehensive file reading, LSP integration
|
|
||||||
|
|
||||||
### **2. The Autonomous Resolution Principle**
|
|
||||||
|
|
||||||
*"Keep going until the user's query is completely resolved"* - Cursor v1.2
|
|
||||||
|
|
||||||
**Implementation**: Self-directed problem solving with minimal user intervention
|
|
||||||
|
|
||||||
### **3. The Memory Integration Principle**
|
|
||||||
|
|
||||||
*"You must ALWAYS cite a memory when you use it"* - Cursor v1.2
|
|
||||||
|
|
||||||
**Implementation**: Persistent knowledge with natural citation format
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📈 Future Trends Identified
|
|
||||||
|
|
||||||
### **1. The Semantic Search Dominance**
|
|
||||||
|
|
||||||
Traditional grep → Semantic understanding
|
|
||||||
- **Why**: Better context understanding
|
|
||||||
- **Impact**: More accurate tool selection
|
|
||||||
|
|
||||||
### **2. The Browser Integration Surge**
|
|
||||||
|
|
||||||
Static file editing → Dynamic web interaction
|
|
||||||
- **Why**: Real-world testing capabilities
|
|
||||||
- **Impact**: End-to-end solution delivery
|
|
||||||
|
|
||||||
### **3. The Deployment Automation**
|
|
||||||
|
|
||||||
Manual deployment → Automated CI/CD
|
|
||||||
- **Why**: Complete solution delivery
|
|
||||||
- **Impact**: Production-ready code generation
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🎯 Key Insights for AI Tool Developers
|
|
||||||
|
|
||||||
### **1. The Context Window Paradox**
|
|
||||||
- **Problem**: More context = better understanding, but slower processing
|
|
||||||
- **Solution**: Smart context selection and hierarchical understanding
|
|
||||||
|
|
||||||
### **2. The Tool Selection Dilemma**
|
|
||||||
- **Problem**: Too many tools = confusion, too few = limitations
|
|
||||||
- **Solution**: Context-aware tool recommendation with clear usage guidelines
|
|
||||||
|
|
||||||
### **3. The Memory Management Challenge**
|
|
||||||
- **Problem**: Persistent memory vs. conversation freshness
|
|
||||||
- **Solution**: Selective memory with natural citation and update mechanisms
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🏆 The Most Innovative Patterns
|
|
||||||
|
|
||||||
### **1. Cursor's "Maximize Context Understanding"**
|
|
||||||
```
|
|
||||||
"TRACE every symbol back to its definitions and usages"
|
|
||||||
"EXPLORE alternative implementations, edge cases, and varied search terms"
|
|
||||||
```
|
|
||||||
|
|
||||||
### **2. Devin's "Planning Mode"**
|
|
||||||
```
|
|
||||||
Planning → Information Gathering → Plan Creation → Execution
|
|
||||||
```
|
|
||||||
|
|
||||||
### **3. Perplexity's "Citation Integration"**
|
|
||||||
```
|
|
||||||
Natural citation format: "AI is transforming coding12."
|
|
||||||
```
|
|
||||||
|
|
||||||
### **4. Replit's "Proposed Action System"**
|
|
||||||
```
|
|
||||||
Structured action proposals with clear change summaries
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🔮 Predictions for 2025
|
|
||||||
|
|
||||||
### **1. The Rise of Multi-Modal Memory**
|
|
||||||
- Visual memory integration
|
|
||||||
- Audio context preservation
|
|
||||||
- Cross-session learning
|
|
||||||
|
|
||||||
### **2. The Emergence of AI Tool Ecosystems**
|
|
||||||
- Inter-tool communication
|
|
||||||
- Shared context protocols
|
|
||||||
- Unified user experience
|
|
||||||
|
|
||||||
### **3. The Evolution of Autonomous Decision Making**
|
|
||||||
- Risk assessment capabilities
|
|
||||||
- Ethical decision frameworks
|
|
||||||
- User preference learning
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📋 Actionable Recommendations
|
|
||||||
|
|
||||||
### **For AI Tool Developers**:
|
|
||||||
1. **Implement Context Hierarchies**: Start with file-level, expand to project-level
|
|
||||||
2. **Adopt Memory Systems**: Enable persistent learning across sessions
|
|
||||||
3. **Embrace Semantic Search**: Replace exact matching with understanding
|
|
||||||
4. **Design for Autonomy**: Minimize user intervention while maintaining control
|
|
||||||
|
|
||||||
### **For AI Tool Users**:
|
|
||||||
1. **Leverage Memory Systems**: Build persistent context for complex projects
|
|
||||||
2. **Use Semantic Queries**: Ask "how" and "why" questions, not just "what"
|
|
||||||
3. **Embrace Autonomous Mode**: Let AI handle routine tasks while you focus on strategy
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🎉 Conclusion
|
|
||||||
|
|
||||||
Your collection reveals an industry in rapid evolution, moving from simple question-answering to autonomous problem-solving. The most successful AI tools are those that combine:
|
|
||||||
|
|
||||||
- **Deep context understanding**
|
|
||||||
- **Autonomous execution capabilities**
|
|
||||||
- **Persistent memory systems**
|
|
||||||
- **Rich tool integration**
|
|
||||||
|
|
||||||
The future belongs to AI assistants that can truly understand, remember, and act independently while maintaining transparency and user control.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*This analysis was generated by examining 20+ AI tool prompts from your comprehensive collection, revealing patterns that span from 2019 to 2024 across the AI assistant landscape.*
|
|
@ -1,231 +0,0 @@
|
|||||||
# 🤖 AI Prompt Evolution Timeline
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
timeline
|
|
||||||
title AI Assistant Evolution (2019-2024)
|
|
||||||
|
|
||||||
section 2019-2021 : Early Era
|
|
||||||
Basic Q&A : Simple text responses
|
|
||||||
Limited Tools : 3-5 basic functions
|
|
||||||
No Memory : Fresh start each session
|
|
||||||
Formal Language : "I will assist you..."
|
|
||||||
|
|
||||||
section 2022-2023 : Growth Era
|
|
||||||
Markdown Formatting : Rich text responses
|
|
||||||
Tool Expansion : 10+ specialized tools
|
|
||||||
Context Awareness : File-level understanding
|
|
||||||
Conversational Tone : "Let me help you!"
|
|
||||||
|
|
||||||
section 2024 : Autonomous Era
|
|
||||||
Memory Systems : Persistent context
|
|
||||||
Semantic Search : Understanding over matching
|
|
||||||
Browser Integration : Real-world testing
|
|
||||||
Autonomous Execution : "I'll handle this for you"
|
|
||||||
Parallel Tools : Multi-tool execution
|
|
||||||
Deployment Automation : End-to-end solutions
|
|
||||||
```
|
|
||||||
|
|
||||||
# 🧠 Cognitive Architecture Comparison
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph TB
|
|
||||||
subgraph "Devin AI Approach"
|
|
||||||
A[Planning Mode] --> B[Information Gathering]
|
|
||||||
B --> C[Plan Creation]
|
|
||||||
C --> D[Standard Mode]
|
|
||||||
D --> E[Execution]
|
|
||||||
end
|
|
||||||
|
|
||||||
subgraph "Cursor Approach"
|
|
||||||
F[Context Analysis] --> G[Tool Selection]
|
|
||||||
G --> H[Autonomous Execution]
|
|
||||||
H --> I[Verification]
|
|
||||||
end
|
|
||||||
|
|
||||||
subgraph "Perplexity Approach"
|
|
||||||
J[Query Analysis] --> K[Search Strategy]
|
|
||||||
K --> L[Source Evaluation]
|
|
||||||
L --> M[Structured Response]
|
|
||||||
end
|
|
||||||
|
|
||||||
style A fill:#ff9999
|
|
||||||
style F fill:#99ccff
|
|
||||||
style J fill:#99ff99
|
|
||||||
```
|
|
||||||
|
|
||||||
# 🔧 Tool Integration Evolution
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph LR
|
|
||||||
subgraph "2019 Tools"
|
|
||||||
T1[File Read]
|
|
||||||
T2[Basic Search]
|
|
||||||
T3[Simple Edit]
|
|
||||||
end
|
|
||||||
|
|
||||||
subgraph "2024 Tools"
|
|
||||||
T4[Semantic Search]
|
|
||||||
T5[LSP Integration]
|
|
||||||
T6[Browser Automation]
|
|
||||||
T7[Memory Management]
|
|
||||||
T8[Deployment Systems]
|
|
||||||
T9[Parallel Execution]
|
|
||||||
end
|
|
||||||
|
|
||||||
T1 --> T4
|
|
||||||
T2 --> T5
|
|
||||||
T3 --> T6
|
|
||||||
T4 --> T7
|
|
||||||
T5 --> T8
|
|
||||||
T6 --> T9
|
|
||||||
|
|
||||||
style T4 fill:#ffcc99
|
|
||||||
style T7 fill:#cc99ff
|
|
||||||
style T9 fill:#99ffcc
|
|
||||||
```
|
|
||||||
|
|
||||||
# 📊 Response Format Evolution
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph TD
|
|
||||||
subgraph "Early Format"
|
|
||||||
E1[Plain Text]
|
|
||||||
E2[Basic Lists]
|
|
||||||
E3[Simple Code Blocks]
|
|
||||||
end
|
|
||||||
|
|
||||||
subgraph "Modern Format"
|
|
||||||
M1[Rich Markdown]
|
|
||||||
M2[Structured Tables]
|
|
||||||
M3[LaTeX Math]
|
|
||||||
M4[Hierarchical Headers]
|
|
||||||
M5[Natural Citations]
|
|
||||||
M6[Memory Integration]
|
|
||||||
end
|
|
||||||
|
|
||||||
E1 --> M1
|
|
||||||
E2 --> M2
|
|
||||||
E3 --> M3
|
|
||||||
M1 --> M4
|
|
||||||
M2 --> M5
|
|
||||||
M3 --> M6
|
|
||||||
|
|
||||||
style M5 fill:#ff9999
|
|
||||||
style M6 fill:#99ccff
|
|
||||||
```
|
|
||||||
|
|
||||||
# 🎯 Key Innovation Timeline
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
gantt
|
|
||||||
title AI Assistant Innovation Timeline
|
|
||||||
dateFormat YYYY-MM
|
|
||||||
axisFormat %Y-%m
|
|
||||||
|
|
||||||
section Core Features
|
|
||||||
Basic Q&A :done, 2019-01, 2021-12
|
|
||||||
Tool Integration :done, 2020-06, 2022-12
|
|
||||||
Memory Systems :active, 2023-01, 2024-12
|
|
||||||
Autonomous Execution :active, 2023-06, 2024-12
|
|
||||||
|
|
||||||
section Advanced Features
|
|
||||||
Semantic Search :active, 2023-03, 2024-12
|
|
||||||
Browser Integration :active, 2023-09, 2024-12
|
|
||||||
Deployment Auto :active, 2024-01, 2024-12
|
|
||||||
Multi-Modal Memory :crit, 2024-06, 2025-12
|
|
||||||
```
|
|
||||||
|
|
||||||
# 🌟 Innovation Patterns
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
mindmap
|
|
||||||
root((AI Prompt Evolution))
|
|
||||||
Context Understanding
|
|
||||||
File-Level Analysis
|
|
||||||
Codebase Navigation
|
|
||||||
Project-Wide Context
|
|
||||||
User Intent Recognition
|
|
||||||
Tool Integration
|
|
||||||
Basic File Operations
|
|
||||||
Semantic Search
|
|
||||||
LSP Integration
|
|
||||||
Browser Automation
|
|
||||||
Deployment Systems
|
|
||||||
Memory Systems
|
|
||||||
Session Memory
|
|
||||||
Persistent Context
|
|
||||||
Natural Citations
|
|
||||||
Cross-Session Learning
|
|
||||||
Response Formatting
|
|
||||||
Plain Text
|
|
||||||
Rich Markdown
|
|
||||||
Structured Tables
|
|
||||||
Mathematical Expressions
|
|
||||||
Hierarchical Organization
|
|
||||||
Execution Models
|
|
||||||
Guided Assistance
|
|
||||||
Autonomous Problem Solving
|
|
||||||
Planning-Driven Execution
|
|
||||||
Context-Aware Actions
|
|
||||||
```
|
|
||||||
|
|
||||||
# 🔮 Future Predictions
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph TB
|
|
||||||
subgraph "2025 Predictions"
|
|
||||||
P1[Multi-Modal Memory]
|
|
||||||
P2[AI Tool Ecosystems]
|
|
||||||
P3[Ethical Decision Frameworks]
|
|
||||||
P4[Cross-Platform Integration]
|
|
||||||
P5[Real-Time Collaboration]
|
|
||||||
P6[Predictive Assistance]
|
|
||||||
end
|
|
||||||
|
|
||||||
subgraph "Current State"
|
|
||||||
C1[Text-Based Memory]
|
|
||||||
C2[Individual Tools]
|
|
||||||
C3[Basic Safety Rules]
|
|
||||||
C4[Platform-Specific]
|
|
||||||
C5[Reactive Responses]
|
|
||||||
C6[Query-Based Help]
|
|
||||||
end
|
|
||||||
|
|
||||||
C1 --> P1
|
|
||||||
C2 --> P2
|
|
||||||
C3 --> P3
|
|
||||||
C4 --> P4
|
|
||||||
C5 --> P5
|
|
||||||
C6 --> P6
|
|
||||||
|
|
||||||
style P1 fill:#ffcc99
|
|
||||||
style P2 fill:#cc99ff
|
|
||||||
style P3 fill:#99ffcc
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📈 Key Metrics Evolution
|
|
||||||
|
|
||||||
| Metric | 2019 | 2022 | 2024 | 2025 (Predicted) |
|
|
||||||
|--------|------|------|------|-------------------|
|
|
||||||
| **Tool Count** | 3-5 | 10-15 | 20+ | 30+ |
|
|
||||||
| **Context Levels** | 1 | 2-3 | 4 | 5+ |
|
|
||||||
| **Memory Persistence** | None | Session | Cross-session | Multi-modal |
|
|
||||||
| **Autonomy Level** | Low | Medium | High | Very High |
|
|
||||||
| **Response Richness** | Basic | Markdown | Rich | Interactive |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🎯 Innovation Scorecard
|
|
||||||
|
|
||||||
| AI Tool | Context Understanding | Tool Integration | Memory Systems | Autonomy Level | Innovation Score |
|
|
||||||
|---------|---------------------|------------------|----------------|----------------|-----------------|
|
|
||||||
| **Cursor v1.2** | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | **95/100** |
|
|
||||||
| **Devin AI** | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | **90/100** |
|
|
||||||
| **Perplexity** | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ | ⭐⭐ | **60/100** |
|
|
||||||
| **Replit** | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐ | **70/100** |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*This visual analysis reveals the rapid evolution of AI assistant capabilities, from simple question-answering to autonomous problem-solving with persistent memory and rich tool integration.*
|
|
149
PowerShell_AI_Agent/PowerShell_AI_Agent/README.md
Normal file
149
PowerShell_AI_Agent/PowerShell_AI_Agent/README.md
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
# PowerShell AI Agent
|
||||||
|
|
||||||
|
A comprehensive, modular PowerShell-based AI agent with advanced capabilities including voice interaction, plugin system, and comprehensive logging.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Modular Architecture**: AI Engine, Voice Engine, Logging Engine, and Plugin Manager
|
||||||
|
- **Advanced AI Processing**: Intent recognition, system commands, and contextual responses
|
||||||
|
- **Voice Integration**: Speech recognition and text-to-speech capabilities
|
||||||
|
- **Plugin System**: Extensible architecture with custom plugin support
|
||||||
|
- **Comprehensive Logging**: Structured logging with multiple output formats
|
||||||
|
- **Memory Persistence**: Intelligent conversation memory with context awareness
|
||||||
|
- **System Integration**: Built-in system monitoring and management commands
|
||||||
|
- **Interactive CLI**: Rich command-line interface with color-coded output
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
1. **Run the agent:**
|
||||||
|
```powershell
|
||||||
|
.\Start-AIAgent.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Available commands:**
|
||||||
|
- `help` - Show available commands
|
||||||
|
- `exit` or `quit` - Exit the agent
|
||||||
|
- `memory` - Show memory statistics
|
||||||
|
- `config` - Show current configuration
|
||||||
|
- `clear` - Clear the screen
|
||||||
|
- `voice` - Toggle voice mode
|
||||||
|
- `logs` - Show recent log entries
|
||||||
|
- `test` - Test system capabilities
|
||||||
|
- `plugins` - Show loaded plugins
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
The agent uses `config/agent-config.json` for settings:
|
||||||
|
|
||||||
|
- **AI**: Model settings (gpt-4, tokens, temperature)
|
||||||
|
- **Voice**: Speech recognition and synthesis settings
|
||||||
|
- **Memory**: Persistence and storage settings
|
||||||
|
- **Autopilot**: Autonomous operation settings
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
PowerShell_AI_Agent/
|
||||||
|
├── Start-AIAgent.ps1 # Main entry point
|
||||||
|
├── config/
|
||||||
|
│ └── agent-config.json # Configuration file
|
||||||
|
├── data/
|
||||||
|
│ └── memory.json # Conversation memory
|
||||||
|
├── logs/ # Log files
|
||||||
|
├── modules/ # PowerShell modules
|
||||||
|
│ ├── AI-Engine.psm1 # AI processing engine
|
||||||
|
│ ├── Voice-Engine.psm1 # Voice recognition/synthesis
|
||||||
|
│ └── Logging-Engine.psm1 # Comprehensive logging
|
||||||
|
├── plugins/ # Extensions
|
||||||
|
│ ├── Plugin-Manager.psm1 # Plugin management system
|
||||||
|
│ └── System-Tools.ps1 # Example system tools plugin
|
||||||
|
├── scripts/ # Utility scripts
|
||||||
|
└── tests/ # Test files
|
||||||
|
│ └── Test-AIAgent.ps1 # Comprehensive test suite
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
- `-Verbose`: Enable verbose error reporting
|
||||||
|
- `-NoVoice`: Disable voice features
|
||||||
|
- `-Debug`: Enable debug logging
|
||||||
|
- `-ConfigPath`: Specify custom config file path
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# Basic run
|
||||||
|
.\Start-AIAgent.ps1
|
||||||
|
|
||||||
|
# With verbose logging
|
||||||
|
.\Start-AIAgent.ps1 -Verbose
|
||||||
|
|
||||||
|
# With debug logging
|
||||||
|
.\Start-AIAgent.ps1 -Debug
|
||||||
|
|
||||||
|
# Disable voice features
|
||||||
|
.\Start-AIAgent.ps1 -NoVoice
|
||||||
|
|
||||||
|
# Custom config file
|
||||||
|
.\Start-AIAgent.ps1 -ConfigPath ".\custom-config.json"
|
||||||
|
|
||||||
|
# Run test suite
|
||||||
|
.\tests\Test-AIAgent.ps1
|
||||||
|
|
||||||
|
# Run tests without voice
|
||||||
|
.\tests\Test-AIAgent.ps1 -SkipVoice
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
### Creating Plugins
|
||||||
|
|
||||||
|
Create new plugins in the `plugins/` directory:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
@{
|
||||||
|
Name = "My Plugin"
|
||||||
|
Version = "1.0"
|
||||||
|
Description = "Description of your plugin"
|
||||||
|
Commands = @(
|
||||||
|
@{
|
||||||
|
Name = "MyCommand"
|
||||||
|
Description = "Description of the command"
|
||||||
|
Function = {
|
||||||
|
param([hashtable]$Parameters)
|
||||||
|
# Your command logic here
|
||||||
|
return "Command executed successfully"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Extending AI Engine
|
||||||
|
|
||||||
|
Modify `modules/AI-Engine.psm1` to add new capabilities:
|
||||||
|
- Add new intent patterns in `Analyze-UserIntent`
|
||||||
|
- Create new system commands in `Execute-SystemCommand`
|
||||||
|
- Extend response patterns in `Generate-ContextualResponse`
|
||||||
|
|
||||||
|
### Voice Integration
|
||||||
|
|
||||||
|
The voice engine supports:
|
||||||
|
- Speech synthesis with configurable speed and voice
|
||||||
|
- Speech recognition with confidence thresholds
|
||||||
|
- Multiple voice selection
|
||||||
|
- Voice testing and diagnostics
|
||||||
|
|
||||||
|
### Logging
|
||||||
|
|
||||||
|
The logging system provides:
|
||||||
|
- Structured JSON logging
|
||||||
|
- Multiple log levels (Debug, Info, Warning, Error)
|
||||||
|
- Log rotation and archiving
|
||||||
|
- Export capabilities (CSV, JSON, HTML)
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- PowerShell 5.1 or higher
|
||||||
|
- Windows 10/11 (for voice features)
|
||||||
|
- Internet connection (for AI service integration)
|
355
PowerShell_AI_Agent/PowerShell_AI_Agent/Start-AIAgent.ps1
Normal file
355
PowerShell_AI_Agent/PowerShell_AI_Agent/Start-AIAgent.ps1
Normal file
@ -0,0 +1,355 @@
|
|||||||
|
# PowerShell AI Agent - Main Entry Point
|
||||||
|
# Version: 2.0 - Enhanced with modules
|
||||||
|
|
||||||
|
param(
|
||||||
|
[switch]$Verbose,
|
||||||
|
[switch]$NoVoice,
|
||||||
|
[switch]$Debug,
|
||||||
|
[string]$ConfigPath = ".\config\agent-config.json"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Import required modules
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Import custom modules
|
||||||
|
$modulePath = ".\modules"
|
||||||
|
if (Test-Path $modulePath) {
|
||||||
|
Import-Module "$modulePath\AI-Engine.psm1" -Force
|
||||||
|
Import-Module "$modulePath\Voice-Engine.psm1" -Force
|
||||||
|
Import-Module "$modulePath\Logging-Engine.psm1" -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
# Import plugin manager
|
||||||
|
$pluginPath = ".\plugins"
|
||||||
|
if (Test-Path $pluginPath) {
|
||||||
|
Import-Module "$pluginPath\Plugin-Manager.psm1" -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to load configuration
|
||||||
|
function Load-Configuration {
|
||||||
|
param([string]$ConfigPath)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (Test-Path $ConfigPath) {
|
||||||
|
$config = Get-Content $ConfigPath -Raw | ConvertFrom-Json
|
||||||
|
# Convert PSCustomObject to hashtable
|
||||||
|
$configHashtable = @{}
|
||||||
|
$config.PSObject.Properties | ForEach-Object {
|
||||||
|
$configHashtable[$_.Name] = $_.Value
|
||||||
|
}
|
||||||
|
Write-Host "Configuration loaded successfully" -ForegroundColor Green
|
||||||
|
return $configHashtable
|
||||||
|
} else {
|
||||||
|
throw "Configuration file not found: $ConfigPath"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Failed to load configuration: $_"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to initialize memory
|
||||||
|
function Initialize-Memory {
|
||||||
|
param($Config)
|
||||||
|
|
||||||
|
$memoryPath = $Config.Memory.PersistencePath
|
||||||
|
if (Test-Path $memoryPath) {
|
||||||
|
try {
|
||||||
|
$memory = Get-Content $memoryPath -Raw | ConvertFrom-Json
|
||||||
|
Write-Host "Memory loaded from: $memoryPath" -ForegroundColor Green
|
||||||
|
return $memory
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to load memory, creating new memory file"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create new memory structure
|
||||||
|
$memory = @{
|
||||||
|
entries = @()
|
||||||
|
lastUpdated = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
version = "1.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ensure directory exists
|
||||||
|
$memoryDir = Split-Path $memoryPath -Parent
|
||||||
|
if (!(Test-Path $memoryDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $memoryDir -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$memory | ConvertTo-Json -Depth 10 | Set-Content $memoryPath
|
||||||
|
Write-Host "New memory file created: $memoryPath" -ForegroundColor Yellow
|
||||||
|
return $memory
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to save memory
|
||||||
|
function Save-Memory {
|
||||||
|
param($Memory, $Config)
|
||||||
|
|
||||||
|
$Memory.lastUpdated = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
$memoryPath = $Config.Memory.PersistencePath
|
||||||
|
$Memory | ConvertTo-Json -Depth 10 | Set-Content $memoryPath
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to add memory entry
|
||||||
|
function Add-MemoryEntry {
|
||||||
|
param($Memory, $Input, $Response, $Timestamp = (Get-Date))
|
||||||
|
|
||||||
|
$entry = @{
|
||||||
|
input = $Input
|
||||||
|
response = $Response
|
||||||
|
timestamp = $Timestamp.ToString("yyyy-MM-dd HH:mm:ss")
|
||||||
|
}
|
||||||
|
|
||||||
|
$Memory.entries += $entry
|
||||||
|
|
||||||
|
# Limit memory entries
|
||||||
|
if ($Memory.entries.Count -gt 1000) {
|
||||||
|
$Memory.entries = $Memory.entries | Select-Object -Last 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to simulate AI response (placeholder for actual AI integration)
|
||||||
|
function Get-AIResponse {
|
||||||
|
param($Input, $Config, $Memory)
|
||||||
|
|
||||||
|
# This is a placeholder - in a real implementation, you would integrate with an AI service
|
||||||
|
$responses = @(
|
||||||
|
"I understand you said: '$Input'. How can I help you further?",
|
||||||
|
"That's an interesting point about '$Input'. Let me think about that...",
|
||||||
|
"Based on your input '$Input', I'd recommend considering the following...",
|
||||||
|
"I've processed your request: '$Input'. Here's what I can do for you...",
|
||||||
|
"Thank you for sharing '$Input'. I'm here to assist you with any tasks."
|
||||||
|
)
|
||||||
|
|
||||||
|
$response = $responses | Get-Random
|
||||||
|
|
||||||
|
# Add context from memory if available
|
||||||
|
if ($Memory.entries.Count -gt 0) {
|
||||||
|
$recentEntries = $Memory.entries | Select-Object -Last 3
|
||||||
|
$context = "Based on our previous conversation, "
|
||||||
|
$response = $context + $response
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to handle voice input/output (placeholder)
|
||||||
|
function Handle-Voice {
|
||||||
|
param($Config, $Enabled = $true)
|
||||||
|
|
||||||
|
if (-not $Enabled -or -not $Config.Voice.Enabled) {
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Voice features are configured but not implemented yet." -ForegroundColor Yellow
|
||||||
|
Write-Host "Voice settings: Language=$($Config.Voice.Language), Speed=$($Config.Voice.ResponseSpeed)" -ForegroundColor Cyan
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main agent loop
|
||||||
|
function Start-AgentLoop {
|
||||||
|
param($Config, $Memory, $AIEngine, $VoiceEngine, $LoggingEngine, $PluginManager)
|
||||||
|
|
||||||
|
Write-Host "=== PowerShell AI Agent Started ===" -ForegroundColor Green
|
||||||
|
Write-Host "AI Model: $($Config.AI.Model)" -ForegroundColor Cyan
|
||||||
|
Write-Host "Max Tokens: $($Config.AI.MaxTokens)" -ForegroundColor Cyan
|
||||||
|
Write-Host "Temperature: $($Config.AI.Temperature)" -ForegroundColor Cyan
|
||||||
|
Write-Host "Memory Enabled: $($Config.Memory.Enabled)" -ForegroundColor Cyan
|
||||||
|
Write-Host "Autopilot Enabled: $($Config.Autopilot.Enabled)" -ForegroundColor Cyan
|
||||||
|
Write-Host "Voice Enabled: $($VoiceEngine.VoiceEnabled)" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Type 'exit' or 'quit' to stop the agent" -ForegroundColor Yellow
|
||||||
|
Write-Host "Type 'help' for available commands" -ForegroundColor Yellow
|
||||||
|
Write-Host "Type 'voice' to toggle voice mode" -ForegroundColor Yellow
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
Write-InfoLog -Engine $LoggingEngine -Message "Agent loop started"
|
||||||
|
|
||||||
|
# Initialize voice if enabled
|
||||||
|
if ($VoiceEngine.VoiceEnabled -and -not $NoVoice) {
|
||||||
|
Test-VoiceSystem -Engine $VoiceEngine
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
Write-Host "AI Agent> " -NoNewline -ForegroundColor Green
|
||||||
|
$userInput = Read-Host
|
||||||
|
|
||||||
|
if ([string]::IsNullOrWhiteSpace($userInput)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-DebugLog -Engine $LoggingEngine -Message "User input received" -Context @{ Input = $userInput }
|
||||||
|
|
||||||
|
# Handle special commands
|
||||||
|
switch ($userInput.ToLower()) {
|
||||||
|
"exit" {
|
||||||
|
Write-InfoLog -Engine $LoggingEngine -Message "User requested exit"
|
||||||
|
Write-Host "Saving memory and shutting down..." -ForegroundColor Yellow
|
||||||
|
Save-Memory -Memory $Memory -Config $Config
|
||||||
|
Write-Host "Goodbye!" -ForegroundColor Green
|
||||||
|
return
|
||||||
|
}
|
||||||
|
"quit" {
|
||||||
|
Write-InfoLog -Engine $LoggingEngine -Message "User requested quit"
|
||||||
|
Write-Host "Saving memory and shutting down..." -ForegroundColor Yellow
|
||||||
|
Save-Memory -Memory $Memory -Config $Config
|
||||||
|
Write-Host "Goodbye!" -ForegroundColor Green
|
||||||
|
return
|
||||||
|
}
|
||||||
|
"help" {
|
||||||
|
Write-Host "Available commands:" -ForegroundColor Cyan
|
||||||
|
Write-Host " help - Show this help message" -ForegroundColor White
|
||||||
|
Write-Host " exit - Exit the agent" -ForegroundColor White
|
||||||
|
Write-Host " quit - Exit the agent" -ForegroundColor White
|
||||||
|
Write-Host " memory - Show memory statistics" -ForegroundColor White
|
||||||
|
Write-Host " config - Show current configuration" -ForegroundColor White
|
||||||
|
Write-Host " clear - Clear the screen" -ForegroundColor White
|
||||||
|
Write-Host " voice - Toggle voice mode" -ForegroundColor White
|
||||||
|
Write-Host " logs - Show recent log entries" -ForegroundColor White
|
||||||
|
Write-Host " test - Test system capabilities" -ForegroundColor White
|
||||||
|
Write-Host " plugins - Show loaded plugins" -ForegroundColor White
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
"memory" {
|
||||||
|
Write-Host "Memory Statistics:" -ForegroundColor Cyan
|
||||||
|
Write-Host " Total Entries: $($Memory.entries.Count)" -ForegroundColor White
|
||||||
|
Write-Host " Last Updated: $($Memory.lastUpdated)" -ForegroundColor White
|
||||||
|
Write-Host " Version: $($Memory.version)" -ForegroundColor White
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
"config" {
|
||||||
|
Write-Host "Current Configuration:" -ForegroundColor Cyan
|
||||||
|
$Config | ConvertTo-Json -Depth 3 | Write-Host -ForegroundColor White
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
"clear" {
|
||||||
|
Clear-Host
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
"voice" {
|
||||||
|
if ($VoiceEngine.VoiceEnabled) {
|
||||||
|
if ($VoiceEngine.IsListening) {
|
||||||
|
Stop-SpeechRecognition -Engine $VoiceEngine
|
||||||
|
} else {
|
||||||
|
Start-SpeechRecognition -Engine $VoiceEngine -OnSpeechRecognized {
|
||||||
|
param($text)
|
||||||
|
Write-Host "Voice: $text" -ForegroundColor Magenta
|
||||||
|
# Process voice input
|
||||||
|
$aiResponse = Get-AIResponse -Engine $AIEngine -Input $text -Memory $Memory
|
||||||
|
Write-Host "AI: $aiResponse" -ForegroundColor Blue
|
||||||
|
Speak-Text -Engine $VoiceEngine -Text $aiResponse
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "Voice features are disabled" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
"logs" {
|
||||||
|
$recentLogs = Get-LogEntries -Engine $LoggingEngine -Count 10
|
||||||
|
Write-Host "Recent Log Entries:" -ForegroundColor Cyan
|
||||||
|
foreach ($log in $recentLogs) {
|
||||||
|
$color = switch ($log.Level) {
|
||||||
|
"Debug" { "Gray" }
|
||||||
|
"Info" { "White" }
|
||||||
|
"Warning" { "Yellow" }
|
||||||
|
"Error" { "Red" }
|
||||||
|
default { "White" }
|
||||||
|
}
|
||||||
|
Write-Host "[$($log.Timestamp)] [$($log.Level)] $($log.Message)" -ForegroundColor $color
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
"test" {
|
||||||
|
Write-Host "Testing system capabilities..." -ForegroundColor Cyan
|
||||||
|
Test-VoiceSystem -Engine $VoiceEngine
|
||||||
|
Write-Host "AI Engine: OK" -ForegroundColor Green
|
||||||
|
Write-Host "Logging Engine: OK" -ForegroundColor Green
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
"plugins" {
|
||||||
|
Show-PluginInfo -Manager $PluginManager
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process user input with AI
|
||||||
|
$aiResponse = Get-AIResponse -Engine $AIEngine -Input $userInput -Memory $Memory
|
||||||
|
|
||||||
|
# Display response
|
||||||
|
Write-Host "AI: $aiResponse" -ForegroundColor Blue
|
||||||
|
|
||||||
|
# Speak response if voice is enabled
|
||||||
|
if ($VoiceEngine.VoiceEnabled -and $VoiceEngine.IsListening) {
|
||||||
|
Speak-Text -Engine $VoiceEngine -Text $aiResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add to memory
|
||||||
|
if ($Config.Memory.Enabled) {
|
||||||
|
Add-MemoryEntry -Memory $Memory -Input $userInput -Response $aiResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
# Log the interaction
|
||||||
|
Write-InfoLog -Engine $LoggingEngine -Message "AI response generated" -Context @{
|
||||||
|
Input = $userInput
|
||||||
|
Response = $aiResponse
|
||||||
|
MemoryEntries = $Memory.entries.Count
|
||||||
|
}
|
||||||
|
|
||||||
|
# Save memory periodically
|
||||||
|
if ($Memory.entries.Count % 10 -eq 0) {
|
||||||
|
Save-Memory -Memory $Memory -Config $Config
|
||||||
|
Write-DebugLog -Engine $LoggingEngine -Message "Memory saved automatically"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-ErrorLog -Engine $LoggingEngine -Message "Error in agent loop: $_" -Context @{ StackTrace = $_.ScriptStackTrace }
|
||||||
|
Write-Error "Error in agent loop: $_"
|
||||||
|
if ($Verbose) {
|
||||||
|
Write-Host "Stack trace: $($_.ScriptStackTrace)" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while ($true)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main execution
|
||||||
|
try {
|
||||||
|
Write-Host "PowerShell AI Agent Starting..." -ForegroundColor Green
|
||||||
|
|
||||||
|
# Load configuration
|
||||||
|
$config = Load-Configuration -ConfigPath $ConfigPath
|
||||||
|
|
||||||
|
# Initialize engines
|
||||||
|
$aiEngine = Initialize-AIEngine -Config $config
|
||||||
|
$voiceEngine = Initialize-VoiceEngine -Config $config
|
||||||
|
$loggingEngine = Initialize-LoggingEngine -Config $config
|
||||||
|
$pluginManager = Initialize-PluginManager -Config $config
|
||||||
|
|
||||||
|
# Set debug level if requested
|
||||||
|
if ($Debug) {
|
||||||
|
$loggingEngine.LogLevel = "Debug"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-InfoLog -Engine $loggingEngine -Message "AI Agent starting with enhanced modules"
|
||||||
|
|
||||||
|
# Load plugins
|
||||||
|
Load-AllPlugins -Manager $pluginManager
|
||||||
|
Write-InfoLog -Engine $loggingEngine -Message "Plugins loaded: $($pluginManager.LoadedPlugins.Count)"
|
||||||
|
|
||||||
|
# Initialize memory
|
||||||
|
$memory = Initialize-Memory -Config $config
|
||||||
|
|
||||||
|
# Start the agent loop
|
||||||
|
Start-AgentLoop -Config $config -Memory $memory -AIEngine $aiEngine -VoiceEngine $voiceEngine -LoggingEngine $loggingEngine -PluginManager $pluginManager
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Failed to start AI Agent: $_"
|
||||||
|
if ($Verbose) {
|
||||||
|
Write-Host "Stack trace: $($_.ScriptStackTrace)" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
exit 1
|
||||||
|
}
|
243
PowerShell_AI_Agent/PowerShell_AI_Agent/modules/AI-Engine.psm1
Normal file
243
PowerShell_AI_Agent/PowerShell_AI_Agent/modules/AI-Engine.psm1
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
# AI Engine Module for PowerShell AI Agent
|
||||||
|
# Provides AI response generation and integration capabilities
|
||||||
|
|
||||||
|
function Initialize-AIEngine {
|
||||||
|
param(
|
||||||
|
[hashtable]$Config
|
||||||
|
)
|
||||||
|
|
||||||
|
$engine = @{
|
||||||
|
Config = $Config
|
||||||
|
Context = @()
|
||||||
|
ResponsePatterns = @{
|
||||||
|
Greeting = @("Hello!", "Hi there!", "Greetings!", "Welcome!")
|
||||||
|
Farewell = @("Goodbye!", "See you later!", "Take care!", "Until next time!")
|
||||||
|
Confused = @("I'm not sure I understand.", "Could you clarify that?", "I need more information.")
|
||||||
|
Helpful = @("I'd be happy to help!", "Let me assist you with that.", "I can help you with this.")
|
||||||
|
}
|
||||||
|
Skills = @{}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Register built-in skills
|
||||||
|
Register-AISkill -Engine $engine -Name "SystemInfo" -Function "Get-SystemInformation"
|
||||||
|
Register-AISkill -Engine $engine -Name "FileOperations" -Function "Handle-FileOperations"
|
||||||
|
Register-AISkill -Engine $engine -Name "ProcessManagement" -Function "Handle-ProcessOperations"
|
||||||
|
|
||||||
|
return $engine
|
||||||
|
}
|
||||||
|
|
||||||
|
function Register-AISkill {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$Name,
|
||||||
|
[string]$Function
|
||||||
|
)
|
||||||
|
|
||||||
|
$Engine.Skills[$Name] = $Function
|
||||||
|
Write-Verbose "Registered AI skill: $Name"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-AIResponse {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$Input,
|
||||||
|
[hashtable]$Memory
|
||||||
|
)
|
||||||
|
|
||||||
|
# Analyze input for intent
|
||||||
|
$intent = Analyze-UserIntent -Input $Input
|
||||||
|
|
||||||
|
# Check for system commands
|
||||||
|
if ($intent.Type -eq "SystemCommand") {
|
||||||
|
return Execute-SystemCommand -Intent $intent -Engine $Engine
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check for skill-based requests
|
||||||
|
if ($intent.Type -eq "SkillRequest") {
|
||||||
|
return Execute-SkillRequest -Intent $intent -Engine $Engine
|
||||||
|
}
|
||||||
|
|
||||||
|
# Generate contextual response
|
||||||
|
$response = Generate-ContextualResponse -Input $Input -Intent $intent -Memory $Memory -Engine $Engine
|
||||||
|
|
||||||
|
# Add to context
|
||||||
|
$Engine.Context += @{
|
||||||
|
Input = $Input
|
||||||
|
Response = $response
|
||||||
|
Intent = $intent
|
||||||
|
Timestamp = Get-Date
|
||||||
|
}
|
||||||
|
|
||||||
|
# Limit context size
|
||||||
|
if ($Engine.Context.Count -gt 10) {
|
||||||
|
$Engine.Context = $Engine.Context | Select-Object -Last 10
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response
|
||||||
|
}
|
||||||
|
|
||||||
|
function Analyze-UserIntent {
|
||||||
|
param([string]$Input)
|
||||||
|
|
||||||
|
$input = $Input.ToLower()
|
||||||
|
|
||||||
|
# System commands
|
||||||
|
if ($input -match "^(get|show|list|display)\s+(system|computer|info|information)") {
|
||||||
|
return @{ Type = "SystemCommand"; Command = "SystemInfo"; Parameters = @{} }
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($input -match "^(get|show|list|display)\s+(process|processes)") {
|
||||||
|
return @{ Type = "SystemCommand"; Command = "ProcessList"; Parameters = @{} }
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($input -match "^(kill|stop|terminate)\s+(process|processes)") {
|
||||||
|
$processName = $input -replace "^(kill|stop|terminate)\s+(process|processes)\s+", ""
|
||||||
|
return @{ Type = "SystemCommand"; Command = "KillProcess"; Parameters = @{ ProcessName = $processName } }
|
||||||
|
}
|
||||||
|
|
||||||
|
# File operations
|
||||||
|
if ($input -match "^(list|show|dir|directory)\s+(files|files in|contents of)") {
|
||||||
|
$path = $input -replace "^(list|show|dir|directory)\s+(files|files in|contents of)\s+", ""
|
||||||
|
return @{ Type = "SystemCommand"; Command = "ListFiles"; Parameters = @{ Path = $path } }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Greetings
|
||||||
|
if ($input -match "^(hello|hi|hey|greetings)") {
|
||||||
|
return @{ Type = "Greeting"; Command = "Greet"; Parameters = @{} }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Farewells
|
||||||
|
if ($input -match "^(goodbye|bye|see you|exit|quit)") {
|
||||||
|
return @{ Type = "Farewell"; Command = "Farewell"; Parameters = @{} }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Help requests
|
||||||
|
if ($input -match "^(help|what can you do|capabilities)") {
|
||||||
|
return @{ Type = "Help"; Command = "ShowHelp"; Parameters = @{} }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Default to conversation
|
||||||
|
return @{ Type = "Conversation"; Command = "Chat"; Parameters = @{} }
|
||||||
|
}
|
||||||
|
|
||||||
|
function Execute-SystemCommand {
|
||||||
|
param(
|
||||||
|
[hashtable]$Intent,
|
||||||
|
[hashtable]$Engine
|
||||||
|
)
|
||||||
|
|
||||||
|
switch ($Intent.Command) {
|
||||||
|
"SystemInfo" {
|
||||||
|
$info = Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion, TotalPhysicalMemory, CsProcessors
|
||||||
|
return "Here's your system information:`n$($info | Format-Table | Out-String)"
|
||||||
|
}
|
||||||
|
"ProcessList" {
|
||||||
|
$processes = Get-Process | Select-Object Name, Id, CPU, WorkingSet -First 10
|
||||||
|
return "Top 10 processes by memory usage:`n$($processes | Format-Table | Out-String)"
|
||||||
|
}
|
||||||
|
"KillProcess" {
|
||||||
|
$processName = $Intent.Parameters.ProcessName
|
||||||
|
try {
|
||||||
|
$processes = Get-Process -Name $processName -ErrorAction Stop
|
||||||
|
$processes | Stop-Process -Force
|
||||||
|
return "Successfully terminated $($processes.Count) process(es) named '$processName'"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return "Error: Could not find or terminate process '$processName'"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"ListFiles" {
|
||||||
|
$path = $Intent.Parameters.Path
|
||||||
|
if ([string]::IsNullOrWhiteSpace($path)) { $path = "." }
|
||||||
|
|
||||||
|
try {
|
||||||
|
$files = Get-ChildItem -Path $path | Select-Object Name, Length, LastWriteTime
|
||||||
|
return "Files in '$path':`n$($files | Format-Table | Out-String)"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return "Error: Could not list files in '$path'"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
return "I'm not sure how to handle that system command."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Execute-SkillRequest {
|
||||||
|
param(
|
||||||
|
[hashtable]$Intent,
|
||||||
|
[hashtable]$Engine
|
||||||
|
)
|
||||||
|
|
||||||
|
$skillName = $Intent.Command
|
||||||
|
if ($Engine.Skills.ContainsKey($skillName)) {
|
||||||
|
$functionName = $Engine.Skills[$skillName]
|
||||||
|
return & $functionName -Parameters $Intent.Parameters
|
||||||
|
}
|
||||||
|
|
||||||
|
return "I don't have that skill available yet."
|
||||||
|
}
|
||||||
|
|
||||||
|
function Generate-ContextualResponse {
|
||||||
|
param(
|
||||||
|
[string]$Input,
|
||||||
|
[hashtable]$Intent,
|
||||||
|
[hashtable]$Memory,
|
||||||
|
[hashtable]$Engine
|
||||||
|
)
|
||||||
|
|
||||||
|
switch ($Intent.Type) {
|
||||||
|
"Greeting" {
|
||||||
|
$greetings = $Engine.ResponsePatterns.Greeting
|
||||||
|
return $greetings | Get-Random
|
||||||
|
}
|
||||||
|
"Farewell" {
|
||||||
|
$farewells = $Engine.ResponsePatterns.Farewell
|
||||||
|
return $farewells | Get-Random
|
||||||
|
}
|
||||||
|
"Help" {
|
||||||
|
return @"
|
||||||
|
I can help you with various tasks:
|
||||||
|
|
||||||
|
System Commands:
|
||||||
|
- Get system information
|
||||||
|
- List processes
|
||||||
|
- Kill processes
|
||||||
|
- List files in directories
|
||||||
|
|
||||||
|
Conversation:
|
||||||
|
- Chat and respond to questions
|
||||||
|
- Remember our conversation history
|
||||||
|
|
||||||
|
Try asking me to:
|
||||||
|
- "Show system information"
|
||||||
|
- "List processes"
|
||||||
|
- "What can you do?"
|
||||||
|
"@
|
||||||
|
}
|
||||||
|
"Conversation" {
|
||||||
|
# Generate contextual response based on input and memory
|
||||||
|
$context = ""
|
||||||
|
if ($Memory.entries.Count -gt 0) {
|
||||||
|
$recentEntries = $Memory.entries | Select-Object -Last 3
|
||||||
|
$context = "Based on our conversation, "
|
||||||
|
}
|
||||||
|
|
||||||
|
$responses = @(
|
||||||
|
"I understand you're asking about '$Input'. Let me help you with that.",
|
||||||
|
"That's an interesting point about '$Input'. I'd be happy to assist.",
|
||||||
|
"Regarding '$Input', I can help you explore this further.",
|
||||||
|
"I've processed your input about '$Input'. How can I best assist you?"
|
||||||
|
)
|
||||||
|
|
||||||
|
return $context + ($responses | Get-Random)
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
return "I'm processing your request: '$Input'. How can I help you further?"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Export functions
|
||||||
|
Export-ModuleMember -Function Initialize-AIEngine, Get-AIResponse, Register-AISkill
|
@ -0,0 +1,259 @@
|
|||||||
|
# Logging Engine Module for PowerShell AI Agent
|
||||||
|
# Provides comprehensive logging capabilities
|
||||||
|
|
||||||
|
function Initialize-LoggingEngine {
|
||||||
|
param(
|
||||||
|
[hashtable]$Config,
|
||||||
|
[string]$LogPath = ".\logs"
|
||||||
|
)
|
||||||
|
|
||||||
|
$engine = @{
|
||||||
|
Config = $Config
|
||||||
|
LogPath = $LogPath
|
||||||
|
LogLevel = "Info" # Debug, Info, Warning, Error
|
||||||
|
MaxLogFiles = 10
|
||||||
|
MaxLogSize = 10MB
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ensure log directory exists
|
||||||
|
if (!(Test-Path $LogPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $LogPath -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create log file name with timestamp
|
||||||
|
$timestamp = Get-Date -Format "yyyy-MM-dd"
|
||||||
|
$engine.LogFile = Join-Path $LogPath "ai-agent-$timestamp.log"
|
||||||
|
|
||||||
|
Write-Verbose "Logging engine initialized. Log file: $($engine.LogFile)"
|
||||||
|
return $engine
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-Log {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$Message,
|
||||||
|
[string]$Level = "Info",
|
||||||
|
[hashtable]$Context = @{}
|
||||||
|
)
|
||||||
|
|
||||||
|
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
$logEntry = @{
|
||||||
|
Timestamp = $timestamp
|
||||||
|
Level = $Level
|
||||||
|
Message = $Message
|
||||||
|
Context = $Context
|
||||||
|
}
|
||||||
|
|
||||||
|
# Convert to JSON for structured logging
|
||||||
|
$logLine = $logEntry | ConvertTo-Json -Compress
|
||||||
|
|
||||||
|
try {
|
||||||
|
Add-Content -Path $Engine.LogFile -Value $logLine -ErrorAction Stop
|
||||||
|
|
||||||
|
# Also write to console with color coding
|
||||||
|
$color = switch ($Level) {
|
||||||
|
"Debug" { "Gray" }
|
||||||
|
"Info" { "White" }
|
||||||
|
"Warning" { "Yellow" }
|
||||||
|
"Error" { "Red" }
|
||||||
|
default { "White" }
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "[$timestamp] [$Level] $Message" -ForegroundColor $color
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to write to log file: $_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-DebugLog {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$Message,
|
||||||
|
[hashtable]$Context = @{}
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($Engine.LogLevel -eq "Debug") {
|
||||||
|
Write-Log -Engine $Engine -Message $Message -Level "Debug" -Context $Context
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-InfoLog {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$Message,
|
||||||
|
[hashtable]$Context = @{}
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Log -Engine $Engine -Message $Message -Level "Info" -Context $Context
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-WarningLog {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$Message,
|
||||||
|
[hashtable]$Context = @{}
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Log -Engine $Engine -Message $Message -Level "Warning" -Context $Context
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-ErrorLog {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$Message,
|
||||||
|
[hashtable]$Context = @{}
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Log -Engine $Engine -Message $Message -Level "Error" -Context $Context
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-LogEntries {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[int]$Count = 50,
|
||||||
|
[string]$Level = $null,
|
||||||
|
[string]$SearchTerm = $null
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!(Test-Path $Engine.LogFile)) {
|
||||||
|
return @()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$entries = Get-Content $Engine.LogFile | ForEach-Object {
|
||||||
|
try {
|
||||||
|
$entry = $_ | ConvertFrom-Json
|
||||||
|
return $entry
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
# Skip invalid JSON entries
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
} | Where-Object { $null -ne $_ }
|
||||||
|
|
||||||
|
# Filter by level if specified
|
||||||
|
if ($Level) {
|
||||||
|
$entries = $entries | Where-Object { $_.Level -eq $Level }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Filter by search term if specified
|
||||||
|
if ($SearchTerm) {
|
||||||
|
$entries = $entries | Where-Object { $_.Message -match $SearchTerm }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return the most recent entries
|
||||||
|
return $entries | Select-Object -Last $Count
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to read log entries: $_"
|
||||||
|
return @()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Clear-LogFiles {
|
||||||
|
param([hashtable]$Engine)
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Get all log files
|
||||||
|
$logFiles = Get-ChildItem -Path $Engine.LogPath -Filter "*.log" | Sort-Object LastWriteTime -Descending
|
||||||
|
|
||||||
|
# Keep only the most recent files
|
||||||
|
if ($logFiles.Count -gt $Engine.MaxLogFiles) {
|
||||||
|
$filesToDelete = $logFiles | Select-Object -Skip $Engine.MaxLogFiles
|
||||||
|
$filesToDelete | Remove-Item -Force
|
||||||
|
|
||||||
|
Write-InfoLog -Engine $Engine -Message "Cleaned up $($filesToDelete.Count) old log files"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check log file size
|
||||||
|
$currentLog = Get-Item $Engine.LogFile -ErrorAction SilentlyContinue
|
||||||
|
if ($currentLog -and $currentLog.Length -gt $Engine.MaxLogSize) {
|
||||||
|
# Archive current log and start new one
|
||||||
|
$archiveName = $Engine.LogFile -replace "\.log$", "-$(Get-Date -Format 'HHmmss').log"
|
||||||
|
Move-Item $Engine.LogFile $archiveName
|
||||||
|
|
||||||
|
Write-InfoLog -Engine $Engine -Message "Log file archived: $archiveName"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to clean up log files: $_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Export-LogReport {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$OutputPath,
|
||||||
|
[string]$Format = "CSV"
|
||||||
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
$entries = Get-LogEntries -Engine $Engine -Count 1000
|
||||||
|
|
||||||
|
switch ($Format.ToLower()) {
|
||||||
|
"CSV" {
|
||||||
|
$entries | Export-Csv -Path $OutputPath -NoTypeInformation
|
||||||
|
}
|
||||||
|
"JSON" {
|
||||||
|
$entries | ConvertTo-Json -Depth 3 | Set-Content $OutputPath
|
||||||
|
}
|
||||||
|
"HTML" {
|
||||||
|
$html = @"
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>AI Agent Log Report</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: Arial, sans-serif; margin: 20px; }
|
||||||
|
table { border-collapse: collapse; width: 100%; }
|
||||||
|
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
|
||||||
|
th { background-color: #f2f2f2; }
|
||||||
|
.debug { background-color: #f9f9f9; }
|
||||||
|
.info { background-color: #e7f3ff; }
|
||||||
|
.warning { background-color: #fff3cd; }
|
||||||
|
.error { background-color: #f8d7da; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>AI Agent Log Report</h1>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Timestamp</th>
|
||||||
|
<th>Level</th>
|
||||||
|
<th>Message</th>
|
||||||
|
</tr>
|
||||||
|
"@
|
||||||
|
|
||||||
|
foreach ($entry in $entries) {
|
||||||
|
$class = $entry.Level.ToLower()
|
||||||
|
$html += @"
|
||||||
|
<tr class="$class">
|
||||||
|
<td>$($entry.Timestamp)</td>
|
||||||
|
<td>$($entry.Level)</td>
|
||||||
|
<td>$($entry.Message)</td>
|
||||||
|
</tr>
|
||||||
|
"@
|
||||||
|
}
|
||||||
|
|
||||||
|
$html += @"
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"@
|
||||||
|
|
||||||
|
$html | Set-Content $OutputPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-InfoLog -Engine $Engine -Message "Log report exported to: $OutputPath"
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-ErrorLog -Engine $Engine -Message "Failed to export log report: $_"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Export functions
|
||||||
|
Export-ModuleMember -Function Initialize-LoggingEngine, Write-Log, Write-DebugLog, Write-InfoLog, Write-WarningLog, Write-ErrorLog, Get-LogEntries, Clear-LogFiles, Export-LogReport
|
@ -0,0 +1,216 @@
|
|||||||
|
# Voice Engine Module for PowerShell AI Agent
|
||||||
|
# Provides speech recognition and text-to-speech capabilities
|
||||||
|
|
||||||
|
function Initialize-VoiceEngine {
|
||||||
|
param(
|
||||||
|
[hashtable]$Config
|
||||||
|
)
|
||||||
|
|
||||||
|
$engine = @{
|
||||||
|
Config = $Config
|
||||||
|
SpeechSynthesizer = $null
|
||||||
|
SpeechRecognizer = $null
|
||||||
|
IsListening = $false
|
||||||
|
VoiceEnabled = $Config.Voice.Enabled
|
||||||
|
Language = $Config.Voice.Language
|
||||||
|
ResponseSpeed = $Config.Voice.ResponseSpeed
|
||||||
|
RecognitionSensitivity = $Config.Voice.RecognitionSensitivity
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize speech synthesizer
|
||||||
|
try {
|
||||||
|
Add-Type -AssemblyName System.Speech
|
||||||
|
$engine.SpeechSynthesizer = New-Object System.Speech.Synthesis.SpeechSynthesizer
|
||||||
|
|
||||||
|
# Configure speech synthesizer
|
||||||
|
$engine.SpeechSynthesizer.Rate = Get-SpeechRate -Speed $Config.Voice.ResponseSpeed
|
||||||
|
$engine.SpeechSynthesizer.Volume = 100
|
||||||
|
|
||||||
|
Write-Verbose "Speech synthesizer initialized successfully"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to initialize speech synthesizer: $_"
|
||||||
|
$engine.VoiceEnabled = $false
|
||||||
|
}
|
||||||
|
|
||||||
|
return $engine
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-SpeechRate {
|
||||||
|
param([string]$Speed)
|
||||||
|
|
||||||
|
switch ($Speed.ToLower()) {
|
||||||
|
"slow" { return -2 }
|
||||||
|
"normal" { return 0 }
|
||||||
|
"fast" { return 2 }
|
||||||
|
"veryfast" { return 4 }
|
||||||
|
default { return 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Speak-Text {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$Text
|
||||||
|
)
|
||||||
|
|
||||||
|
if (-not $Engine.VoiceEnabled -or $null -eq $Engine.SpeechSynthesizer) {
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$Engine.SpeechSynthesizer.SpeakAsync($Text)
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to speak text: $_"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Start-SpeechRecognition {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[scriptblock]$OnSpeechRecognized
|
||||||
|
)
|
||||||
|
|
||||||
|
if (-not $Engine.VoiceEnabled) {
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Create speech recognition engine
|
||||||
|
$grammar = New-Object System.Speech.Recognition.DictationGrammar
|
||||||
|
$Engine.SpeechRecognizer = New-Object System.Speech.Recognition.SpeechRecognitionEngine
|
||||||
|
$Engine.SpeechRecognizer.LoadGrammar($grammar)
|
||||||
|
|
||||||
|
# Set recognition sensitivity
|
||||||
|
$Engine.SpeechRecognizer.SpeechRecognized += {
|
||||||
|
param($sender, $e)
|
||||||
|
if ($e.Result.Confidence -ge $Engine.RecognitionSensitivity) {
|
||||||
|
$OnSpeechRecognized.Invoke($e.Result.Text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$Engine.SpeechRecognizer.SetInputToDefaultAudioDevice()
|
||||||
|
$Engine.SpeechRecognizer.RecognizeAsync()
|
||||||
|
$Engine.IsListening = $true
|
||||||
|
|
||||||
|
Write-Host "Voice recognition started. Speak now..." -ForegroundColor Green
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to start speech recognition: $_"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Stop-SpeechRecognition {
|
||||||
|
param([hashtable]$Engine)
|
||||||
|
|
||||||
|
if ($Engine.IsListening -and $null -ne $Engine.SpeechRecognizer) {
|
||||||
|
try {
|
||||||
|
$Engine.SpeechRecognizer.RecognizeAsyncStop()
|
||||||
|
$Engine.SpeechRecognizer.Dispose()
|
||||||
|
$Engine.SpeechRecognizer = $null
|
||||||
|
$Engine.IsListening = $false
|
||||||
|
|
||||||
|
Write-Host "Voice recognition stopped." -ForegroundColor Yellow
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to stop speech recognition: $_"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-AvailableVoices {
|
||||||
|
param([hashtable]$Engine)
|
||||||
|
|
||||||
|
if ($null -eq $Engine.SpeechSynthesizer) {
|
||||||
|
return @()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return $Engine.SpeechSynthesizer.GetInstalledVoices() | ForEach-Object {
|
||||||
|
@{
|
||||||
|
Name = $_.VoiceInfo.Name
|
||||||
|
Culture = $_.VoiceInfo.Culture
|
||||||
|
Gender = $_.VoiceInfo.Gender
|
||||||
|
Age = $_.VoiceInfo.Age
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to get available voices: $_"
|
||||||
|
return @()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Set-Voice {
|
||||||
|
param(
|
||||||
|
[hashtable]$Engine,
|
||||||
|
[string]$VoiceName
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($null -eq $Engine.SpeechSynthesizer) {
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$voices = Get-AvailableVoices -Engine $Engine
|
||||||
|
$selectedVoice = $voices | Where-Object { $_.Name -eq $VoiceName }
|
||||||
|
|
||||||
|
if ($selectedVoice) {
|
||||||
|
$Engine.SpeechSynthesizer.SelectVoice($VoiceName)
|
||||||
|
Write-Host "Voice changed to: $VoiceName" -ForegroundColor Green
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Warning "Voice '$VoiceName' not found"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to set voice: $_"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-VoiceSystem {
|
||||||
|
param([hashtable]$Engine)
|
||||||
|
|
||||||
|
Write-Host "Testing voice system..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# Test speech synthesis
|
||||||
|
if ($null -ne $Engine.SpeechSynthesizer) {
|
||||||
|
Write-Host "Speech synthesizer: OK" -ForegroundColor Green
|
||||||
|
Speak-Text -Engine $Engine -Text "Voice system is working correctly."
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host "Speech synthesizer: FAILED" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test speech recognition
|
||||||
|
if ($Engine.VoiceEnabled) {
|
||||||
|
Write-Host "Speech recognition: Available" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host "Speech recognition: Disabled" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show available voices
|
||||||
|
$voices = Get-AvailableVoices -Engine $Engine
|
||||||
|
if ($voices.Count -gt 0) {
|
||||||
|
Write-Host "Available voices:" -ForegroundColor Cyan
|
||||||
|
$voices | ForEach-Object {
|
||||||
|
Write-Host " - $($_.Name) ($($_.Culture))" -ForegroundColor White
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Export functions
|
||||||
|
Export-ModuleMember -Function Initialize-VoiceEngine, Speak-Text, Start-SpeechRecognition, Stop-SpeechRecognition, Get-AvailableVoices, Set-Voice, Test-VoiceSystem
|
@ -0,0 +1,153 @@
|
|||||||
|
# Plugin Manager Module for PowerShell AI Agent
|
||||||
|
# Provides plugin loading and management capabilities
|
||||||
|
|
||||||
|
function Initialize-PluginManager {
|
||||||
|
param(
|
||||||
|
[hashtable]$Config,
|
||||||
|
[string]$PluginPath = ".\plugins"
|
||||||
|
)
|
||||||
|
|
||||||
|
$manager = @{
|
||||||
|
Config = $Config
|
||||||
|
PluginPath = $PluginPath
|
||||||
|
Plugins = @{}
|
||||||
|
LoadedPlugins = @()
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ensure plugin directory exists
|
||||||
|
if (!(Test-Path $PluginPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $PluginPath -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Verbose "Plugin manager initialized. Plugin path: $PluginPath"
|
||||||
|
return $manager
|
||||||
|
}
|
||||||
|
|
||||||
|
function Load-Plugin {
|
||||||
|
param(
|
||||||
|
[hashtable]$Manager,
|
||||||
|
[string]$PluginName
|
||||||
|
)
|
||||||
|
|
||||||
|
$pluginFile = Join-Path $Manager.PluginPath "$PluginName.ps1"
|
||||||
|
|
||||||
|
if (!(Test-Path $pluginFile)) {
|
||||||
|
Write-Warning "Plugin file not found: $pluginFile"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Load plugin script
|
||||||
|
$pluginScript = Get-Content $pluginFile -Raw
|
||||||
|
$plugin = Invoke-Expression $pluginScript
|
||||||
|
|
||||||
|
# Validate plugin structure
|
||||||
|
if (-not $plugin.Name -or -not $plugin.Version -or -not $plugin.Commands) {
|
||||||
|
Write-Warning "Invalid plugin structure: $PluginName"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Register plugin
|
||||||
|
$Manager.Plugins[$PluginName] = $plugin
|
||||||
|
$Manager.LoadedPlugins += $PluginName
|
||||||
|
|
||||||
|
Write-Host "Plugin loaded: $($plugin.Name) v$($plugin.Version)" -ForegroundColor Green
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Failed to load plugin $PluginName : $_"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Load-AllPlugins {
|
||||||
|
param([hashtable]$Manager)
|
||||||
|
|
||||||
|
$pluginFiles = Get-ChildItem -Path $Manager.PluginPath -Filter "*.ps1" -Exclude "Plugin-Manager.psm1"
|
||||||
|
|
||||||
|
foreach ($pluginFile in $pluginFiles) {
|
||||||
|
$pluginName = $pluginFile.BaseName
|
||||||
|
Load-Plugin -Manager $Manager -PluginName $pluginName
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Loaded $($Manager.LoadedPlugins.Count) plugins" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-PluginCommands {
|
||||||
|
param([hashtable]$Manager)
|
||||||
|
|
||||||
|
$commands = @()
|
||||||
|
|
||||||
|
foreach ($plugin in $Manager.Plugins.Values) {
|
||||||
|
foreach ($command in $plugin.Commands) {
|
||||||
|
$commands += @{
|
||||||
|
Name = $command.Name
|
||||||
|
Description = $command.Description
|
||||||
|
Plugin = $plugin.Name
|
||||||
|
Function = $command.Function
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $commands
|
||||||
|
}
|
||||||
|
|
||||||
|
function Execute-PluginCommand {
|
||||||
|
param(
|
||||||
|
[hashtable]$Manager,
|
||||||
|
[string]$CommandName,
|
||||||
|
[hashtable]$Parameters = @{}
|
||||||
|
)
|
||||||
|
|
||||||
|
$commands = Get-PluginCommands -Manager $Manager
|
||||||
|
$command = $commands | Where-Object { $_.Name -eq $CommandName }
|
||||||
|
|
||||||
|
if ($command) {
|
||||||
|
try {
|
||||||
|
$result = & $command.Function -Parameters $Parameters
|
||||||
|
return @{
|
||||||
|
Success = $true
|
||||||
|
Result = $result
|
||||||
|
Plugin = $command.Plugin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return @{
|
||||||
|
Success = $false
|
||||||
|
Error = $_.Exception.Message
|
||||||
|
Plugin = $command.Plugin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return @{
|
||||||
|
Success = $false
|
||||||
|
Error = "Command '$CommandName' not found"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Show-PluginInfo {
|
||||||
|
param([hashtable]$Manager)
|
||||||
|
|
||||||
|
Write-Host "Loaded Plugins:" -ForegroundColor Cyan
|
||||||
|
|
||||||
|
if ($Manager.LoadedPlugins.Count -eq 0) {
|
||||||
|
Write-Host " No plugins loaded" -ForegroundColor Yellow
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($pluginName in $Manager.LoadedPlugins) {
|
||||||
|
$plugin = $Manager.Plugins[$pluginName]
|
||||||
|
Write-Host " $($plugin.Name) v$($plugin.Version)" -ForegroundColor White
|
||||||
|
Write-Host " Description: $($plugin.Description)" -ForegroundColor Gray
|
||||||
|
Write-Host " Commands: $($plugin.Commands.Count)" -ForegroundColor Gray
|
||||||
|
|
||||||
|
foreach ($command in $plugin.Commands) {
|
||||||
|
Write-Host " - $($command.Name): $($command.Description)" -ForegroundColor Gray
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Export functions
|
||||||
|
Export-ModuleMember -Function Initialize-PluginManager, Load-Plugin, Load-AllPlugins, Get-PluginCommands, Execute-PluginCommand, Show-PluginInfo
|
125
PowerShell_AI_Agent/PowerShell_AI_Agent/plugins/System-Tools.ps1
Normal file
125
PowerShell_AI_Agent/PowerShell_AI_Agent/plugins/System-Tools.ps1
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
@{
|
||||||
|
Name = "System Tools"
|
||||||
|
Version = "1.0"
|
||||||
|
Description = "Provides system utility commands for the AI agent"
|
||||||
|
Author = "AI Agent Team"
|
||||||
|
Commands = @(
|
||||||
|
@{
|
||||||
|
Name = "Get-SystemStatus"
|
||||||
|
Description = "Get comprehensive system status information"
|
||||||
|
Function = {
|
||||||
|
param([hashtable]$Parameters)
|
||||||
|
|
||||||
|
$status = @{
|
||||||
|
ComputerName = $env:COMPUTERNAME
|
||||||
|
OS = (Get-ComputerInfo).WindowsProductName
|
||||||
|
Version = (Get-ComputerInfo).WindowsVersion
|
||||||
|
Uptime = (Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
|
||||||
|
CPU = (Get-CimInstance Win32_Processor).Name
|
||||||
|
Memory = [math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB, 2)
|
||||||
|
DiskSpace = Get-WmiObject Win32_LogicalDisk | ForEach-Object {
|
||||||
|
[math]::Round($_.Size / 1GB, 2)
|
||||||
|
}
|
||||||
|
FreeSpace = Get-WmiObject Win32_LogicalDisk | ForEach-Object {
|
||||||
|
[math]::Round($_.FreeSpace / 1GB, 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "System Status:`n" +
|
||||||
|
"Computer: $($status.ComputerName)`n" +
|
||||||
|
"OS: $($status.OS) $($status.Version)`n" +
|
||||||
|
"Uptime: $($status.Uptime.Days) days, $($status.Uptime.Hours) hours`n" +
|
||||||
|
"CPU: $($status.CPU)`n" +
|
||||||
|
"Memory: $($status.Memory) GB`n" +
|
||||||
|
"Disk Space: $($status.DiskSpace) GB`n" +
|
||||||
|
"Free Space: $($status.FreeSpace) GB"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
@{
|
||||||
|
Name = "Get-NetworkInfo"
|
||||||
|
Description = "Get network configuration and status"
|
||||||
|
Function = {
|
||||||
|
param([hashtable]$Parameters)
|
||||||
|
|
||||||
|
$network = Get-NetAdapter | Where-Object { $_.Status -eq "Up" }
|
||||||
|
$ipConfig = Get-NetIPAddress | Where-Object { $_.AddressFamily -eq "IPv4" }
|
||||||
|
|
||||||
|
$result = "Network Information:`n"
|
||||||
|
foreach ($adapter in $network) {
|
||||||
|
$ip = $ipConfig | Where-Object { $_.InterfaceIndex -eq $adapter.InterfaceIndex }
|
||||||
|
$result += "Adapter: $($adapter.Name)`n"
|
||||||
|
$result += "Status: $($adapter.Status)`n"
|
||||||
|
$result += "IP: $($ip.IPAddress)`n"
|
||||||
|
$result += "Speed: $($adapter.LinkSpeed)`n`n"
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
},
|
||||||
|
@{
|
||||||
|
Name = "Get-ServiceStatus"
|
||||||
|
Description = "Get status of important Windows services"
|
||||||
|
Function = {
|
||||||
|
param([hashtable]$Parameters)
|
||||||
|
|
||||||
|
$services = @("spooler", "themes", "wsearch", "wuauserv", "bits")
|
||||||
|
$result = "Service Status:`n"
|
||||||
|
|
||||||
|
foreach ($service in $services) {
|
||||||
|
try {
|
||||||
|
$svc = Get-Service -Name $service -ErrorAction Stop
|
||||||
|
$status = $svc.Status
|
||||||
|
$color = if ($status -eq "Running") { "Green" } else { "Red" }
|
||||||
|
$result += "$service`: $status`n"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$result += "$service`: Not Found`n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
},
|
||||||
|
@{
|
||||||
|
Name = "Get-ProcessInfo"
|
||||||
|
Description = "Get detailed information about running processes"
|
||||||
|
Function = {
|
||||||
|
param([hashtable]$Parameters)
|
||||||
|
|
||||||
|
$processes = Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
|
||||||
|
$result = "Top 10 Processes by CPU:`n"
|
||||||
|
|
||||||
|
foreach ($process in $processes) {
|
||||||
|
$cpu = [math]::Round($process.CPU, 2)
|
||||||
|
$memory = [math]::Round($process.WorkingSet / 1MB, 2)
|
||||||
|
$result += "$($process.Name): CPU=$cpu, Memory=${memory}MB`n"
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
},
|
||||||
|
@{
|
||||||
|
Name = "Test-Connectivity"
|
||||||
|
Description = "Test network connectivity to common services"
|
||||||
|
Function = {
|
||||||
|
param([hashtable]$Parameters)
|
||||||
|
|
||||||
|
$hosts = @("8.8.8.8", "1.1.1.1", "google.com", "microsoft.com")
|
||||||
|
$result = "Connectivity Test:`n"
|
||||||
|
|
||||||
|
foreach ($host in $hosts) {
|
||||||
|
try {
|
||||||
|
$ping = Test-Connection -ComputerName $host -Count 1 -Quiet
|
||||||
|
$status = if ($ping) { "OK" } else { "FAILED" }
|
||||||
|
$result += "$host`: $status`n"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$result += "$host`: ERROR`n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
313
PowerShell_AI_Agent/PowerShell_AI_Agent/tests/Test-AIAgent.ps1
Normal file
313
PowerShell_AI_Agent/PowerShell_AI_Agent/tests/Test-AIAgent.ps1
Normal file
@ -0,0 +1,313 @@
|
|||||||
|
# Test Script for PowerShell AI Agent
|
||||||
|
# Comprehensive testing of all components
|
||||||
|
|
||||||
|
param(
|
||||||
|
[switch]$Verbose,
|
||||||
|
[switch]$SkipVoice,
|
||||||
|
[string]$ConfigPath = ".\config\agent-config.json"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Import modules
|
||||||
|
$modulePath = ".\modules"
|
||||||
|
if (Test-Path $modulePath) {
|
||||||
|
Import-Module "$modulePath\AI-Engine.psm1" -Force
|
||||||
|
Import-Module "$modulePath\Voice-Engine.psm1" -Force
|
||||||
|
Import-Module "$modulePath\Logging-Engine.psm1" -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
# Import plugin manager
|
||||||
|
$pluginPath = ".\plugins"
|
||||||
|
if (Test-Path $pluginPath) {
|
||||||
|
Import-Module "$pluginPath\Plugin-Manager.psm1" -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-Configuration {
|
||||||
|
Write-Host "Testing Configuration..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
try {
|
||||||
|
$config = Get-Content $ConfigPath -Raw | ConvertFrom-Json
|
||||||
|
Write-Host "✓ Configuration loaded successfully" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Test required sections
|
||||||
|
$requiredSections = @("AI", "Voice", "Memory", "Autopilot")
|
||||||
|
foreach ($section in $requiredSections) {
|
||||||
|
if ($config.$section) {
|
||||||
|
Write-Host "✓ $section section present" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ $section section missing" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "✗ Configuration test failed: $_" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-AIEngine {
|
||||||
|
Write-Host "Testing AI Engine..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
try {
|
||||||
|
$config = Get-Content $ConfigPath -Raw | ConvertFrom-Json
|
||||||
|
$aiEngine = Initialize-AIEngine -Config $config
|
||||||
|
Write-Host "✓ AI Engine initialized" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Test response generation
|
||||||
|
$response = Get-AIResponse -Engine $aiEngine -Input "Hello" -Memory @{ entries = @() }
|
||||||
|
if ($response) {
|
||||||
|
Write-Host "✓ AI response generation working" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ AI response generation failed" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test system commands
|
||||||
|
$systemResponse = Get-AIResponse -Engine $aiEngine -Input "Show system information" -Memory @{ entries = @() }
|
||||||
|
if ($systemResponse -and $systemResponse.Contains("system information")) {
|
||||||
|
Write-Host "✓ System command processing working" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ System command processing failed" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "✗ AI Engine test failed: $_" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-VoiceEngine {
|
||||||
|
if ($SkipVoice) {
|
||||||
|
Write-Host "Skipping Voice Engine test..." -ForegroundColor Yellow
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Testing Voice Engine..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
try {
|
||||||
|
$config = Get-Content $ConfigPath -Raw | ConvertFrom-Json
|
||||||
|
$voiceEngine = Initialize-VoiceEngine -Config $config
|
||||||
|
|
||||||
|
if ($voiceEngine.VoiceEnabled) {
|
||||||
|
Write-Host "✓ Voice Engine initialized" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Test speech synthesis
|
||||||
|
$speakResult = Speak-Text -Engine $voiceEngine -Text "Voice test successful"
|
||||||
|
if ($speakResult) {
|
||||||
|
Write-Host "✓ Speech synthesis working" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "⚠ Speech synthesis not available" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test voice availability
|
||||||
|
$voices = Get-AvailableVoices -Engine $voiceEngine
|
||||||
|
if ($voices.Count -gt 0) {
|
||||||
|
Write-Host "✓ $($voices.Count) voices available" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "⚠ No voices available" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "⚠ Voice Engine disabled in configuration" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "✗ Voice Engine test failed: $_" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-LoggingEngine {
|
||||||
|
Write-Host "Testing Logging Engine..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
try {
|
||||||
|
$config = Get-Content $ConfigPath -Raw | ConvertFrom-Json
|
||||||
|
$loggingEngine = Initialize-LoggingEngine -Config $config
|
||||||
|
Write-Host "✓ Logging Engine initialized" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Test log writing
|
||||||
|
Write-InfoLog -Engine $loggingEngine -Message "Test log entry"
|
||||||
|
Write-WarningLog -Engine $loggingEngine -Message "Test warning"
|
||||||
|
Write-ErrorLog -Engine $loggingEngine -Message "Test error"
|
||||||
|
|
||||||
|
# Test log reading
|
||||||
|
$entries = Get-LogEntries -Engine $loggingEngine -Count 5
|
||||||
|
if ($entries.Count -gt 0) {
|
||||||
|
Write-Host "✓ Log writing and reading working" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ Log reading failed" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "✗ Logging Engine test failed: $_" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-PluginManager {
|
||||||
|
Write-Host "Testing Plugin Manager..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
try {
|
||||||
|
$config = Get-Content $ConfigPath -Raw | ConvertFrom-Json
|
||||||
|
$pluginManager = Initialize-PluginManager -Config $config
|
||||||
|
Write-Host "✓ Plugin Manager initialized" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Load plugins
|
||||||
|
Load-AllPlugins -Manager $pluginManager
|
||||||
|
|
||||||
|
if ($pluginManager.LoadedPlugins.Count -gt 0) {
|
||||||
|
Write-Host "✓ $($pluginManager.LoadedPlugins.Count) plugins loaded" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Test plugin commands
|
||||||
|
$commands = Get-PluginCommands -Manager $pluginManager
|
||||||
|
if ($commands.Count -gt 0) {
|
||||||
|
Write-Host "✓ $($commands.Count) plugin commands available" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Test a plugin command
|
||||||
|
$testCommand = $commands[0]
|
||||||
|
$result = Execute-PluginCommand -Manager $pluginManager -CommandName $testCommand.Name
|
||||||
|
if ($result.Success) {
|
||||||
|
Write-Host "✓ Plugin command execution working" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "⚠ Plugin command execution failed: $($result.Error)" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "⚠ No plugin commands available" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "⚠ No plugins loaded" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "✗ Plugin Manager test failed: $_" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-MemorySystem {
|
||||||
|
Write-Host "Testing Memory System..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
try {
|
||||||
|
$config = Get-Content $ConfigPath -Raw | ConvertFrom-Json
|
||||||
|
|
||||||
|
# Test memory initialization
|
||||||
|
$memory = @{
|
||||||
|
entries = @()
|
||||||
|
lastUpdated = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
version = "1.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test memory operations
|
||||||
|
$memory.entries += @{
|
||||||
|
input = "Test input"
|
||||||
|
response = "Test response"
|
||||||
|
timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($memory.entries.Count -eq 1) {
|
||||||
|
Write-Host "✓ Memory operations working" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ Memory operations failed" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "✗ Memory System test failed: $_" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-Integration {
|
||||||
|
Write-Host "Testing Integration..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
try {
|
||||||
|
$config = Get-Content $ConfigPath -Raw | ConvertFrom-Json
|
||||||
|
|
||||||
|
# Initialize all engines
|
||||||
|
$aiEngine = Initialize-AIEngine -Config $config
|
||||||
|
$voiceEngine = Initialize-VoiceEngine -Config $config
|
||||||
|
$loggingEngine = Initialize-LoggingEngine -Config $config
|
||||||
|
$pluginManager = Initialize-PluginManager -Config $config
|
||||||
|
|
||||||
|
# Test integrated workflow
|
||||||
|
Write-InfoLog -Engine $loggingEngine -Message "Integration test started"
|
||||||
|
|
||||||
|
$memory = @{ entries = @() }
|
||||||
|
$response = Get-AIResponse -Engine $aiEngine -Input "Integration test" -Memory $memory
|
||||||
|
|
||||||
|
Write-InfoLog -Engine $loggingEngine -Message "Integration test completed"
|
||||||
|
|
||||||
|
if ($response) {
|
||||||
|
Write-Host "✓ Integration test passed" -ForegroundColor Green
|
||||||
|
return $true
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ Integration test failed" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "✗ Integration test failed: $_" -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main test execution
|
||||||
|
function Start-TestSuite {
|
||||||
|
Write-Host "=== PowerShell AI Agent Test Suite ===" -ForegroundColor Green
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
$tests = @(
|
||||||
|
@{ Name = "Configuration"; Function = "Test-Configuration" },
|
||||||
|
@{ Name = "AI Engine"; Function = "Test-AIEngine" },
|
||||||
|
@{ Name = "Voice Engine"; Function = "Test-VoiceEngine" },
|
||||||
|
@{ Name = "Logging Engine"; Function = "Test-LoggingEngine" },
|
||||||
|
@{ Name = "Plugin Manager"; Function = "Test-PluginManager" },
|
||||||
|
@{ Name = "Memory System"; Function = "Test-MemorySystem" },
|
||||||
|
@{ Name = "Integration"; Function = "Test-Integration" }
|
||||||
|
)
|
||||||
|
|
||||||
|
$passed = 0
|
||||||
|
$total = $tests.Count
|
||||||
|
|
||||||
|
foreach ($test in $tests) {
|
||||||
|
Write-Host "Running $($test.Name) test..." -ForegroundColor White
|
||||||
|
$result = & $test.Function
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$passed++
|
||||||
|
Write-Host "✓ $($test.Name) test PASSED" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ $($test.Name) test FAILED" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# Summary
|
||||||
|
Write-Host "=== Test Summary ===" -ForegroundColor Cyan
|
||||||
|
Write-Host "Passed: $passed/$total" -ForegroundColor $(if ($passed -eq $total) { "Green" } else { "Yellow" })
|
||||||
|
|
||||||
|
if ($passed -eq $total) {
|
||||||
|
Write-Host "All tests passed! AI Agent is ready to use." -ForegroundColor Green
|
||||||
|
return $true
|
||||||
|
} else {
|
||||||
|
Write-Host "Some tests failed. Please check the issues above." -ForegroundColor Red
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
Start-TestSuite
|
Loading…
Reference in New Issue
Block a user