DEV Community

chinaabin
chinaabin

Posted on • Originally published at tutorial.gogoai.xin

Build an AI Agent for GitHub Issues with LangGraph

Build an AI Agent for GitHub Issues with LangGraph

Imagine an AI agent that automatically triages, labels, comments on, and closes your GitHub issues — without you lifting a finger. In this tutorial, you'll build exactly that using LangGraph (a framework for building stateful AI agent workflows) and Node.js. By the end, you'll have a fully autonomous agent that reads new issues, analyzes them with an LLM, and takes real actions on your repository.

This project is ideal for developers who want to move beyond simple chatbots and build agents that interact with real-world APIs.

What You'll Learn

  • How to design a multi-step AI agent with LangGraph's state graph
  • How to connect an LLM to the GitHub REST API using custom tools
  • How to build a decision loop where the agent autonomously chooses actions
  • How to test and run your agent locally with Node.js

Prerequisites You'll Need Before Starting

Before diving in, make sure you have the following tools and accounts ready:

  • Node.js v18 or higher installed on your machine
  • A GitHub account with a repository you can test against
  • A GitHub Personal Access Token (PAT) with repo scope
  • An OpenAI API key (or another LLM provider key)
  • Basic familiarity with JavaScript/TypeScript and REST APIs
  • A code editor like VS Code

You don't need prior experience with LangGraph. We'll explain every concept as we go.

Understanding How the Agent Architecture Works

Before writing code, let's understand what we're building. The agent follows a ReAct loop (Reason + Act), where it thinks about what to do, takes an action, observes the result, and then decides what to do next.

Here's the high-level flow:

  1. The agent fetches open GitHub issues from your repository
  2. It analyzes each issue using an LLM to understand intent and severity
  3. It decides on an action: label the issue, post a comment, assign it, or close it
  4. It executes that action via the GitHub API
  5. It loops back to check if more actions are needed

LangGraph makes this possible by letting you define a state graph — a directed graph where each node is a function and edges define the flow between them. Unlike simple chains, LangGraph supports cycles, which means your agent can loop and make multiple decisions autonomously.

Setting Up Your Node.js Project

Create a new project directory and initialize it with npm. Open your terminal and run the following commands:

mkdir github-issue-agent
cd github-issue-agent
npm init -y
Enter fullscreen mode Exit fullscreen mode

Now install the required dependencies. You'll need LangGraph, LangChain core modules, the OpenAI integration, and the Octokit library for GitHub API access.

npm install @langchain/langgraph @langchain/core @langchain/openai @octokit/rest dotenv zod
Enter fullscreen mode Exit fullscreen mode

Create a .env file in your project root to store your API keys securely:


bash
OPENAI_API_KEY=sk-your-openai-key-here
GITHUB_TOKEN=ghp_your-github-token-here
GITHUB_OWNER=your-github-user

---

📖 **[Read the full tutorial on AI Tutorials →](https://tutorial.gogoai.xin/tutorial/build-an-ai-agent-for-github-issues-with-langgraph)**
Enter fullscreen mode Exit fullscreen mode

Top comments (0)