Skip to content

marcuwynu23/agentai

Repository files navigation

agentai - Agentic AI Code Assistant

A Node.js command-line tool that acts as an agentic AI code generator with intelligent planning, memory management, and MCP server integration.

Features

  • Goal-Based Code Generation: Describe what you want to build, and agentai plans and executes it
  • Intelligent Planning: Breaks down high-level goals into actionable steps
  • Memory Management: Maintains project state and execution history
  • MCP Integration: Communicates with MCP servers for file handling, command execution, and test creation
  • Structured Logging: Comprehensive logs in the logs/ directory

Project Structure

.
├── src/
│   ├── agentai.js         # CLI entry point
│   ├── core/              # Core AI logic
│   │   ├── ai_core.js         # AI reasoning and Gemini API integration
│   │   ├── chat_handler.js    # Chat command orchestration
│   │   ├── memory_manager.js  # Memory and state management
│   │   ├── planner.js         # Goal-to-plan conversion
│   │   └── mcp_client.js      # MCP server communication
│   ├── mcp_servers/       # MCP server stubs
│   │   ├── file_handling_server.js
│   │   ├── command_execution_server.js
│   │   └── test_server.js
├── .env                   # Environment configuration (create from .env.example)
├── .env.example           # Example environment configuration
├── workspace/             # Generated project files
├── logs/                  # Execution and planning logs
└── package.json          # Node.js package configuration

Installation

  1. Clone or navigate to the project directory

  2. Install dependencies:

    npm install
  3. Configure the tool:

    Copy the example environment file and add your configuration:

    cp .env.example .env

    Edit .env and add your Google Gemini API token:

    GEMINI_API_TOKEN=your-actual-api-token-here

Configuration

The tool reads configuration from a .env file in the project root. Create .env from .env.example:

cp .env.example .env

Configuration variables:

  • GEMINI_API_TOKEN: Your Google Gemini API token (required)
  • GEMINI_MODEL: Gemini model to use (default: gemini-2.5-flash)
  • REQUEST_DELAY: Delay between API requests in milliseconds (default: 2000 = 2 seconds). Increase if you hit rate limits
  • MAX_RETRIES: Maximum retry attempts for rate limit errors (default: 3)
  • WORKSPACE_PATH: Path where generated files are stored (default: current working directory where command is run)
  • LOGS_PATH: Path where logs are stored (default: ./logs in current directory)
  • MCP_FILE_HANDLING_URL: MCP server endpoint for file handling (default: http://localhost:3001)
  • MCP_COMMAND_EXECUTION_URL: MCP server endpoint for command execution (default: http://localhost:3002)
  • MCP_TEST_SERVER_URL: MCP server endpoint for test creation (default: http://localhost:3003)
  • LOG_LEVEL: Logging level (default: info)
  • LOG_MAX_FILE_SIZE: Maximum log file size (default: 10MB)
  • LOG_MAX_FILES: Maximum number of log files to keep (default: 5)

Rate Limiting

The tool automatically handles rate limits with:

  • Automatic retries: Retries up to 3 times when rate limited
  • Smart delays: Extracts retry delay from API error messages
  • Request throttling: Configurable delay between requests (default: 2 seconds)

If you frequently hit rate limits, increase REQUEST_DELAY in your .env:

REQUEST_DELAY=5000  # 5 seconds between requests

Usage

The CLI only accepts the chat subcommand:

node src/agentai.js chat "your goal here"

Or if installed globally:

agentai chat "create a REST API with Express.js"

Example

node src/agentai.js chat "create a simple Express.js server with a /hello endpoint"

This will:

  1. Load configuration
  2. Create a plan breaking down the goal into steps
  3. Execute each step via MCP servers
  4. Update memory with results
  5. Log all actions to logs/

Development Status

Fully Working: The system is now complete and functional!

  • Google Gemini API Integration: ✅ Fully implemented and working
  • MCP Servers: ✅ Fully implemented with actual file operations, command execution, and test creation
  • MCP Client: ✅ Working in-process communication with MCP servers
  • File Operations: ✅ Creates and modifies files in the workspace
  • Code Generation: ✅ Uses AI to generate actual code
  • Test Creation: ✅ Creates test files with AI-generated content
  • Command Execution: ✅ Safely executes commands with validation

How It Works

AI-Powered Planning

  1. Goal Analysis: The system uses Google Gemini API to analyze your goal
  2. Plan Generation: Creates a detailed, step-by-step plan with dependencies
  3. Step Reasoning: For each step, AI provides reasoning and approach

File Operations

  • File Creation: Creates files with AI-generated content
  • Code Generation: Uses AI to write complete, working code
  • File Modification: Updates existing files intelligently

Test Creation

  • Automatically generates test files
  • Uses AI to create comprehensive test cases
  • Supports Jest and Mocha frameworks

Command Execution

  • Safely executes commands like npm install, npm init, etc.
  • Validates commands for safety
  • Blocks dangerous operations
  • Returns execution results

Security Features

  • Command validation before execution
  • Blocks dangerous commands (rm, del, format, etc.)
  • Validates file paths
  • Safe error handling

Requirements

  • Node.js >= 18.0.0
  • npm or yarn

License

MIT

About

a command-line agentic ai assistant for automated coding, planning, and mcp integration

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors