Skip to content

entrhq/forge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

417 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Forge

CI Go Report Card GoDoc License

Forge is an open-source, lightweight agent framework for building AI agents with pluggable components. It provides a clean, modular architecture that makes it easy to create agents with different LLM providers and execution environments.

Features

  • ๐Ÿ”Œ Pluggable Architecture: Interface-based design for maximum flexibility
  • ๐Ÿค– LLM Provider Abstraction: Support for OpenAI-compatible APIs with extensibility for custom providers
  • ๐Ÿ› ๏ธ Tool System: Agent loop with tool execution and custom tool registration
  • ๐Ÿง  Chain-of-Thought: Built-in thinking/reasoning capabilities for transparent agent behavior
  • ๐Ÿ’พ Memory Management: Conversation history and context management
  • ๐Ÿ”„ Event-Driven: Real-time streaming of thinking, tool calls, and messages
  • ๐Ÿ” Self-Healing Error Recovery: Automatic error recovery with circuit breaker pattern
  • ๐Ÿš€ Execution Plane Abstraction: Run agents in different environments (CLI, API, custom)
  • ๐Ÿค– Headless Mode: Automated CI/CD workflows with git integration and PR creation
  • ๐Ÿ“š Automated Documentation: AI-powered documentation updates on every PR
  • ๐Ÿ“ฆ Library-First Design: Import as a Go module in your own applications
  • ๐Ÿงช Well-Tested: Comprehensive test coverage (196+ tests passing)
  • ๐Ÿ“– Well-Documented: Clear, comprehensive documentation

Quick Start

go get github.com/entrhq/forge
package main

import (
    "context"
    "log"
    "os"

    "github.com/entrhq/forge/pkg/agent"
    "github.com/entrhq/forge/pkg/executor/tui"
    "github.com/entrhq/forge/pkg/llm/openai"
    "github.com/entrhq/forge/pkg/tools/coding"
)

func main() {
    // Create LLM provider
    provider, err := openai.NewProvider(
        os.Getenv("OPENAI_API_KEY"),
        openai.WithModel("gpt-4o"),
    )
    if err != nil {
        log.Fatal(err)
    }
    
    // Create coding agent with built-in tools
    ag := agent.NewDefaultAgent(provider,
        agent.WithCustomInstructions("You are an expert coding assistant."),
    )
    
    // Register coding tools
    coding.RegisterTools(ag, ".")
    
    // Launch TUI executor
    executor := tui.NewExecutor(ag)
    if err := executor.Run(context.Background()); err != nil {
        log.Fatal(err)
    }
}

๐ŸŽฏ Key Features

๐Ÿ–ฅ๏ธ Advanced Terminal UI

  • Real-time Streaming: See agent thinking, tool calls, and responses stream in as they happen
  • Compact Header Bar: Workspace path and active model shown at a glance; context-aware hints update with TUI state
  • Smart Scroll-Lock: Scroll up to review history while the agent works; a banner appears when new content arrives, press G to jump back and resume auto-follow
  • Command Palette: Instant slash command launcher via Ctrl+K / Ctrl+P or typing /; Enter executes immediately
  • Diff Viewer: Interactive unified diff viewer with syntax highlighting for file changes
  • Tool Result History: Browse all tool results from the session with Ctrl+L; inspect the latest result with Ctrl+V
  • Clipboard Copy: Copy the full conversation as plain text with Ctrl+Y
  • Agent Thinking Blocks: Extended reasoning shown inline with elapsed time; toggle visibility in settings
  • Interactive Settings: Live configuration of LLM parameters, auto-approval rules, and UI preferences
  • Slash Commands: Built-in commands for common workflows (/commit, /pr, /bash, /notes, /help, /snapshot)

๐Ÿ› ๏ธ Complete Coding Toolkit

File Operations:

  • read_file - Read files with optional line ranges
  • write_file - Create or overwrite files with automatic directory creation
  • list_files - List and filter files with glob patterns and recursive search
  • search_files - Regex search across files with context lines

Code Manipulation:

  • apply_diff - Surgical code edits with search/replace operations
  • execute_command - Run shell commands with streaming output and timeout control

Agent Control:

  • task_completion - Mark tasks complete and present results
  • ask_question - Request clarifying information from users
  • converse - Engage in natural conversation

๐Ÿ” Security & Control

  • Workspace Guard: Prevent operations outside designated directories
  • File Ignore System: Respect .gitignore and custom ignore patterns
  • Tool Approval: Review and approve tool executions before running
  • Auto-Approval Whitelist: Configure safe operations to run automatically
  • Command Timeout: Prevent runaway processes with configurable timeouts

๐Ÿง  Smart Context Management

  • Token-Based Pruning: Automatic conversation history management
  • Tool Call Summarization: Condense tool results to preserve context
  • Composable Strategies: Mix and match context management approaches
  • Threshold-Based Trimming: Keep conversation within model limits

๐Ÿ”„ Git Workflow Integration

  • Automated Commits: Review and commit changes directly from the TUI
  • Pull Request Creation: Generate PRs with AI-written descriptions
  • Headless CI/CD: Run Forge in GitHub Actions and other CI/CD pipelines
  • Automated PR Documentation: Auto-update docs when PRs are opened
  • Change Tracking: Monitor file modifications across agent sessions
  • Diff Preview: View changes before committing

๐Ÿ“š Documentation

Getting Started

How-To Guides

Architecture

Reference

Architecture Decision Records

See ADRs for detailed design decisions including:

๐Ÿ—๏ธ Architecture

Forge is built with a clean, modular architecture designed for extensibility:

