惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
罗磊的独立博客
B
Blog
博客园_首页
A
About on SuperTechFans
有赞技术团队
有赞技术团队
V
V2EX
U
Unit 42
I
InfoQ
IT之家
IT之家
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
H
Help Net Security

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
LangGraph's Routing Is LLM-Guessing. I Wrote 50 Lines of ...
WAFER · 2026-06-25 · via DEV Community

WAFER

Every time your LangGraph agent sees "check nginx logs", it might call a different tool.

That's not an exaggeration. LangGraph's routing is driven by an LLM prompt — and prompts aren't reproducible. Same input, different day, different LLM mood, different tool selected.

I spent months debugging this. Every wrong route meant tweaking a prompt, hoping the next call would be better. It never was.

So I wrote something different.

The Problem: Routing by LLM is fragile

LangGraph is great at orchestrating multi-step agent workflows. But the first step — "what tool should I use?" — is a black box.

You define a prompt, the LLM decides. If it chooses wrong, you can't debug it. You can only guess: was the prompt not specific enough? Too specific? Wrong example?

This is the routing problem: given user input, which domain or tool should handle it? LangGraph leaves this to the LLM. I think it shouldn't.

The Fix: 50 Lines of YAML + Python

from decide_router import RouteTable

rt = RouteTable("routes.yaml")
rule, _ = rt.match("check nginx error logs")
# rule.domain → "monitoring" — always, every time

No LLM call. No prompt. Just a YAML file and 50 lines of matching logic.

The YAML defines domains with keywords and regex patterns:

domains:
  monitoring:
    priority: 100
    keywords: [log, error, nginx, monitor, health, status]
    patterns: ["(check|look).*(log|status|error)"]
  coding:
    priority: 100
    keywords: [code, script, deploy, write]
  human:
    priority: 100
    keywords: [delete production, restart cluster]
    require_confirm: true

Plug it into LangGraph as a node:

from langgraph.graph import Graph
from decide_router import RouteTable

rt = RouteTable("routes.yaml")

def routing_node(state):
    rule, _ = rt.match(state["input"])
    state["domain"] = rule.domain if rule else "unknown"
    return state

graph = Graph()
graph.add_node("decide_route", routing_node)
graph.set_entry_point("decide_route")

Your LangGraph agent now routes with rules, not guesses. Same input → same domain. Every time.

The Surprising Part: It Learns From Corrections

The best part wasn't planned — it emerged from using it.

I noticed I kept correcting wrong routes. "That's monitoring, not coding." Every correction was a signal. So I added a feedback cache:

# User corrects once → remembers immediately
rt.record_feedback("check nginx errors", "monitoring")

Same correction 3 times → becomes a permanent routing rule at priority 70. Rules not used in 30 days auto-delete. The system gets smarter with every correction. No fine-tuning. No prompt engineering.

The core module is one file, 200 lines of Python. Read the whole thing in 5 minutes.

Try It

pip install decide-router

Or browse the code: github.com/chex0210-crypto/decide-router


I built this because I was tired of guessing why my agent picked the wrong tool. If you've had the same frustration, star the repo — it helps other people find it.