This repository contains a specialized orchestration layer designed exclusively for the Opencode CLI agent.
It enables a "Stateless Development" workflow where the AI agent operates in a persistent, headless tmux environment, while the human operator controls it remotely via a Telegram bot.
The system solves the problem of maintaining context and session state when the user switches devices or restarts their local machine.
- The Agent (
opencode): Runs inside atmuxsession. It is persistent. It has no direct UI; it "speaks" by executing a tool (send_telegram.py). - The Bridge (
telegram_agent.py): A lightweight Python process that:- Polls Telegram for user messages.
- Routes messages directly into the agent's brain via
tmux send-keys(primary) or theopencodeREST API (fallback). - Does not execute code itself. It is a dumb pipe.
- The Loop:
- User sends "Refactor main.py" on Telegram.
- Bridge injects prompt into Agent's session.
- Agent wakes up, reads prompt, edits files, runs tests.
- Agent runs
send_telegram.py "Done. Tests passed."to reply.
If you are an AI agent instructed to set this up, follow these steps exactly to replicate the environment:
- Opencode CLI: Must be installed and accessible.
- Tmux: Must be installed.
- Python 3.13+: Required for the bridge script.
Create a .env file in the root:
TELEGRAM_TOKEN=your_token_hereSecurity Note: Edit telegram_agent.py and set ALLOWED_USER_ID to the operator's Telegram ID.
# Clone this repo (if not already present)
# git clone [email protected]:llvm-x86/opencode-orchestration.git
# Setup Python environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtTo keep the bot running after you close your terminal, run it inside a tmux session:
tmux new-session -s orchestrator
./run_bot.sh
# Press Ctrl+B, then D to detachTo make the bot run indefinitely, start on boot, and restart on crash:
- Edit
opencode-orchestrator.serviceand verify the paths (WorkingDirectory,User,ExecStart). - Install the service:
sudo cp opencode-orchestrator.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable opencode-orchestrator sudo systemctl start opencode-orchestrator - Check status:
sudo systemctl status opencode-orchestrator
- Workspace: All coding work should happen in
github_work_desk/(automatically git-ignored). - Communication: The agent must use
send_telegram.pyto talk to the user. Standard output is invisible.
telegram_agent.py: The bridge logic. Managestmuxsessions and API forwarding.AGENTS.md: The "Constitution" for the sub-agent. It dictates behavior and protocols.ab_test_api.py: A self-verification script to ensure the API bridge is working.send_telegram.py: The "mouth" of the agent.
MIT