pkg/
โ”œโ”€โ”€ agent/          # Agent core, loop, prompts, memory
โ”‚   โ”œโ”€โ”€ context/    # Context management strategies
โ”‚   โ”œโ”€โ”€ git/        # Git integration
โ”‚   โ”œโ”€โ”€ memory/     # Conversation history
โ”‚   โ”œโ”€โ”€ prompts/    # Dynamic prompt assembly
โ”‚   โ”œโ”€โ”€ slash/      # Slash command system
โ”‚   โ””โ”€โ”€ tools/      # Tool interface and built-ins
โ”œโ”€โ”€ executor/       # Execution environments
โ”‚   โ”œโ”€โ”€ cli/        # Command-line executor
โ”‚   โ””โ”€โ”€ tui/        # Terminal UI executor
โ”œโ”€โ”€ llm/            # LLM provider abstraction
โ”‚   โ”œโ”€โ”€ openai/     # OpenAI implementation
โ”‚   โ”œโ”€โ”€ parser/     # Response parsing
โ”‚   โ””โ”€โ”€ tokenizer/  # Token counting
โ”œโ”€โ”€ tools/          # Tool implementations
โ”‚   โ””โ”€โ”€ coding/     # File and command tools
โ”œโ”€โ”€ config/         # Configuration management
โ”œโ”€โ”€ security/       # Security features
โ”‚   โ””โ”€โ”€ workspace/  # Workspace isolation
โ””โ”€โ”€ types/          # Shared types and events

Key Design Principles

  • Interface-First: Clean abstractions for maximum flexibility
  • Event-Driven: Real-time streaming of agent activities
  • Composable: Mix and match components as needed
  • Testable: Comprehensive test coverage (200+ tests)
  • Type-Safe: Strong typing with Go's type system

๐Ÿ’ก Examples

Basic Coding Agent

package main

import (
    "context"
    "log"
    "os"

    "github.com/entrhq/forge/pkg/agent"
    "github.com/entrhq/forge/pkg/executor/cli"
    "github.com/entrhq/forge/pkg/llm/openai"
    "github.com/entrhq/forge/pkg/tools/coding"
)

func main() {
    provider, _ := openai.NewProvider(os.Getenv("OPENAI_API_KEY"))
    
    ag := agent.NewDefaultAgent(provider,
        agent.WithCustomInstructions("You are a helpful coding assistant."),
        agent.WithMaxIterations(50),
    )
    
    // Register all coding tools
    coding.RegisterTools(ag, ".")
    
    executor := cli.NewExecutor(ag)
    executor.Run(context.Background())
}

With Custom Tools

type WeatherTool struct{}

func (t *WeatherTool) Name() string { return "get_weather" }
func (t *WeatherTool) Description() string {
    return "Get current weather for a location"
}
func (t *WeatherTool) Parameters() map[string]interface{} {
    return map[string]interface{}{
        "location": map[string]interface{}{
            "type":        "string",
            "description": "City name",
            "required":    true,
        },
    }
}
func (t *WeatherTool) Execute(ctx context.Context, args map[string]interface{}) (string, error) {
    location := args["location"].(string)
    // Call weather API...
    return fmt.Sprintf("Weather in %s: Sunny, 72ยฐF", location), nil
}

// Register custom tool
ag.RegisterTool(&WeatherTool{})

See examples/ for complete working examples.

๐Ÿ”ง Development

Prerequisites

  • Go 1.21 or higher
  • Make (optional, recommended)
  • Git

Setup

# Clone repository
git clone https://github.com/entrhq/forge.git
cd forge

# Install development tools
make install-tools

# Run tests
make test

# Run linter
make lint

# Build CLI
make build

Make Targets

  • make test - Run all tests with coverage
  • make lint - Run linters (golangci-lint)
  • make fmt - Format code
  • make build - Build Forge CLI
  • make install - Install Forge CLI
  • make clean - Clean build artifacts
  • make all - Run all checks and build

Running Tests

# All tests
make test

# Specific package
go test ./pkg/agent/...

# With coverage
go test -cover ./...

# Verbose
go test -v ./pkg/tools/coding/

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Areas for Contribution

  • ๐Ÿ”Œ Additional LLM provider implementations (Anthropic, Google, etc.)
  • ๐Ÿ› ๏ธ New tool implementations
  • ๐Ÿ“ Documentation improvements
  • ๐Ÿ› Bug fixes and performance improvements
  • โœจ New features and enhancements

Code of Conduct

By participating, you agree to abide by our Code of Conduct.

Security

For security issues, see our Security Policy.

๐Ÿ—บ๏ธ Roadmap

โœ… Completed

  • Core agent loop with tool execution
  • OpenAI provider with streaming support
  • Advanced TUI with syntax highlighting
  • Complete coding toolkit (read, write, diff, search, execute)
  • Context management with multiple strategies
  • Auto-approval and settings system
  • Git integration (commits and PRs)
  • Headless mode for CI/CD automation
  • Automated PR documentation workflow
  • File ignore system for security
  • Slash command system
  • Self-healing error recovery
  • XML/CDATA tool call format
  • Comprehensive test suite (200+ tests)

๐Ÿšง In Progress

  • Additional LLM providers (Anthropic Claude, Google Gemini)
  • Multi-agent coordination and handoffs
  • Advanced executor implementations (HTTP API, Slack bot)
  • Plugin system for third-party tools
  • Enhanced memory with vector storage

๐Ÿ”ฎ Planned

  • Web-based UI
  • Agent marketplace and sharing
  • Observability and monitoring
  • Advanced debugging tools
  • Multi-modal support (vision, audio)

See ROADMAP.md for detailed plans.

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

Built with โค๏ธ as part of the Entr Agent Platform.

๐Ÿ”— Links

About

Forge: Open-source, lightweight agent for executing anywhere

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors