Skip to content

PowerShell script simulates a team of AI Agents working together on a user provided PowerShell project. It utilizes Retrieval-Augmented Generation (RAG). The project leverages Azure OpenAI, Ollama, and LM Studio.

Notifications You must be signed in to change notification settings

voytas75/AIPSTeam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI PowerShell Team with RAG

AIPSTeam

ko-fi

PowerShell Gallery Codacy Badge

Table of Contents

Overview

This PowerShell script simulates a team of AI Agents working together on a PowerShell project. Each Agent has a unique role and contributes to the project in a sequential manner. The script processes user input, performs various tasks, and generates outputs such as code, documentation, and analysis reports. The application utilizes Retrieval-Augmented Generation (RAG) to enhance its capabilities and can leverage Azure OpenAI, Ollama, or LM Studio to generate the output.

For more information on the AI models and services used in this script, please refer to the following links:

Important

You need AZURE OpenAI subscription, Ollama or LMStudio to use this script.

The quality of the project generated by the AI PowerShell Team depends significantly on the model used and the context window available. The model's ability to understand and process the input accurately is crucial for generating high-quality outputs. Ensure that the model and context window settings are optimized for the best performance and results.

Retrieval-Augmented Generation (RAG)

RAG combines retrieval and generation processes to produce accurate and contextually relevant outputs. The framework operates as follows:

  1. Retrieval: The system retrieves pertinent information from extensive data sources.
  2. Generation: A generative model uses the retrieved information to produce coherent and appropriate responses.

By integrating these two phases, RAG ensures the AI specialists deliver precise and informed outputs based on a comprehensive knowledge base.

Data Source for RAG

The AI PowerShell Team utilizes the Bing Web Search API as the primary data source for its Retrieval-Augmented Generation (RAG) capabilities. This API enables the system to retrieve relevant information from billions of web documents, ensuring that the generated outputs are accurate and contextually relevant.

For more information on the Bing Web Search API, please refer to the following link:

By leveraging the Bing Web Search API, the AI PowerShell Team can provide enhanced search details, safe and location-aware search results, and a variety of instant answers, including images, videos, news, and more. This integration significantly improves the quality and relevance of the outputs generated by the AI Agents.

Features

  • Team Simulation: Emulates a team of specialists including Requirements Analyst, System Architect, PowerShell Developer, QA Engineer, Documentation Specialist, and Project Manager.
  • Sequential Processing: Each specialist processes the input and passes the result to the next specialist in the workflow.
  • Live Streaming: Option to stream output live.
  • Logging: Logs actions and responses of each specialist.
  • Documentation Generation: Automatically generates comprehensive documentation for the project.
  • Code Analysis: Integrates with PSScriptAnalyzer for code quality checks.
  • Feedback Integration: Collects and integrates feedback from team members to improve the response.
  • State Management: Manages global state across different stages of the project.
  • Error Handling: Robust error handling mechanisms to capture and log errors.
  • Version Control: Saves and updates code versions with detailed logs.
  • Interactive Menu: Provides an interactive menu for suggesting new features, analyzing code, generating documentation, and more. This menu can be disabled by enabling Non-Interactive Mode.
  • Input Check: Checks user input and tests if clarification and more context are needed to ensure comprehensive understanding and accurate processing.
  • Non-Interactive Mode: Disables all interaction functionality, allowing the script to run the entire team collaboration workflow without requiring any user input or displaying any menus during the session.
  • User Code Support: Allows the team to work directly on user-provided PowerShell code instead of just a project description, enhancing the ability to debug, optimize, and extend existing scripts.

User Guide

Installation

  1. Install Required Modules: Ensure you have the required PowerShell modules installed:

    Install-Module -Name PSAOAI
    Install-Module -Name PSScriptAnalyzer
    Install-Module -Name powerHTML
  2. Install the Script: Install script from Powershell Gallery.

    Install-Script AIPSTeam
  3. Run the Script: Execute the script using PowerShell:

    "Your project description here" | AIPSTeam.ps1

