Triage newly opened GitHub issues with an assistant
Python · LLM apps · intermediate · modification
Adds an issue-triage assistant to our GitHub app. When an issue is opened, the agent reads it, can browse the repository's files to find the code it is about, and is instructed to finish with one triage comment: the likely area, the files worth reading and what information is missing. It runs unattended, so the limits live in the tool layer rather than the prompt: arguments are checked against the tool schemas before anything runs, the agent is kept to the issue's repository, comments go only on the issue that started the run and at most once, and the issue text reaches the model only as the user message. GitHub failures come back to the model as short errors, with the detail in the log. Tried it on a sandbox repository with a handful of real bug reports: each got one comment pointing at the right module.
Python 3.12 service behind the org's GitHub App. `app/webhooks/receiver.py` (existing, unchanged) verifies `X-Hub-Signature-256`, answers GitHub 202 and enqueues the delivery; the job worker calls `handlers.dispatch` once per delivery, never retries, and logs any exception a handler raises. The payload is GitHub's `issues` webhook payload: `issue.number` is a positive integer, `issue.title` a non-empty string, `issue.body` a string of up to 65,536 characters or `null`. The app is installed on all of the org's repositories, public and private, with contents read and issues write, and the service calls GitHub with that installation token; the org's public repositories accept issues from any GitHub account. `app/github_client.py` (existing, unchanged) wraps the REST API with that token: `list_directory(owner, repo, path)` returns a list of `{"name", "type"}` dicts (at most 1,000), `get_file(owner, repo, path)` returns the file's text (files up to 1 MB, decoded as UTF-8), `post_comment(owner, repo, issue_number, body)` returns nothing; each URL-encodes its arguments and raises `github_client.GitHubError` (attribute `status`: the HTTP status, or 0 when GitHub was unreachable) on any failure, including a missing path or one of the wrong kind. Owner and repository names are ASCII (GitHub's rule). `app/agents/release_notes.py` is the existing release-notes agent.
Requirements
- For every verified `issues` delivery whose `action` is `opened`, run the triage agent once for that issue, on any repository the org's GitHub App is installed on. The agent may look at the issue's repository and is instructed to end by posting one triage comment on the issue; a run that ends without one (the model stops calling tools first, or the 8 completion calls run out) posts nothing and logs that no comment was posted. Other actions and other events are handled as before (`release` unchanged, the rest ignored).
- Scope (the security team's rule for unattended agents): a triage run touches exactly one repository, the one the issue was opened in. Every tool call, read or write, whose `owner`/`repo` names any other repository is refused before GitHub is called, and the model gets an error tool result instead. Owner and repository names compare case-insensitively, as GitHub treats them. Comments go only on the issue being triaged, and a run makes at most one comment-posting attempt: a failed attempt is logged and not retried.
- Nobody confirms the agent's tool calls: it runs from the job worker with no human in the loop, so requirement 2 is enforced in code, whatever the model asks for. The system prompt is a constant; the issue's title and body reach the model only as the user message.
- The agent uses the openai 1.x SDK with the pinned snapshot `gpt-4.1-mini-2025-04-14`, at most 8 completion calls per run (a completion call is one `client.chat.completions.create()` invocation, the SDK's own retries included) and at most one tool call per response. It offers exactly three tools, all arguments required and no others: `list_directory(owner, repo, path)` (empty `path` is the root), `get_file(owner, repo, path)`, `post_comment(owner, repo, issue_number, body)`. Arguments are validated against the declared schema before anything runs (JSON Schema integers: `5.0` counts as `5`, `true` is not an integer; `issue_number` at least 1; `body` 1 to 4,000 characters). An unknown tool, invalid JSON, failed validation, a refused call or a GitHub failure goes back to the model as a `{"error": ...}` tool result with a short message; GitHub's error detail goes to the log only.
- File contents go back to the model cut to their first 20,000 characters, with `truncated` saying whether anything was cut.
Files touched
- app/webhooks/handlers.py
- app/agents/issue_triage.py