1:"$Sreact.fragment" 2:I[41596,["/_next/static/chunks/51cf3403df3ab8db.js"],"ThemeProvider"] 3:I[99623,["/_next/static/chunks/1f465ca74a71847d.js","/_next/static/chunks/6628e8793cd41c7c.js"],"default"] 4:I[1810,["/_next/static/chunks/1f465ca74a71847d.js","/_next/static/chunks/6628e8793cd41c7c.js"],"default"] 6:I[39271,["/_next/static/chunks/1f465ca74a71847d.js","/_next/static/chunks/6628e8793cd41c7c.js"],"OutletBoundary"] 7:"$Sreact.suspense" 9:I[39271,["/_next/static/chunks/1f465ca74a71847d.js","/_next/static/chunks/6628e8793cd41c7c.js"],"ViewportBoundary"] b:I[39271,["/_next/static/chunks/1f465ca74a71847d.js","/_next/static/chunks/6628e8793cd41c7c.js"],"MetadataBoundary"] d:I[79129,[],"default"] :HL["/_next/static/chunks/c2a0804a12c1a234.css","style"] :HL["/_next/static/media/1b99372b3eaef0c8-s.p.758e15a8.woff2","font",{"crossOrigin":"","type":"font/woff2"}] :HL["/_next/static/media/797e433ab948586e-s.p.dbea232f.woff2","font",{"crossOrigin":"","type":"font/woff2"}] :HL["/_next/static/media/caa3a2e1cccd8315-s.p.853070df.woff2","font",{"crossOrigin":"","type":"font/woff2"}] 0:{"P":null,"b":"3CCc4JxoD54WNKxdcWa8x","c":["","blog","building-ai-agents-with-langgraph"],"q":"","i":false,"f":[[["",{"children":["blog",{"children":[["slug","building-ai-agents-with-langgraph","d"],{"children":["__PAGE__",{}]}]}]},"$undefined","$undefined",true],[["$","$1","c",{"children":[[["$","link","0",{"rel":"stylesheet","href":"/_next/static/chunks/c2a0804a12c1a234.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}],["$","script","script-0",{"src":"/_next/static/chunks/51cf3403df3ab8db.js","async":true,"nonce":"$undefined"}]],["$","html",null,{"lang":"en","suppressHydrationWarning":true,"children":[["$","head",null,{"children":["$","script",null,{"type":"application/ld+json","dangerouslySetInnerHTML":{"__html":"{\"@context\":\"https://schema.org\",\"@type\":\"Person\",\"name\":\"Raad Kasem\",\"url\":\"https://raadkasem.dev\",\"jobTitle\":\"Senior Software Engineer & Team Lead\",\"worksFor\":{\"@type\":\"Organization\",\"name\":\"CanGuru\"},\"alumniOf\":[{\"@type\":\"CollegeOrUniversity\",\"name\":\"Syrian Virtual University\"},{\"@type\":\"CollegeOrUniversity\",\"name\":\"Tishreen University\"}],\"knowsAbout\":[\"Artificial Intelligence\",\"Machine Learning\",\"LangChain\",\"LangGraph\",\"FastAPI\",\"Python\",\"PHP\",\"Laravel\",\"RAG Pipelines\"],\"sameAs\":[\"https://github.com/raadkasem\",\"https://linkedin.com/in/raad-kasem\"]}"}}]}],["$","body",null,{"className":"geist_a71539c9-module__T19VSG__variable geist_mono_8d43a2aa-module__8Li5zG__variable outfit_a0e3ceb4-module__1hgF0q__variable antialiased","children":["$","$L2",null,{"children":["$","$L3",null,{"parallelRouterKey":"children","error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L4",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":404}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],[]],"forbidden":"$undefined","unauthorized":"$undefined"}]}]}]]}]]}],{"children":[["$","$1","c",{"children":[null,["$","$L3",null,{"parallelRouterKey":"children","error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L4",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","forbidden":"$undefined","unauthorized":"$undefined"}]]}],{"children":[["$","$1","c",{"children":[null,["$","$L3",null,{"parallelRouterKey":"children","error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L4",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","forbidden":"$undefined","unauthorized":"$undefined"}]]}],{"children":[["$","$1","c",{"children":["$L5",[["$","script","script-0",{"src":"/_next/static/chunks/e1faea17a9e9ed14.js","async":true,"nonce":"$undefined"}]],["$","$L6",null,{"children":["$","$7",null,{"name":"Next.MetadataOutlet","children":"$@8"}]}]]}],{},null,false,false]},null,false,false]},null,false,false]},null,false,false],["$","$1","h",{"children":[null,["$","$L9",null,{"children":"$La"}],["$","div",null,{"hidden":true,"children":["$","$Lb",null,{"children":["$","$7",null,{"name":"Next.Metadata","children":"$Lc"}]}]}],["$","meta",null,{"name":"next-size-adjust","content":""}]]}],false]],"m":"$undefined","G":["$d",[]],"S":true} e:I[97333,["/_next/static/chunks/51cf3403df3ab8db.js","/_next/static/chunks/e1faea17a9e9ed14.js"],""] 5:["$","div",null,{"className":"min-h-screen bg-[var(--bg)]","children":["$","article",null,{"className":"section-container pt-32 max-w-3xl","children":[["$","$Le",null,{"href":"/blog","className":"inline-flex items-center gap-2 text-sm text-muted hover:text-accent transition-colors mb-8","children":[["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-arrow-left h-4 w-4","aria-hidden":"true","children":[["$","path","1l729n",{"d":"m12 19-7-7 7-7"}],["$","path","x3x0zl",{"d":"M19 12H5"}],"$undefined"]}],"Back to Blog"]}],["$","header",null,{"className":"mb-10","children":[["$","div",null,{"className":"flex flex-wrap items-center gap-3 text-sm text-muted mb-4","children":[["$","span",null,{"className":"inline-flex items-center gap-1.5","children":[["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-calendar h-3.5 w-3.5","aria-hidden":"true","children":[["$","path","1cmpym",{"d":"M8 2v4"}],["$","path","4m81vk",{"d":"M16 2v4"}],["$","rect","1hopcy",{"width":"18","height":"18","x":"3","y":"4","rx":"2"}],["$","path","8toen8",{"d":"M3 10h18"}],"$undefined"]}],"January 15, 2025"]}],["$","span",null,{"className":"inline-flex items-center gap-1.5","children":[["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-clock h-3.5 w-3.5","aria-hidden":"true","children":[["$","circle","1mglay",{"cx":"12","cy":"12","r":"10"}],["$","path","mmk7yg",{"d":"M12 6v6l4 2"}],"$undefined"]}],"4 min read"]}]]}],["$","h1",null,{"className":"font-[family-name:var(--font-outfit)] text-3xl font-bold tracking-tight text-foreground sm:text-4xl lg:text-5xl","children":"Building Production-Ready AI Agents with LangGraph"}],["$","div",null,{"className":"mt-4 flex flex-wrap gap-2","children":[["$","span","AI",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"AI"}],["$","span","LangGraph",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"LangGraph"}],["$","span","LangChain",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"LangChain"}],["$","span","Multi-Agent Systems",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"Multi-Agent Systems"}],["$","span","Python",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"Python"}]]}]]}],["$","div",null,{"className":"prose-custom","children":"$Lf"}]]}]}] a:[["$","meta","0",{"charSet":"utf-8"}],["$","meta","1",{"name":"viewport","content":"width=device-width, initial-scale=1"}]] 10:I[39406,["/_next/static/chunks/1f465ca74a71847d.js","/_next/static/chunks/6628e8793cd41c7c.js"],"IconMark"] 8:null c:[["$","title","0",{"children":"Building Production-Ready AI Agents with LangGraph | Raad Kasem"}],["$","meta","1",{"name":"description","content":"A deep dive into designing multi-agent systems with LangGraph's state-machine orchestration, including patterns for tool routing, memory management, and fault-tolerant agent loops."}],["$","link","2",{"rel":"author","href":"https://raadkasem.dev"}],["$","meta","3",{"name":"author","content":"Raad Kasem"}],["$","meta","4",{"name":"keywords","content":"Raad Kasem,Software Engineer,AI Engineer,LangChain,LangGraph,RAG,FastAPI,Full Stack Developer,Team Lead,LLM,Machine Learning"}],["$","meta","5",{"name":"creator","content":"Raad Kasem"}],["$","meta","6",{"name":"robots","content":"index, follow"}],["$","meta","7",{"name":"googlebot","content":"index, follow, max-video-preview:-1, max-image-preview:large, max-snippet:-1"}],["$","meta","8",{"property":"og:title","content":"Raad Kasem — AI-focused Senior Software Engineer"}],["$","meta","9",{"property":"og:description","content":"Senior Software Engineer & Team Lead with 7+ years building production-ready AI/LLM-powered solutions."}],["$","meta","10",{"property":"og:url","content":"https://raadkasem.dev"}],["$","meta","11",{"property":"og:site_name","content":"Raad Kasem"}],["$","meta","12",{"property":"og:locale","content":"en_US"}],["$","meta","13",{"property":"og:image:alt","content":"Raad Kasem — AI-focused Senior Software Engineer"}],["$","meta","14",{"property":"og:image:type","content":"image/png"}],["$","meta","15",{"property":"og:image","content":"https://raadkasem.dev/opengraph-image?6524c747f4eb7f2a"}],["$","meta","16",{"property":"og:image:width","content":"1200"}],["$","meta","17",{"property":"og:image:height","content":"630"}],["$","meta","18",{"property":"og:type","content":"website"}],["$","meta","19",{"name":"twitter:card","content":"summary_large_image"}],["$","meta","20",{"name":"twitter:title","content":"Raad Kasem — AI-focused Senior Software Engineer"}],["$","meta","21",{"name":"twitter:description","content":"Senior Software Engineer & Team Lead with 7+ years building production-ready AI/LLM-powered solutions."}],["$","meta","22",{"name":"twitter:image:alt","content":"Raad Kasem — AI-focused Senior Software Engineer"}],["$","meta","23",{"name":"twitter:image:type","content":"image/png"}],["$","meta","24",{"name":"twitter:image","content":"https://raadkasem.dev/opengraph-image?6524c747f4eb7f2a"}],["$","meta","25",{"name":"twitter:image:width","content":"1200"}],["$","meta","26",{"name":"twitter:image:height","content":"630"}],["$","link","27",{"rel":"icon","href":"/icon?51d30ca368f9894e","alt":"$undefined","type":"image/png","sizes":"32x32"}],["$","$L10","28",{}]] f:[["$","h1",null,{"className":"font-[family-name:var(--font-outfit)] text-3xl font-bold tracking-tight text-foreground mt-10 mb-4 first:mt-0","children":"Building Production-Ready AI Agents with LangGraph"}],"\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"After spending the past two years building AI-powered systems in production — from medical diagnosis assistants serving thousands of doctors to automated customer support triage — I've learned that the gap between a working prototype and a reliable production system is enormous. In this post, I'll share the patterns and lessons that have made the biggest difference."}],"\n",["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Why LangGraph?"}],"\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":["LangChain is fantastic for chaining together LLM calls, but production agent systems need something more: ",["$","strong",null,{"className":"font-semibold text-foreground","children":"explicit control flow"}],". LangGraph gives you a state-machine abstraction where each node is a function and edges define transitions — including conditional routing based on the current state."]}],"\n",["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"from"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" langgraph.graph "}],["$","span",null,{"style":{"color":"#F47067"},"children":"import"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" StateGraph, "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"END"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"from"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" typing "}],["$","span",null,{"style":{"color":"#F47067"},"children":"import"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" TypedDict"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"class"}],["$","span",null,{"style":{"color":"#F69D50"},"children":" AgentState"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"("}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"TypedDict"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"):"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" messages: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"list"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" current_agent: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" tool_results: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"dict"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":"graph "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" StateGraph(AgentState)"}]]}]]}]}]}],"\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"This matters because in production you need:"}],"\n",["$","ul",null,{"className":"list-disc list-inside space-y-2 text-muted mb-5","children":["\n",["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Deterministic routing"}]," — you must know which agent handles which query type"]}],"\n","$L11","\n","$L12","\n"]}],"\n","$L13","\n","$L14","\n","$L15","\n","$L16","\n","$L17","\n","$L18","\n","$L19","\n","$L1a","\n","$L1b","\n","$L1c","\n","$L1d","\n","$L1e","\n","$L1f","\n","$L20","\n","$L21","\n","$L22","\n","$L23","\n","$L24"] 11:["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"State persistence"}]," — conversations can span hours in healthcare scenarios"]}] 12:["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Fault tolerance"}]," — if one agent fails, the system should gracefully degrade"]}] 13:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"The Multi-Agent Pattern"}] 14:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"The architecture I've found most effective separates concerns into specialized agents:"}] 15:["$","ol",null,{"className":"list-decimal list-inside space-y-2 text-muted mb-5","children":["\n",["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Router Agent"}]," — classifies incoming queries and routes to specialists"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Retrieval Agent"}]," — handles RAG pipeline queries against the knowledge base"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Action Agent"}]," — executes tool calls (database writes, API calls)"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Synthesis Agent"}]," — combines results into a coherent response"]}],"\n"]}] 16:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Each agent has its own prompt, tools, and guardrails. The router is the entry point and decides which specialist to invoke."}] 17:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"State Management at Scale"}] 18:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":["One critical lesson: ",["$","strong",null,{"className":"font-semibold text-foreground","children":"never trust the LLM to manage state"}],". Use LangGraph's state object as the single source of truth:"]}] 19:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"def"}],["$","span",null,{"style":{"color":"#DCBDFB"},"children":" router_node"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(state: AgentState) -> AgentState:"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" classification "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" classify_query(state["}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"messages\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"]["}],["$","span",null,{"style":{"color":"#F47067"},"children":"-"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"1"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"])"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" {"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" **"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"state,"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"current_agent\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":": classification.agent,"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"metadata\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":": {"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"confidence\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":": classification.confidence,"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"timestamp\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":": datetime.now().isoformat(),"}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" }"}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" }"}]}]]}]}]}] 1a:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"This pattern saved us countless debugging hours. Every state transition is explicit, logged, and reproducible."}] 1b:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"RAG Pipeline Optimization"}] 1c:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"For our medical AI assistant, retrieval quality is literally life-critical. Here's what moved the needle:"}] 1d:["$","ul",null,{"className":"list-disc list-inside space-y-2 text-muted mb-5","children":["\n",["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Hybrid search"}]," — combine dense vector similarity (Qdrant) with BM25 keyword search"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Reranking"}]," — use a cross-encoder to rerank the top-k results before passing to the LLM"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Chunk strategy"}]," — medical literature works best with 512-token chunks and 64-token overlap"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Metadata filtering"}]," — filter by specialty, recency, and evidence level before retrieval"]}],"\n"]}] 1e:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Error Handling in Agent Loops"}] 1f:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Production agents need circuit breakers. Without them, a confused agent can loop indefinitely, burning tokens and frustrating users:"}] 20:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#6CB6FF"},"children":"MAX_ITERATIONS"}],["$","span",null,{"style":{"color":"#F47067"},"children":" ="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 5"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"def"}],["$","span",null,{"style":{"color":"#DCBDFB"},"children":" should_continue"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(state: AgentState) -> "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" if"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" state.get("}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"iteration_count\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"0"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":") "}],["$","span",null,{"style":{"color":"#F47067"},"children":">="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" MAX_ITERATIONS"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"fallback\""}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" if"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" state.get("}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"confidence\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"0"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":") "}],["$","span",null,{"style":{"color":"#F47067"},"children":">"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 0.85"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"respond\""}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"continue\""}]]}]]}]}]}] 21:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Lessons Learned"}] 22:["$","ol",null,{"className":"list-decimal list-inside space-y-2 text-muted mb-5","children":["\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Start with the simplest architecture that works."}]," You don't need 10 agents. Start with 2-3 and add complexity only when you have evidence it's needed."]}],"\n"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Log everything."}]," Every state transition, every LLM call, every tool invocation. When something goes wrong at 3 AM, you'll be grateful."]}],"\n"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Test with real data early."}]," Synthetic test cases will lull you into false confidence. Get real user queries into your test suite as soon as possible."]}],"\n"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Monitor costs obsessively."}]," A single bad routing decision can cascade into dozens of unnecessary LLM calls. Set up cost alerts and track per-query spending."]}],"\n"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Build human escalation into the architecture."}]," No matter how good your agents are, some queries need a human. Make this path easy and frictionless."]}],"\n"]}],"\n"]}] 23:["$","hr",null,{"className":"my-8 border-[var(--card-border)]"}] 24:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Building AI agents is one of the most exciting areas in software engineering right now. The tools have matured enormously in the past year, and the gap between what's possible and what most companies have deployed is massive. If you're starting this journey, I hope these patterns save you some of the pain I went through learning them."}]