An autonomous agent that monitors Gitea repositories for issues, automatically generates code solutions using the kilocode AI tool, and creates pull requests for review.
Comment on the resulting PR or add review comments to iterate. The agent will respond to your feedback and update the PR!
The system consists of three main components:
┌─────────────┐
│ Gitea API │
└──────┬──────┘
│
┌──────▼──────┐
│ Main Agent │
│ (main.py) │
└──────┬──────┘
│ Polls for open issues
│ Reserves issues with labels
│ Spawns subagents
┌──────▼──────┐
│ Subagent │
│ (subagent.py│
│ process) │
└──────┬──────┘
│ Clones repo
│ Generates code with kilocode
│ Commits & pushes changes
│ Creates PR
│ Monitors PR comments
│ Responds to feedback
┌──────▼──────┐
│ Gitea │
│ Repository │
│ & PRs │
└─────────────┘
Control Flow:
- Main agent polls Gitea API for open issues
- Filters qualifying issues (no reserve/acceptance labels)
- Reserves issue by adding label
- Spawns subagent subprocess
- Subagent clones repo, generates code, creates PR
- Subagent monitors PR for comments and responds
- Main agent monitors for merged PRs and cleans up
- Docker
- Gitea instance with API access
- Valid Gitea token with repo and issue permissions
Set the following environment variables:
GITEA_BASE_URL: Base URL for Gitea API (e.g.,https://gitea.example.com/api/v1)GITEA_TOKEN: Personal access token for Gitea APIGITEA_REPOS: Comma-separated list of repositories to monitor (e.g.,owner/repo1,owner/repo2)POLLING_FREQUENCY: Polling interval in seconds (default: 60)ISSUE_LABEL_RESERVE: Label for reserving issues (default:agent-working)LOG_LEVEL: Logging level (default:INFO)LOG_FILE: Log file path (default:kilocode_agent.log)AGENT_CLI: Which CLI to run for code generation (kilocodeorcodex, default:kilocode)KILOCODE_ARGS: Override kilocode CLI args (default:-a -m orchestrator -j)CODEX_EXEC_ARGS: Override codex exec args (default:--full-auto)CODEX_PROMPT_MODE: How to pass prompts to codex (stdinorarg, default:stdin)CODEX_MODEL: Optional codex model name (passed as-m)PROMPT_TEMPLATE_PATH: Path to the prompt template file (default:prompt_template.txt)MAX_CONTEXT_CHARS: Max characters of repo context injected into prompts (default:8000)WORKSPACE_DIR: Directory where subagent clones repositories (default:/workspace)
-
Build and push the image:
pip install -e . ship-imageOr manually:
podman build --platform linux/arm64/v8 -t kilo-agents:latest . podman tag kilo-agents:latest homenas.tail38254.ts.net:5001/kilo-agents:latest podman push homenas.tail38254.ts.net:5001/kilo-agents:latest -
Run the container:
podman run -e GITEA_BASE_URL=... -e GITEA_TOKEN=... -e GITEA_REPOS=... homenas.tail38254.ts.net:5001/kilo-agents:latest
-
Install dependencies:
pip install -r requirements.txt
-
Install kilocode CLI:
curl -fsSL https://kilo.ai/install.sh | sh -
(Optional) Install Codex CLI:
npm install -g @openai/codex
-
Run the agent:
python main.py
To use Codex CLI for code generation, set AGENT_CLI=codex.
Codex CLI can authenticate either via browser login (codex --login) or by using an API key. For headless servers, use the API key flow.
-
Install the CLI:
npm install -g @openai/codex
-
Export an API key in the environment (recommended):
export OPENAI_API_KEY="<OAI_KEY>"
-
Verify the CLI is available:
codex --version
-
Run this agent with Codex:
export AGENT_CLI=codex python main.py
Run the integration test to verify API connectivity and basic functionality:
python test_integration.pyThe test checks:
- Configuration validation
- Gitea API connectivity
- Repository access
- Label creation
Logs are written to kilocode_agent.log with the format:
timestamp - [process_type] - level - message
Where process_type is either main or subagent to distinguish log sources.
The agent uses the following labels:
ISSUE_LABEL_RESERVE: Applied to issues being worked on by subagents
- Store Gitea tokens securely
- Ensure the token has appropriate permissions
- The agent will create commits and PRs in monitored repositories