prompt fix

This commit is contained in:
Luxferre
2026-08-08 20:28:58 +03:00
parent bec49bad94
commit e64fa242fd
3 changed files with 49 additions and 6 deletions
+36 -5
View File
@@ -2,7 +2,7 @@
## About
Bantam is a minimalist, dependency-free AI agent specification and implementation (under 300 SLOC of Python (~250 in the reference implementation)). It provides an agentic loop capable of autonomous tool execution, shell interaction, real-time response streaming, Fibonacci backoff network resilience, and subagent delegation using any OpenAI-compatible completions API.
Bantam is a minimalist, dependency-free AI agent specification with two reference implementations: **Python** (`bantam.py`, ~300 SLOC) and **Go** (`main.go` + `term_*.go`, module `code.luxferre.top/luxferre/bantam`). It provides an agentic loop capable of autonomous tool execution, shell interaction, real-time response streaming, Fibonacci backoff network resilience, and subagent delegation using any OpenAI-compatible completions API.
The entire philosophy of Bantam is built upon two principles:
@@ -14,11 +14,29 @@ Because of the second principle, Bantam itself was named after Victorinox Bantam
## Usage
### Prerequisites
- Python 3.7+ (no external dependencies required)
- **Go 1.21+** (Go implementation, no external dependencies) or **Python 3.7+** (reference implementation)
- An OpenAI-compatible API endpoint (or OpenAI API key)
### Installation (Go)
```bash
go install code.luxferre.top/luxferre/bantam@latest
```
This installs the `bantam` binary into `$(go env GOPATH)/bin` (make sure it is on your `PATH`). To build from a local checkout instead:
```bash
go build ./... # produces ./bantam
# or run without building:
go run . prompt.txt
```
The Go port is a single `main.go` plus two small platform files (`term_linux.go`, `term_darwin.go`, `term_windows.go`, `term_other.go`) for the built-in raw-terminal line editor — zero external dependencies, same as the Python version.
### Running Bantam
Both implementations read the same `model.cfg` and `system.txt` from the current working directory.
1. Configure `model.cfg` with your API settings:
```ini
endpoint=https://api.openai.com/v1
@@ -30,10 +48,11 @@ Because of the second principle, Bantam itself was named after Victorinox Bantam
2. Interactive mode:
```bash
python3 bantam.py
bantam # Go (or: go run .)
python3 bantam.py # Python
```
In interactive mode, prompts can span multiple lines: press **Ctrl+J** to insert a real line break (the cursor moves to the next line), then **Enter** to submit the whole multi-line prompt. This works when `readline` is available; without it, prompts are single-line.
In interactive mode, prompts can span multiple lines: press **Ctrl+J** to insert a real line break (the cursor moves to the next line), then **Enter** to submit the whole multi-line prompt. The Go port ships its own raw-mode line editor (arrow keys move the cursor, Up/Down browse history, Backspace edits, Ctrl+C/Ctrl+D exit), so this works everywhere without dependencies; the Python port uses `readline` when available and falls back to single-line prompts otherwise.
Sessions are saved under `~/.bantam/sessions/` and can be managed with these commands:
- `/save` — save the entire conversation to a new session file (auto-id like `20260808-190038`) and generate its summary
@@ -48,7 +67,8 @@ Because of the second principle, Bantam itself was named after Victorinox Bantam
3. File input mode:
```bash
python3 bantam.py prompt.txt
python3 bantam.py prompt.txt # Python
bantam prompt.txt # Go
```
## Rules of Bantam (The Algorithm)
@@ -95,6 +115,8 @@ Using these rules, everyone can build their own copy of Bantam from scratch in l
### Model configuration parameters
(shared by both implementations; `model.cfg` is plain `key=value` with `#` comments)
- `endpoint` (base OpenAI-compatible API URL, default `https://api.openai.com/v1`)
- `model` (model name, e.g. `gpt-4o`)
- `temperature` (model temperature, default 0.7)
@@ -105,6 +127,8 @@ Using these rules, everyone can build their own copy of Bantam from scratch in l
- `shell_timeout` (timeout in seconds for `shell_exec` commands, default 120)
- `max_al_iterations` (max tool-call loop iterations per `AL()` invocation, default 1000)
Both implementations keep the interactive prompt safe against the classic "long line overwrites the prompt" readline bug: the Python port wraps the ANSI escapes in `\001`/`\002` (`RL_PROMPT_START_IGNORE`/`RL_PROMPT_END_IGNORE`) markers, and the Go port's built-in editor tracks the cursor with its own column math (terminal auto-wrap aware) and redraws from the first line of the buffer, so wrapped input stays clean at any terminal width.
When enabled, the interactive console uses a subtle ANSI palette: the pending-request status `...requesting...` is darkened bold, reasoning markers are cyan, reasoning text is dim, `[tool call: ...]` traces are yellow, `[tool result: ...]` headers are green, tool result bodies are dim (red for tool errors/unknown tools), and errors/network retries are red. Tool result payloads fed back to the LLM are never colored.
### Tool call definitions
@@ -121,6 +145,13 @@ When enabled, the interactive console uses a subtle ANSI palette: the pending-re
- Return value: string
- Action: run shell command specified in `command` subject to `shell_timeout` (default 120s) and return `output + '\n\nexit: ' + exit_code` string.
## Repository layout
- `bantam.py` — Python reference implementation (stdlib only)
- `main.go`, `term_linux.go`, `term_darwin.go`, `term_windows.go`, `term_other.go` — Go implementation (stdlib only, module `code.luxferre.top/luxferre/bantam`)
- `model.cfg`, `system.txt` — shared configuration and system prompt
- `README.md` — this document
## FAQ
### Why no MCP support?