0

GitHub

The GitHub interface receives a GitHub App's webhook deliveries for the repositories you choose and hands each verified event to a handler. Unlike chat interfaces, it doesn't run an agent itself: the handler decides what an event becomes, for example a Company Task. AgentOS still needs an agent, t

Example · مثالgithub

Content

GitHub

The GitHub interface receives a GitHub App's webhook deliveries for the repositories you choose and hands each verified event to a handler. Unlike chat interfaces, it doesn't run an agent itself: the handler decides what an event becomes, for example a Company Task. AgentOS still needs an agent, team, workflow, knowledge base or database to start; basic.py passes a database.

What the interface does before calling the handler:

  • Refuses deliveries without a valid X-Hub-Signature-256 signature for the webhook's secret (400 when missing, 403 when wrong).
  • Answers GitHub's ping.
  • Reads both of GitHub's content types: application/json, and the form encoding (payload=<JSON>) that the REST API uses by default for repository webhooks.
  • Ignores, with a 200 and a reason: repositories it does not watch, events it does not handle (default issues.opened and issue_comment.created), and bots, including the App's own [bot] account, so what the App posts isn't handled again. handle_bot_events=True accepts bots such as Dependabot; the handler must then recognize the App's own events itself.
  • Passes the installation that sent the delivery as event.installation_id, so the handler can act with that installation's token.
  • Answers a redelivery of a delivery it already handled from the first run ("duplicate": true) without calling the handler again. A redelivery that arrives while the first is still running waits for it.

The handler must record the event before it returns. GitHub does not retry a failed delivery on its own, so the interface reports success (202) only after the handler returns, and a handler error returns 500 so the delivery can be redelivered from the App's Advanced settings; a failed delivery is then handled again.

Writing a handler:

  • Return within a few seconds. GitHub gives up on a delivery after 10 seconds and marks it failed. Record the event, return, and run slow work afterwards; basic.py reads the issue back that way.
  • Sync or async. A sync handler runs in the threadpool, so it doesn't hold up other deliveries.
  • Return a JSON-serializable dict, or nothing. It's sent back under "result". A result that can't be encoded is left out; the delivery still succeeds, since the event is already recorded.
  • Make it safe to receive an event twice. Duplicate detection is per process and lasts ten minutes; across restarts and replicas, key the records the handler creates on something stable such as the repository and issue number.

GET <prefix>/status answers {"status": "available"}, to check the interface is mounted.

agno.utils.github_auth.GitHubAppCredentials mints the installation tokens: it signs a short-lived JWT with the App's private key and exchanges it for a token valid for an hour, cached per installation. Uninstalling the App, or removing a repository from it, revokes that access.

Files

| File | What it teaches | |---|---| | basic.py | Serve the interface for one repository and read each new issue back with the App's installation token; --check sends signed deliveries in process. |

Prerequisites

./scripts/demo_setup.sh

--check needs nothing else. Serving for a real repository needs ngrok (brew install ngrok) and a GitHub App, set up below.

Set up a GitHub App on a private repository

  1. Start ngrok and copy the https://….ngrok-free.app forwarding URL it prints. The App's webhook points there.
   ngrok http 7777
  1. Generate the webhook secret once, so every terminal uses the same value:
   openssl rand -hex 32 > ~/.agno_github_webhook_secret
  1. Create the App: GitHub → Settings → Developer settings → GitHub Apps → New GitHub App (for an organization: the organization's Settings → Developer settings → GitHub Apps).

| Field | Value | |---|---| | GitHub App name | Any unique name, e.g. <you>-agno-dev | | Homepage URL | Any URL, e.g. your repository's | | Webhook → Active | Checked | | Webhook URL | <ngrok URL>/github/events | | Webhook secret | The contents of ~/.agno_github_webhook_secret | | Repository permissions | Issues: Read and write; Contents: Read-only; Metadata: Read-only | | Subscribe to events | Issues, Issue comment | | Where can this GitHub App be installed? | Only on this account |

Leave every other permission at No access.

  1. Note the App ID at the top of the App's General page, then under Private keys click Generate a private key. GitHub downloads a .pem file; keep it outside the repository.
  1. Install the App: on the App's page, Install App → your account → Only select repositories → your private repository → Install.
  1. Remove any repository webhook you created earlier for the same events, or each event arrives twice:
   gh api repos/<owner>/<repo>/hooks --jq '.[] | "\(.id) \(.config.url)"'
   gh api -X DELETE repos/<owner>/<repo>/hooks/<id>

Run

# Local check, no GitHub
.venvs/demo/bin/python cookbook/05_agent_os/32_github/basic.py --check

# Serve for the App
unset AGENT_OS_PORT    # serve on 7777, where ngrok forwards
export GITHUB_WEBHOOK_SECRET=$(cat ~/.agno_github_webhook_secret)
export GITHUB_APP_ID=<App ID>
export GITHUB_APP_PRIVATE_KEY_PATH=<path to the .pem>
export GITHUB_REPOSITORY=<owner>/<repo>
.venvs/demo/bin/python cookbook/05_agent_os/32_github/basic.py

Open an issue on the repository. The server prints the event, then reads the issue back with the installation's token:

issues.opened on <owner>/<repo> #2 by <you>: Export fails
Read #2 with installation 12345678's token: open, 0 comments

GITHUB_APP_PRIVATE_KEY can hold the PEM contents instead of a path.

Check the deliveries

  • The App's Advanced tab lists recent deliveries with the response, and can redeliver one.
  • ngrok's inspector at http://127.0.0.1:4040 shows each request and response, and can replay one.
  • A free ngrok URL changes on every restart; update the App's Webhook URL when it does.

Without an App

A repository webhook with a personal token also works for receiving events: set the same secret on the webhook and leave GITHUB_APP_ID unset. Comments posted with a personal token appear as that person's, so they aren't ignored as a bot's; prefer an App when the handler will post.

gh api repos/$GITHUB_REPOSITORY/hooks -X POST -f name=web \
  -f 'config[url]=<ngrok URL>/github/events' -f 'config[content_type]=json' \
  -f "config[secret]=$GITHUB_WEBHOOK_SECRET" \
  -f 'events[]=issues' -f 'events[]=issue_comment'

Source and license

Source
Agno
Original
agno-agi/agno/cookbook/05_agent_os/32_github
License
Apache-2.0