Self-healing LangSmith eval pipeline service. It runs on FastAPI + APScheduler inside one Docker container, proposes atomic fixes with Claude Sonnet, validates score improvements, opens draft PRs, and posts Slack notifications. Human review is always required.
At AdQuick, I was maintaining an AI Copilot with 53 tool calls.
When evals started failing, debugging why an LLM picks the wrong tool was a manual nightmare — reading traces, tweaking prompts, updating tool descriptions, rerunning evals. Each tool took 2-3 days to fix.
We built a golden dataset for each tool using LLM-assisted examples. Fast to build — but LLMs generate subtly wrong examples too. Our LLM-as-judge score came back at 63%. No systematic way to find what was broken.
So I built this. A nightly loop that diagnoses failures, asks Claude Sonnet for one precise atomic fix, reruns evals, and drafts a PR if the score improves. Humans always approve.
After the first run, score jumped to 80%+.
The unexpected insight: 3 tools stayed at exactly 0% while everything else improved. That shouldn't happen. Zero movement meant the golden dataset examples themselves were wrong — not the code. The self-healer exposed bad training data by elimination.
git clone https://github.com/zoosphar/langsmith-self-heal
cp healer/.env.example healer/.env
nano healer/.env
docker-compose -f healer/docker-compose.yml up -d- Nightly cron in-container triggers
/heallogic. - Service fetches current LangSmith scores and failing traces/examples.
- Failures are bucketed into
prompt,tool_schema,tool_description,wiring_code. - Claude Sonnet returns one atomic diff proposal.
- Service reads tool source directly via GitHub API (
GITHUB_TOOLS_PATH), creates candidate branch commit(s), and runs eval rerun mode:EVAL_MODE=local: runsEVAL_SCRIPT_PATH --tool <tool_name>.EVAL_MODE=github_actions: dispatchesGITHUB_ACTIONS_WORKFLOWwithtool_nameinput and polls completion every 30s.
- Service waits before score read (
POST_EVAL_LANGSMITH_WAIT_SECONDS, plus GitHub Actions extra wait) to avoid stale LangSmith scores. - If score improvement is
>= HEAL_THRESHOLD, it drafts a PR and sends Slack notification. - Nothing auto-merges.
| Method | Endpoint | Purpose |
|---|---|---|
| POST | /heal |
Trigger full heal run manually. |
| POST | /heal/{tool_name} |
Trigger heal run for one tool. |
| GET | /status |
Return last run summary and per-tool results. |
| GET | /scores |
Return latest observed eval scores per tool. |
| GET | /anomalies |
Return tools flagged as bad examples (stuck at 0%). |
- APScheduler runs inside the same FastAPI container.
- Cron expression is configured via
CRON_SCHEDULE. - On startup, the app logs the next scheduled run time.
- No Redis, Celery, Kubernetes CronJob, or external scheduler is required.
+-------------------------+
| FastAPI + APScheduler |
| /heal + nightly cron |
+-----------+-------------+
|
v
+-------------------+
| LangSmith Fetcher |
| scores + failures |
+---------+---------+
|
v
+-------------------+
| Failure Bucketer |
+---------+---------+
|
v
+-------------------+
| Claude Suggester |
| atomic diff JSON |
+---------+---------+
|
v
+-------------------+
| GitHub Notifier |
| read source + |
| candidate branch |
+---------+---------+
|
v
+-------------------+
| Evaluator |
| local or actions |
+---------+---------+
|
v
+-------------------+
| Compare Scores |
| threshold check |
+---------+---------+
|
+------------+-------------+
| |
v v
+----------------------+ +----------------------+
| Draft GitHub PR | | Skip / Continue Tool |
| + Slack Notification | | (graceful failure) |
+----------------------+ +----------------------+
Copy .env.example to .env and set:
LANGSMITH_API_KEY,LANGSMITH_PROJECT_NAME,LANGSMITH_DATASET_NAMEANTHROPIC_API_KEYGITHUB_TOKEN,GITHUB_REPO,GITHUB_TOOLS_PATH,GITHUB_DEFAULT_BRANCHEVAL_MODE(localorgithub_actions)EVAL_SCRIPT_PATH(used in local mode)GITHUB_ACTIONS_WORKFLOW,GITHUB_EVAL_WORKFLOW_REF,GITHUB_EVAL_POLL_INTERVAL_SECONDS,GITHUB_EVAL_TIMEOUT_SECONDSPOST_EVAL_LANGSMITH_WAIT_SECONDS,GITHUB_ACTIONS_EXTRA_LANGSMITH_WAIT_SECONDSSLACK_WEBHOOK_URLHEAL_THRESHOLD,CRON_SCHEDULE
cd healer
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000Building agentic AI workflows and struggling with eval coverage?
I help teams design and implement eval pipelines for production agentic systems with 10+ tools.
reach out: avrlsngh@gmail.com