Chapter 21 · LangChain LangChain Track CLI Project

An RCA agent that gathers real evidence before it blames anything.

A production LangChain tool-calling agent for root-cause analysis. When a build goes red it pulls the Jenkins console log, the latest GitHub commits, and a live health ping of the app under test, then delivers one most-likely root cause with the evidence and a concrete fix.

01 What students build

The RCA agent from the LangChain production trio. Three real @tool functions give the agent eyes: fetch_test_logs tails the Jenkins console output (where Playwright failures land), recent_commits lists what changed on main, and service_health pings the live app under test. A Groq llama-3.3-70b-versatile ReAct loop decides which tools to call, in what order, and only then writes its verdict. When Jenkins is unreachable the log tool self-falls-back to a clearly labelled sample log, so the agent never dies in a shipped environment.

Evidence First

The system prompt forces tool calls before conclusions: check the log, check the commits, check whether the site is even up, then reason.

Three Real Sources

Jenkins REST consoleText, the GitHub commits API, and a timed HTTP GET of the app under test · no mocked inputs.

Graceful Fallback

401, 404 or an unreachable Jenkins returns a banner-labelled sample log instead of crashing, so the RCA still completes with what it has.

02 Architecture

Question"why is the build red?"
──▶
RCA Agentcreate_agent · ReAct loop
──▶
fetch_test_logsJenkins consoleText
──▶
recent_commitsGitHub API · main
──▶
service_healthHTTP ping + latency
──▶
Verdictroot cause + fix
groq llama-3.3-70b-versatile · jenkins self-falls-back to a labelled sample log

03 Live demo (simulated with sample data)

This is a UI walkthrough with pre-baked sample data so you can feel the agent's tool loop without a Jenkins server. In the course you run the real thing: Groq + LangChain against your own Jenkins job, GitHub repo and health URL.

python src/prod/rca_agent_prod.py demo · sample data

04 Inputs & outputs

What goes in

  • A natural-language question ("is the automation healthy?")
  • Jenkins job + build number (or lastBuild) via .env
  • GitHub repo of the automation framework
  • Health URL of the app under test

What comes out

  • The full tool-call trace: every fetch, every result
  • Single most-likely root cause with its evidence
  • A blame candidate: the suspicious commit, if any
  • One concrete fix, plus what was ruled out and why

05 How it's built

Write three @tool functions with rich docstrings: the docstring is the API the LLM reads to decide when to call each tool.
Tail the Jenkins console log (last 4,000 chars) because Playwright failures and stack traces land at the end.
List recent commits on main via the GitHub API: what changed lately is the prime suspect for new failures.
Time an HTTP GET of the app under test to rule "the site is down" in or out.
Wire the tools into create_agent with a system prompt that demands evidence before conclusions.
Add fallbacks: unreachable Jenkins returns a banner-labelled sample log so the agent keeps reasoning instead of crashing.

06 Tech stack

Python · LangChaincreate_agent (ReAct)Groq llama-3.3-70b-versatileJenkins REST consoleTextGitHub commits APIrequests health ping@tool functionsdotenv config