AI agent framework with an interactive terminal UI (Ink/React). The core loop: user input → query rewriting → memory retrieval → context compaction → LLM → tool execution → repeat.
git clone https://github.com/LongPPPP/Coding-Agent.git && cd cogent
npm install
cp .env.example .env
# Edit .env — set LLM_API_KEY to your API key
npm run devPrerequisites: Node.js ≥ 18, an API key from a provider with an OpenAI-compatible endpoint (DeepSeek by default).
| Command | Description |
|---|---|
npm run dev |
Run with tsx hot-reload |
npm run build |
TypeScript compilation (tsc) |
npm start |
Run compiled JS (node dist/index.js) |
npm run pico |
Run pico task-completion benchmark |
PICO_FILTER=text-edit npm run pico |
Filter benchmark tasks |
Copy .env.example → .env and edit. Key variables:
| Variable | Default | Description |
|---|---|---|
LLM_API_KEY |
— | Required — API key for LLM access |
MODEL_NAME |
deepseek-v4-flash |
Primary model for agent reasoning |
MODEL_BASE_URL |
https://api.deepseek.com |
OpenAI-compatible API endpoint |
AGENT_MAX_ITERATIONS |
30 |
Max LLM iterations per agent run |
PROJECT_RULES_FILE |
COGENT.md |
Project-level instructions injected into agent prompt |
All config is validated at startup — warnings are printed to console if any values look wrong. Full reference: see .env.example for every variable, and src/config.ts for the typed schema.
src/
├── main.tsx # Ink CLI entry point
├── config.ts # Configuration (env vars → typed frozen object)
├── agent.ts # Agent execution loop
├── Tool.ts # Tool system registry and dispatch
├── commands.ts # CLI slash-commands (/clear, /exit, /status, ...)
├── db.ts # SQLite database init
├── type.ts # Shared TypeScript types
├── compact/ # Context compaction (microCompact + AutoCompactor)
├── memory/ # Memory system (SQLite + vector embeddings + FTS5)
├── tools/ # Built-in tools
│ ├── FileReadTool/ # File reading with line-range support
│ ├── FileEditTool/ # Exact-string replacement editing
│ ├── FileWriteTool/ # File creation/overwrite
│ ├── GlobTool/ # Fast file pattern matching
│ ├── TodoWriteTool/ # Task list management
│ ├── AgentTool/ # Sub-agent spawning
│ └── PowerShellTool/ # Shell command execution
├── utils/ # LLM client, logger, token counting, sanitizers
├── App/ # CLI app state management
├── components/ # Ink UI components
├── benchmark/ # Benchmark suite
│ └── pico/ # Task-completion benchmark with fixtures
└── test/ # Unit and integration tests
Up to AGENT_MAX_ITERATIONS iterations per run. Each iteration: microCompact (rule-based trim) → AutoCompactor (at 85% context, LLM summarizes non-system messages) → LLM call → tool dispatch → inject results → repeat. On no tool calls, finishes and saves conversation to memory.
SQLite with vector embeddings (all-MiniLM-L6-v2 via @xenova/transformers) + FTS5 full-text search. Composite retrieval scoring: cosine similarity (45%), BM25 (25%), context/language match (15%), access frequency (10%), time decay (5%). Conversation summaries saved as knowledge after each agent run.
Central toolsPool Map registers tools by name + aliases. Each tool defines: schema, execution, result formatting, and security constraints. Results exceeding size limits are saved to disk with a preview returned to the LLM.
Two-stage: microCompact() (rule-based, strips oldest messages beyond token/age thresholds) then AutoCompactor.compact() (LLM-powered summarization). Full transcripts saved before compression.
Ink-based React TUI with states: input, thinking (agent status panel with live tool tracking), confirm (tool approval), done (result display). Todo panel shows plan progress. Slash-commands: /clear, /exit, /status, /help, /model, /context.
- Token counting via
tiktoken; agent logs via Pino - Memory DB at
data/agent-memory.db(SQLite WAL mode) - TypeScript strict mode, ES2020 target, ESNext module resolution
- Config is deeply frozen at runtime — no accidental mutations
ISC