A lightweight bash-based AI coding agent that uses the OpenRouter API with native tool calls.
┌─────────────────────────────────────────────────────────────────┐
│ agent.sh │
│ Tool-Call Based CLI Agent │
└─────────────────────────────────────────────────────────────────┘
┌──────────────────┐
│ User Input │
│ "You: ___" │
└────────┬─────────┘
│
▼
┌──────────────────────────────────────────────────┐
│ Build context: │
│ • System prompt (cached) │
│ • Conversation history (cached) │
│ • <previous-result> + <task> tags │
└────────────────────┬─────────────────────────────┘
│
▼
┌─────────────┐ ┌─────────────────┐
│ agent │──curl──▶│ OpenRouter API │
│ │◀────────│ (Claude Model) │
└─────────────┘ └─────────────────┘
│
┌─────────────┴─────────────┐
▼ ▼
┌──────────────┐ ┌───────────────┐
│ Tool Call │ │ Text Reply │
│ run_script │ │ (no tool) │
└──────┬───────┘ └───────────────┘
│
▼
┌──────────────────┐
│ Show script │
│ Ask "Run? (y/n)" │
└────────┬─────────┘
│ (confirmed)
▼
┌──────────────────────────────────────────────────┐
│ bash -c "$script" ──┬──▶ stdout │
│ └──▶ result.txt (for next) │
└──────────────────────────────────────────────────┘
├── agent.sh # Main agent script
├── history.json # Conversation memory [{role,content},...]
├── result.txt # Last script output (fed back to AI)
└── system_prompt.txt # Customizable system instructions
- Set your OpenRouter API key:
export OPENROUTER_API_KEY="your-key"- Run the agent:
bash agent.sh- Describe tasks in plain English
- Review and confirm script execution with y/n
AUTO=1 bash agent.sh- curl
- jq
- coreutils
| Variable | Default | Description |
|---|---|---|
| OPENROUTER_API_KEY | (required) | Your OpenRouter API key |
| MODEL | anthropic/claude-sonnet-4-20250514 | Model to use |
| ENDPOINT | https://openrouter.ai/api/v1/chat/completions | API endpoint |
| AUTO | 0 | Set to 1 to auto-execute scripts |
- User describes a task in natural language
- Agent builds messages with system prompt + history + current task
- Sends request to OpenRouter with
run_scripttool definition - AI responds with either:
- Tool call: Script to execute (user confirms, output saved)
- Text: Direct response (displayed to user)
- History and results persist for multi-turn conversations
- Prompt caching reduces API costs on repeated context