Configuration

  • Parameters:
    • userInput: Defines the project outline as a string (can also be piped).
    • Stream: Controls whether the output should be streamed live (default: $true).
    • NOPM: Disables the Project Manager functions.
    • NODocumentator: Disables the Documentator functions.
    • NOLog: Disables the logging functions.
    • LogFolder: Specifies the folder where logs should be stored.
    • DeploymentChat: Specifies the deployment chat environment variable for Azure OpenAI (default: retrieved from environment variable PSAOAI_API_AZURE_OPENAI_CC_DEPLOYMENT - PSAOAI).
    • MaxTokens: Specifies the maximum number of tokens to generate in the response. This parameter controls the length of the generated output. The default value is set within the script, but it can be overridden by the user if needed.
    • LLMProvider: Specifies the LLM provider to use (e.g., ollama, LMStudio, AzureOpenAI). Default is "AzureOpenAI".
    • NOTips: Disables tips.
    • VerbosePrompt: Show Prompts.
    • LoadProjectStatus: Loads the project status from a specified path. Part of the 'LoadStatus' parameter set.
    • LLMProvider: Specifies the LLM provider to use (e.g., ollama, LMStudio, AzureOpenAI). Default is "AzureOpenAI".
    • NORAG: Disables the RAG (Retrieve and Generate) functionality.
    • NOUserInputCheck: Disables the input check.
    • NOInteraction: Disable the interaction.
    • TheCodePath: Specifies the path to the user code to be processed by the AI Team.

Environment Variables

To configure the script to use external providers, you need to set the following environment variables:

  1. Azure OpenAI:

    • PSAOAI_API_AZURE_OPENAI_KEY: Your Azure OpenAI API key.
    • PSAOAI_API_AZURE_OPENAI_ENDPOINT: Your Azure OpenAI endpoint.
    • PSAOAI_API_AZURE_OPENAI_APIVERSION: The version of the Azure OpenAI API you want to use.
    • PSAOAI_API_AZURE_OPENAI_CC_DEPLOYMENT: Your Azure OpenAI Chat Completion deployment name.
    • PSAOAI_BANNER: Disable PSAOAI banner. AIPSTeam sets to "0".

    When you start the script, you will be prompted to provide these environment variables if they are not already set. Alternatively, you can set them earlier to avoid prompts during execution. Additionally, ensure that you have the latest version of the PSAOAI module installed to avoid compatibility issues. You can check for updates and install the latest version using the following command:

    Install-Module -Name PSAOAI

    Example:

    [Environment]::SetEnvironmentVariable('PSAOAI_API_AZURE_OPENAI_ENDPOINT','https://<your-endpoint>.openai.azure.com','user')
    [Environment]::SetEnvironmentVariable('PSAOAI_API_AZURE_OPENAI_APIVERSION','2024-05-01-preview','user')
    [Environment]::SetEnvironmentVariable('PSAOAI_API_AZURE_OPENAI_CC_DEPLOYMENT','your-deployment-name','user')

Important

The PSAOAI_API_AZURE_OPENAI_KEY environment variable cannot be provided manually because the PSAOAI module encrypts it for security purposes. Ensure that the key is set and managed through the PSAOAI module's secure mechanisms.

  1. Ollama:
    • OLLAMA_ENDPOINT: Ollama API Endpoint.
    • OLLAMA_MODEL: Ollama model.

The OLLAMA_ENDPOINT environment variable is set to a default value of http://localhost:11434/ by the script. If you need to use a different endpoint, you must manually change the value of this environment variable. You can do this by using the following command:

[Environment]::SetEnvironmentVariable('OLLAMA_ENDPOINT','your-ollama-api-endpoint-uri','user')

Important

For the Ollama provider, you do not need to manually define the OLLAMA_MODEL environment variable. The script will automatically check the status of Ollama and interactively prompt you to start and choose the model to use if it is not already running. This ensures a seamless setup process and reduces the need for manual.

Example:

