Minimal AI coding agent
Project description
NTN - Minimal AI Coding Agent
A minimal AI agent that helps with coding tasks in a workspace. Supports multiple LLM providers (OpenAI GPT-5.2, Anthropic Claude).
Features
- Multi-provider support: GPT-5.2 (default), Claude Opus/Sonnet/Haiku
- Docker-first file operations: All file operations run in a Docker container with Unix tools
- Web search: Search using DuckDuckGo (ddgs package)
- Web fetching: Fetch and read webpage content
- Terminal execution: Run Windows commands when needed
- Persistent container: Single container per session, auto-starts on launch
- Command denylist: Dangerous commands require user confirmation
- Colored output: Easy-to-read console with color-coded messages
- Debug logging: Incremental logging to
debug/folder (crash-resilient) - Resume sessions: Continue previous conversations with
-rflag - Mid-turn resume: Automatically recovers from crashes mid-tool-execution
- Auto-compact: Automatically summarizes context when approaching token limit
- Auto-cleanup: Empty conversations (no user messages) are automatically deleted
- Rate limit handling: Automatically waits and retries using
retry-afterheader - Prompt caching: System prompt and tools are cached to reduce costs
- Model selection: Choose between GPT and Claude models with
-mflag - Streaming output: Real-time response display (always enabled)
- Cost tracking: Shows per-request and session costs with token usage
- Extended thinking: Enable deep reasoning for complex tasks with
-tflag
Installation
Install from PyPI:
pip install ntn
Or install from source:
git clone https://github.com/ntrnghia/coding-agent.git
cd ntn
pip install -e .
Setup
Set your API key based on the model you want to use:
For GPT-5.2 (default):
export OPENAI_API_KEY='your-api-key-here'
For Claude models:
export ANTHROPIC_API_KEY='your-api-key-here'
(Optional) Install Docker for sandbox functionality.
Usage
Run the agent:
ntn
Resume a previous session:
# Resume most recent session
ntn -r
# Resume specific session
ntn -r debug/debug_20251210_120000.txt
Enable extended thinking (better for complex reasoning):
ntn -t
Use a different model:
ntn -m gpt # Use GPT-5.2 (default)
ntn -m opus # Use Claude Opus 4.5
ntn -m sonnet # Use Claude Sonnet 4.5
ntn -m haiku # Use Claude Haiku 4.5
Combine flags:
ntn -t -r # Resume with extended thinking
ntn -m opus -t # Opus with extended thinking
Alternative: Run as Python module:
python -m ntn
Input controls:
Shift+Enter- New line (shows\)Enter- Submit messageCtrl+C- Exit the agent
Example prompts:
- "Create a new Python project with main.py and tests/"
- "Search for PyTorch distributed training docs"
- "List all Python files in this directory"
- "Run pytest on my tests"
- "Tell me what the code in D:\Downloads\some-project does" (uses Docker sandbox)
Package Structure
ntn/
├── src/ntn/
│ ├── __init__.py # Package exports
│ ├── __main__.py # Entry for `python -m ntn`
│ ├── agent.py # Main agent with auto-compact and resume support
│ ├── tools.py # Tool implementations (Terminal, Web, Docker)
│ ├── providers.py # LLM provider abstraction (OpenAI, Anthropic)
│ ├── config.py # Configuration loader
│ ├── config.yaml # Configuration values
│ └── cli.py # CLI entry point
├── pyproject.toml # Package configuration
├── LICENSE # MIT License
└── README.md # This file
Tools
Terminal Tool
Executes shell commands in your workspace. Dangerous commands (rm, sudo, curl, etc.) require user confirmation before execution.
Web Search Tool
Searches the web using DuckDuckGo, returns top 10 results.
Fetch Web Tool
Fetches and extracts text content from URLs.
Docker Sandbox Tool
All file operations run in a Docker container for consistent Unix environment:
- Auto-starts on launch with workspace pre-mounted
- Single persistent container per session (named
agent_<timestamp>) - Directories mounted at Unix-style paths:
D:\Downloads\project→/d/downloads/project - Read-write access to all mounted directories
- Multiple directories can be mounted dynamically
- Container persists across prompts and survives resume
- Lazy recovery: If container stops, auto-restarts on next command
- Uses
python:slimimage by default
Context Management
The agent automatically manages context when approaching token limits:
- Auto-compact triggers: Summarizes older conversation turns
- Preserves current task: Summary includes your current question
- Seamless continuation: You won't notice the compaction
Debug file shows compaction events:
=== COMPACTION EVENT ===
Reason: Exceeded context (180000 tokens attempted)
Removed turns: 1-3
Summary content: [condensed conversation]
Resume Sessions
Sessions are logged incrementally to debug/debug_<timestamp>.txt. To resume:
# Resume most recent session
ntn -r
# Resume specific session
ntn -r debug/debug_20251210_120000.txt
On resume:
- Previous conversation is displayed (including tool operations)
- Context is restored (including any compacted summaries)
- Container state is restored (mounts preserved)
- New messages append to the same debug file
- Crash recovery: If the agent crashed mid-turn, it will automatically continue from where it left off
- Multi-model support: Can resume with a different model than originally used
Debug Log Format
Debug files use an incremental format for crash resilience:
=== TURN 1 ===
--- USER ---
<user message>
--- ASSISTANT ---
<JSON response>
--- USAGE: {"model": "gpt", "input": 1000, "output": 50, ...} ---
--- TOOL_RESULT ---
<JSON tool results>
--- END_TURN ---
Each block is written immediately, so even if the agent crashes, the debug file contains all completed operations.
Output Format
The agent uses colored output for readability:
- 🟢 Green: Agent messages
- 🟡 Yellow: Tool operations (📂 List files, 📄 Read file, ✏️ Edit file, 🐳 Docker, etc.)
- 🟣 Magenta: Thinking indicator (when extended thinking enabled)
- 🔵 Cyan: System messages, user prompts
- 🔴 Red: Errors
Full JSON input/output is logged to debug/debug_<timestamp>.txt for debugging.
Security Notes
- Commands run without timeout (for long-running processes)
- Dangerous commands require explicit user confirmation
- Docker sandbox provides isolated environment for external directories
- All commands run in the specified workspace directory
- Never commit API keys to version control
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ntn-0.3.0.tar.gz.
File metadata
- Download URL: ntn-0.3.0.tar.gz
- Upload date:
- Size: 39.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad1d2eb2c54339d81c273c29a677d2b439c17850962a0445820b721681f42853
|
|
| MD5 |
cbd6b7d8c534e9d6ebfa01af450ce4dd
|
|
| BLAKE2b-256 |
3383096ea2eff9e59169f968cebbdfee4199ddc8efb557be229b42a4c54f5de2
|
File details
Details for the file ntn-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ntn-0.3.0-py3-none-any.whl
- Upload date:
- Size: 42.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d52fffae50b2064e3a66f07da07a27b6979b76150daf07c5f44e44dfcd43c7c
|
|
| MD5 |
09eb5246f80642d5bc60701e94234cc5
|
|
| BLAKE2b-256 |
e929628a99c7ca452e84c71b3d7433a4170ee49249e8e2166a5da1e6acd4d5ed
|