AI Infrastructure Agent

repository·main·Indexed 42 days ago

https://github.com/versuscontrol/ai-infrastructure-agent

An AI-powered infrastructure management agent for AWS that translates natural language intent into executable operations. It supports multiple AI providers including OpenAI, Google Gemini, Anthropic, AWS Bedrock Nova, and Ollama. The system features a web dashboard for real-time monitoring, dependency graph visualization, and a safety-first workflow utilizing dry-runs, conflict detection, and user approval before executing changes to resources like VPC, EC2, Security Groups, Auto Scaling Groups, and ALBs.

Tokens
21K
Snippets
59
Records
98
Agent score
54%

What's inside AI Infrastructure Agent

  1. Overview of AI Infrastructure Agent

    main

    The AI Infrastructure Agent is an intelligent system designed to manage AWS infrastructure using natural language commands. Instead of writing complex infrastructure-as-code, users can describe their desired state in plain English. The agent maintains a Terraform-like state to ensure accuracy and includes conflict detection and dry-run modes to provide safety during infrastructure changes.

    Key Capabilities:

    • Natural Language Interface: Describe infrastructure requirements directly.
    • Multi-AI Provider Support: Compatible with OpenAI, Google Gemini, Anthropic, AWS Bedrock Nova, and Ollama (for local LLM execution).
    • AWS Resource Management: Supports VPC, EC2, Security Groups, Auto Scaling Groups, and ALBs.
    • Web Dashboard: Provides a visual interface for managing infrastructure.
  2. Overview of the testing architecture and mock system

    main

    The project uses a sophisticated mock system to provide realistic testing environments without hitting live AWS endpoints. The testing architecture integrates real production logic (like pattern matching and field resolution) with the following mock components:

    • MockMCPServer: Simulates a complete MCP server with 50+ tools.
    • MockStateManager: Simulates state management including real resource analysis.
    • MockAWSClient: Simulates AWS API responses.
    • MockAdapters: Provides service-specific mocks for isolated testing.
  3. How the AI Agent manages resource state and reuse

    main
    The AI Infrastructure Agent uses a state-tracking mechanism to intelligently reuse resources created in previous phases. When you request a new component (like a Load Balancer), the agent automatically identifies and references existing resource IDs (such as Security Group IDs or Subnet IDs) from the current state, eliminating the need for manual ID specification in your natural language prompts.
  4. Understand the MCP Layer and Tooling

    main

    The Model Context Protocol (MCP) layer acts as the standardized interface between AI models and infrastructure tools.

    MCP Server & Tool Manager:

    • Implements the full MCP specification.
    • Uses a Tool Factory Pattern for dynamic tool creation and lifecycle management.
    • Enables Capability Discovery, allowing the AI to enumerate available tools at runtime.

    Tools Layer: Provides over 50 specialized tools for AWS operations, including:

    • EC2 & VPC: Instance lifecycle and network infrastructure.
    • Security & Load Balancing: Firewall rules (Security Groups) and ALB operations.
    • Auto Scaling & RDS: ASG management and database operations.
    • State & Discovery: Infrastructure analysis and resource correlation.

    All tools implement the MCPTool interface, providing a standardized way to execute commands and retrieve schemas.

    type MCPTool interface {
        Execute(ctx context.Context, args map[string]interface{}) (*mcp.CallToolResult, error)
        GetSchema() map[string]interface{}
        GetMetadata() ToolMetadata
    }
  5. How the AI Infrastructure Agent works

    main

    The agent operates through a multi-step lifecycle to ensure safe infrastructure management:

    1. AI Analysis & Planning: The agent receives a natural language request, retrieves the current infrastructure state, queries available tools via the MCP Server, and generates an execution plan using an LLM.
    2. Plan Validation: The plan is validated against AWS (dry-run checks) to ensure feasibility.
    3. User Approval: The agent presents the detailed plan to the user via the Web Dashboard. No changes are made until the user approves.
    4. Execution & Monitoring: Upon approval, the agent executes the plan, creating resources in the correct dependency order and monitoring progress in real-time.
  6. How the AI Agent handles execution errors

    main

    If the AI agent encounters an error during infrastructure deployment (e.g., due to environment mismatches or AWS state conflicts), it features a built-in recovery mechanism.

    When an error occurs, the agent automatically triggers a recovery plan to analyze the failure and attempt to fix the issue. Users can review the recovery steps and choose to either let the agent proceed with the fix or skip the problematic step if the core infrastructure is already in the desired state.

  7. Infrastructure Discovery capabilities

    main

    The Discovery System is responsible for scanning and mapping existing infrastructure. Its core capabilities include:

    • Multi-Service Scanning: Comprehensive discovery across various AWS services.
    • Relationship Mapping: Identifying and mapping the relationships between discovered resources.

    Note: State Correlation and Drift Detection are currently marked as 'Not Ready'.

  8. Workflow best practices for the AI Infrastructure Agent

    main

    When using the AI Infrastructure Agent to manage cloud resources, follow these core principles to ensure safety and accuracy:

    1. Use Natural Language: Describe your infrastructure needs in plain English.
    2. Be Specific for Consistency: Different AI models interpret requests differently; detailed prompts reduce ambiguity.
    3. Review Before Executing: Always carefully inspect the generated infrastructure plan before allowing the agent to apply changes.
    4. Verify in AWS Console: After execution, confirm that the provisioned resources match your expectations in the AWS Management Console.
    5. Follow Security Best Practices: Especially when defining security groups and network access for production environments.
  9. How Adapters and AWS Integration work together

    main

    The system uses a two-tier approach to manage AWS resources:

    1. Adapters Layer: Implements the Adapter pattern to provide a consistent interface across different AWS services. Every service-specific adapter (e.g., VPC Adapter, EC2 Adapter) implements the AWSResourceAdapter interface, ensuring standardized resource lifecycle management, validation, and metadata extraction.
    2. AWS Integration Layer: Provides the low-level abstraction for the AWS SDK. It manages multi-service clients, handles authentication (IAM roles/credentials), and implements automatic retries with exponential backoff.
    type AWSResourceAdapter interface {
        GetResourceType() string
        ValidateResource(resource *types.ResourceState) error
        NormalizeResource(rawResource interface{}) (*types.ResourceState, error)
        ExtractMetadata(resource interface{}) map[string]interface{}
    }
  10. Understanding the AI Agent Workflow

    main

    The AI Infrastructure Agent follows a four-step lifecycle to transform natural language into AWS infrastructure:

    1. Enter Request: Describe your infrastructure needs in plain English via the Web UI.
    2. Review Plan: The AI generates a detailed execution plan. Review this for dependencies, parameters (like instance types or AMIs), and resource IDs.
    3. Approve & Execute: Once you click "Confirm & Execute", the agent performs the AWS API calls sequentially.
    4. Verify Resources: Check the dashboard or the AWS Console to confirm the resources were created correctly.
  11. How the Agent Layer orchestrates infrastructure decisions

    main

    The Agent Layer is the intelligence core of the system. It uses a StateAware Agent to bridge LLMs with infrastructure via the Model Context Protocol (MCP).

    Key capabilities include:

    • Multi-AI Provider Support: Integrates with OpenAI, Google Gemini, Anthropic Claude, AWS Bedrock Nova, and Ollama.
    • Request Processing: Converts natural language into context-aware execution plans with dependency resolution.
    • Plan Execution: Manages step-by-step execution, ensuring resources are created in the correct dependency order. It supports Dry-Run mode to simulate changes without actual resource creation.
    • Resource Analysis: Uses a Pattern Matcher, Field Resolver, and Value Type Inferrer to map AWS API responses to internal structures.
    • Safety: Performs pre-execution validation to detect conflicts and ensure consistency.
  12. How the Resource Analysis System works

    main

    The Resource Analysis System enables intelligent handling of AWS resources through three primary mechanisms:

    1. Pattern Matching Engine: Uses compiled regex patterns to detect AWS resource types and automatically maps tool names to specific resource types. It is configuration-driven and optimized via pattern caching.
    2. Field Resolution Engine: Performs runtime mapping between AWS API responses and internal data structures. It supports deep object traversal using dot notation (e.g., parent.child.field) and includes automatic type conversion and error recovery for missing fields.
    3. Value Type Inference: Uses context-aware rules and pattern matching based on field names and descriptions to intelligently infer data types.