[Environment]::SetEnvironmentVariable('OLLAMA_MODEL','ollama model, example: phi3:latest','user')
  1. LM Studio:

    • OPENAI_API_KEY: Your LM Studio API key, default is 'lm-studio'.
    • OPENAI_API_BASE : The LLM model to use with LM Studio, default is 'http://localhost:1234/v1'.

    Example:

    [Environment]::SetEnvironmentVariable('OPENAI_API_KEY','lm-studio','user')
    [Environment]::SetEnvironmentVariable('OPENAI_API_BASE','http://localhost:1234/v1','user')
  2. RAG Configuration:

    • AZURE_BING_API_KEY: Your Azure Bing Web Search API key.
    • AZURE_BING_ENDPOINT: Your Azure Bing Web Search endpoint. ()

    Example:

    [Environment]::SetEnvironmentVariable('AZURE_BING_API_KEY','your-azure-bing-api-key','user')
    [Environment]::SetEnvironmentVariable('AZURE_BING_ENDPOINT','https://api.bing.microsoft.com/','user')

Bing Search API documentation

Ensure these environment variables are set before running the script to enable the respective functionalities.

Usage

  1. Basic Usage:

    "Monitor RAM usage and show a single color block based on the load." | AIPSTeam.ps1

    or

    AIPSTeam -userInput "Monitor RAM usage and show a single color block based on the load."
  2. Disable Live Streaming:

    "Monitor RAM usage" | AIPSTeam.ps1 -Stream $false
  3. Specify Log Folder:

    "Monitor RAM usage" | AIPSTeam.ps1 -LogFolder "C:\Logs"
  4. Monitor Disk Usage:

    "Monitor disk usage and display a pie chart of used vs free space." | AIPSTeam.ps1 -Stream $false

    Description: This example monitors the disk usage and displays a pie chart showing the used versus free space. The -Stream $false parameter disables live streaming of the output.

  5. Generate System Report:

    "Script for reporting CPU, RAM, and disk usage." | AIPSTeam -LogFolder "C:\SystemReports"

    Description: This example generates a comprehensive system report that includes details about CPU, RAM, and disk usage. The report is saved in the specified log folder C:\SystemReports.

  6. Check Network Latency:

    "Check network latency and display a line graph of latency over time." | AIPSTeam.ps1 -NOPM

    Description: This example checks the network latency and displays a line graph showing the latency over time. The -NOPM parameter disables the Project Manager functions.

  7. Analyze Event Logs:

    "Analyze Windows Event Logs and summarize critical errors." | AIPSTeam.ps1 -NODocumentator

    Description: This example analyzes the Windows Event Logs and provides a summary of critical errors. The -NODocumentator parameter disables the Documentator functions.

  8. Backup Important Files:

    "Backup important files from Documents to an external drive." | AIPSTeam -NOLog

    Description: This example backs up important files from the Documents folder to an external drive. The -NOLog parameter disables the logging functions.

  9. Monitor GPU Usage:

    "Monitor GPU usage and display a bar chart of GPU load." | AIPSTeam -Stream $true

    Description: This example monitors the GPU usage and displays a bar chart showing the GPU load. The -Stream $true parameter enables live streaming of the output.

  10. Check System Uptime:

    "Check system uptime and display the total uptime in days." | AIPSTeam.ps1 -NOLog -NOPM

    Description: This example checks the system uptime and displays the total uptime in days. The -NOLog parameter disables the logging functions, and the -NOPM parameter disables the Project Manager functions.

  11. Generate Security Audit Report:

    "Generate a security audit report for the system." | AIPSTeam.ps1 -LogFolder "C:\SecurityReports" -NODocumentator

    Description: This example generates a security audit report for the system. The report is saved in the specified log folder C:\SecurityReports. The -NODocumentator parameter disables the Documentator functions.

  12. Monitor Network Bandwidth:

    "Monitor network bandwidth usage and display a real-time graph." | AIPSTeam.ps1 -Stream $true -NOLog

    Description: This example monitors the network bandwidth usage and displays a real-time graph. The -Stream $true parameter enables live streaming of the output, and the -NOLog parameter disables the logging functions.

  13. Check Disk Health:

    "Check disk health and display a summary of SMART attributes." | AIPSTeam -NOPM -NODocumentator

    Description: This example checks the disk health and displays a summary of SMART attributes. The -NOPM parameter disables the Project Manager functions, and the -NODocumentator parameter disables the Documentator functions.

  14. Generate Text Summary Using LLM Provider:

    "Recent software activities on Windows 11." | AIPSTeam -LLMProvider "ollama" -Stream $false

    Description: This example generates a text summary of recent project activities using the specified LLM provider, in this case, "ollama". The -Stream $false parameter disables live streaming of the output.

  15. Run Script Without User Input Check:

    "Cleaning folders where is file 'clean.it'" | AIPSTeam.ps1 -NOUserInputCheck

    Description: This example runs the script without performing any user input checks. The -NOUserInputCheck parameter disables the input validation functions.

  16. Run Script with Disabled Interaction:

    "Generate a daily system health report." | AIPSTeam.ps1 -NOInteraction

    Description: This example runs the script without requiring any user interaction throughout the session. The -NOInteraction parameter ensures that the script will not prompt the user for any input or display any menus.

  17. Work on User's Code:

    AIPSTeam.ps1 -TheCodePath "C:\UserScripts\script.ps1"

    Description: This example works on the user's provided PowerShell script located at C:\UserScripts\script.ps1. The -TheCodePath parameter specifies the path to the user code that the AI team will enhance. If interactive mode is not disabled, the user can provide additional instructions during the session, such as "adding additional logging functionality".

