GitHub Issue and Review Bot

medium15 mingithub-bot.ts

You want an agent that answers when people mention it in issues, pull requests and code reviews, in the same place they asked.

What it shows

  • Run a Gateway with githubChannel() on a webhook server of its own
  • Every issue and pull request is a conversation, and every review thread one of its own, answered with a reply in it
  • Deliveries are checked against the webhook secret and handled once, even when GitHub sends one again
  • Only the repository owner, members and collaborators reach the agent by default (associations, authors), since what people write steers it
  • The bot answers mentions of @login (or every event with trigger: 'all'), skips its own comments and other bots

The code

github-bot.ts
import { Agent, Cogitator } from '@cogitator-ai/core';
import { Gateway, githubChannel } from '@cogitator-ai/channels';

const token = process.env.GITHUB_CHANNEL_TOKEN;
const secret = process.env.GITHUB_WEBHOOK_SECRET;
const apiKey = process.env.GOOGLE_API_KEY;
if (!token || !secret || !apiKey) {
  throw new Error('Set GITHUB_CHANNEL_TOKEN, GITHUB_WEBHOOK_SECRET and GOOGLE_API_KEY');
}

const github = githubChannel({
  token,
  webhook: { secret, port: 8787 },
  repositories: ['acme/*'],
});

const agent = new Agent({
  name: 'github-assistant',
  model: 'google/gemini-3.5-flash-lite',
  instructions: 'You help maintainers on GitHub. Be precise and brief, and use GitHub Markdown.',
});

const cogitator = new Cogitator({
  llm: { providers: { google: { apiKey } } },
  memory: { adapter: 'memory' },
});
const memory = await cogitator.getMemory();

const gateway = new Gateway({
  agent,
  cogitator,
  channels: [github],
  ...(memory && { memory }),
  reactions: { enabled: true },
});

await gateway.start();
console.log(`@${github.login} is listening on http://localhost:8787/github/webhook`);

Run it

install · bash
pnpm add @cogitator-ai/core @cogitator-ai/channels
EnvironmentGITHUB_CHANNEL_TOKENGITHUB_WEBHOOK_SECRETGOOGLE_API_KEY
run · bash
npx tsx github-bot.ts

Or run the full example from a clone of the repository (keys in .env):

repository · bash
npx tsx examples/channels/06-github-bot.ts

Learn more