Skip to main content

The AI coding agent you can read in an afternoon. ~2000 lines of Python, fully hackable.

Project description

mini-cognit-cli

A minimal, hackable CLI AI agent for software engineering — built to be understood, modified, and extended.

Unlike heavyweight AI coding tools, mini-cognit-cli is intentionally small (~1500 lines of Python) so you can read the entire codebase in an afternoon and make it your own.

Features

  • Agentic loop — the LLM autonomously calls tools, observes results, and iterates until the task is done
  • Built-in tools — file read/write, shell execution, grep search, web search — everything needed for coding tasks
  • Tool approval — dangerous operations (shell commands) require user confirmation; bypass with --yolo when you trust it
  • Context compaction — automatically summarizes conversation history when approaching token limits, so long sessions don't break
  • Any OpenAI-compatible API — works with OpenAI, Anthropic (via proxies like subrouter), local models, or any provider with an OpenAI-compatible endpoint
  • TOML config — configure providers, models, and defaults in a simple cognit.toml file
  • Streaming output — responses stream token-by-token with rich terminal formatting

Quickstart

# Clone and install
git clone https://github.com/gxPan1006/mini-cognit-cli.git
cd mini-cognit-cli
pip install -e .

# Option 1: Configure via cognit.toml
cp cognit.toml.example cognit.toml
# Edit cognit.toml with your API key and preferred model

# Option 2: Use environment variables
export OPENAI_API_KEY="sk-..."
export OPENAI_BASE_URL="https://api.openai.com/v1"  # optional

# Start chatting
cognit chat

Usage

# Basic usage (reads from cognit.toml or env vars)
cognit chat

# Specify model and provider directly
cognit chat --model gpt-4o --api-key sk-... --base-url https://api.openai.com/v1

# YOLO mode — auto-approve all tool executions (no confirmation prompts)
cognit chat --yolo

# Limit agent loop steps per turn
cognit chat --max-steps 20

# Show version
cognit version

In-session commands

Command Description
/help Show available commands
/clear Clear conversation context
/exit Quit the session

Configuration

Create a cognit.toml in your project directory or ~/.config/cognit/cognit.toml:

[providers.my_provider]
type = "openai"
base_url = "https://api.openai.com/v1"
api_key = "sk-..."

[models.default]
provider = "my_provider"
model = "gpt-4o"
max_context_size = 128000

Config priority: CLI flags > cognit.toml > environment variables.

Architecture

src/cognit/
├── cli.py              # CLI entry point (Typer)
├── app.py              # Orchestrator — wires everything together
├── config.py           # TOML config loading
├── llm/
│   ├── provider.py     # Abstract LLM provider interface
│   ├── openai_provider.py  # OpenAI-compatible implementation
│   ├── generate.py     # LLM call + tool execution step
│   └── message.py      # Message, ToolCall, ToolResult types
├── soul/
│   ├── agent.py        # Core agent loop
│   ├── context.py      # Conversation context management
│   ├── compaction.py   # Context summarization
│   └── toolset.py      # Tool registry and dispatch
├── tools/
│   ├── file_read.py    # Read files with line numbers
│   ├── file_write.py   # Write/edit files
│   ├── grep.py         # Search file contents
│   ├── shell.py        # Shell command execution
│   └── web_search.py   # Web search via DuckDuckGo
└── ui/
    └── terminal.py     # Terminal I/O (prompt-toolkit + rich)

The design is modular — each component has a clear responsibility:

  • soul/agent.py — the brain. Runs the LLM-tool loop until the task is complete.
  • soul/toolset.py — tool registry with decorator-based registration and automatic JSON Schema inference.
  • llm/ — provider abstraction. Swap in any OpenAI-compatible API.
  • tools/ — each tool is a self-contained module. Adding a new tool is ~30 lines of code.

Adding a custom tool

# src/cognit/tools/my_tool.py
from cognit.soul.toolset import Toolset

def register(toolset: Toolset) -> None:
    @toolset.tool(
        name="my_tool",
        description="Does something useful.",
        requires_approval=False,  # set True for dangerous operations
    )
    async def my_tool(arg1: str, arg2: int = 10) -> str:
        # Your logic here
        return f"Result: {arg1}, {arg2}"

Then register it in app.py:

from cognit.tools import my_tool
my_tool.register(toolset)

Requirements

  • Python >= 3.12
  • Dependencies: openai, prompt-toolkit, rich, typer, tomlkit, tiktoken

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mini_cognit_cli-0.2.0.tar.gz (309.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mini_cognit_cli-0.2.0-py3-none-any.whl (42.3 kB view details)

Uploaded Python 3

File details

Details for the file mini_cognit_cli-0.2.0.tar.gz.

File metadata

  • Download URL: mini_cognit_cli-0.2.0.tar.gz
  • Upload date:
  • Size: 309.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for mini_cognit_cli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 10328cc45c498b6df3f81031874dfc96b08596f07b2647146e45df80cd55d0f6
MD5 c119e1e44dbb25a5e595a6796d7f4c86
BLAKE2b-256 6ba0130891da483ddca9024f142d60fe8912f9fc4bf49dec9b52d5e0da8fcf0e

See more details on using hashes here.

File details

Details for the file mini_cognit_cli-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mini_cognit_cli-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ca8f55d15de7c2e0e3cc03de3ae4813b67d73491a79d12df3e15d905a839b7f
MD5 7d147c7de93298ecb07856a4ffd516a6
BLAKE2b-256 c4c709aac177489a94c7c39642e81afd0affaaa14aaf437004ad274627f12694

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page