Developer Notes

Code Structure

  • Main Script: AIPSTeam.ps1
  • Classes: ProjectTeam
  • Functions: Various utility functions for processing input, logging, and analysis.

Key Functions and Logic

  • ProjectTeam Class: Represents a team member with specific expertise.
    • ProcessInput: Processes the input and generates a response.
    • Feedback: Provides feedback on the input.
    • AddLogEntry: Adds an entry to the log.
    • Notify: Sends a notification.
    • SummarizeMemory: Summarizes the team member's memory.
  • Utility Functions:
    • SendFeedbackRequest: Sends a feedback request to a team member.
    • Invoke-CodeWithPSScriptAnalyzer: Analyzes the code using PSScriptAnalyzer.
    • Export-AndWritePowerShellCodeBlocks: Exports and writes PowerShell code blocks to a file.

Installation Instructions

Installation

Dependencies and Prerequisites

  • PowerShell Version: Ensure you are using PowerShell 5.1 or later.
  • Modules:
    • PSAOAI
    • PSScriptAnalyzer
    • PowerHTML

Troubleshooting Tips and Common Issues

  • Module Not Found: Ensure the required modules are installed using Install-Module.
  • Permission Issues: Run PowerShell as an administrator.
  • Script Errors: Check the log files in the specified log folder for detailed error messages.

FAQ

  1. How do I install the required modules?

    Install-Module -Name PSAOAI
    Install-Module -Name PSScriptAnalyzer
    Install-Module -Name powerHTML
  2. How do I disable live streaming?

    AIPSTeam.ps1 -Stream $false
  3. Where are the log files stored?

    Log files are stored in the specified log folder or the default folder in MyDocuments.

  4. How do I load a saved project status?

    AIPSTeam.ps1 -LoadProjectStatus "path\to\your\Project.xml"
  5. How do I disable the Project Manager functions?

    AIPSTeam.ps1 -NOPM
  6. How do I specify a custom LLM model for ollama?

    $env:OLLAMA_MODEL = "your_custom_model"
    AIPSTeam.ps1 -LLMProvider "ollama"

About

PowerShell script simulates a team of AI Agents working together on a user provided PowerShell project. It utilizes Retrieval-Augmented Generation (RAG). The project leverages Azure OpenAI, Ollama, and LM Studio.

Topics

Resources

Stars

Watchers

Forks