{"id":174,"date":"2026-07-26T21:10:36","date_gmt":"2026-07-26T13:10:36","guid":{"rendered":"https:\/\/fsdata.site\/?p=174"},"modified":"2026-07-26T22:29:45","modified_gmt":"2026-07-26T14:29:45","slug":"langgraph-multi-agent-orchestration-practice","status":"publish","type":"post","link":"https:\/\/fsdata.site\/?p=174","title":{"rendered":"LangGraph \u591a\u667a\u80fd\u4f53\u7f16\u6392\u5b9e\u6218\uff1a\u4ece\u5355 Agent \u5230\u56e2\u961f\u534f\u4f5c"},"content":{"rendered":"<h2>\u4e3a\u4ec0\u4e48\u9700\u8981\u591a Agent \u534f\u4f5c\uff1f<\/h2>\n<p>\u5355 Agent \u5728\u5904\u7406\u7b80\u5355\u4efb\u52a1\u65f6\u8868\u73b0\u4e0d\u9519\uff0c\u4f46\u9762\u5bf9\u9700\u8981\u591a\u4e2a\u4e13\u4e1a\u9886\u57df\u77e5\u8bc6\u7684\u590d\u6742\u95ee\u9898\u65f6\uff0c\u5f80\u5f80\u4f1a\u529b\u4e0d\u4ece\u5fc3\u3002\u5c31\u50cf\u4f60\u4e0d\u80fd\u6307\u671b\u4e00\u4e2a\u5168\u6808\u5de5\u7a0b\u5e08\u72ec\u7acb\u5b8c\u6210\u6570\u636e\u5e93\u8bbe\u8ba1\u3001\u524d\u7aef\u5f00\u53d1\u548c\u8fd0\u7ef4\u76d1\u63a7\u4e00\u6837\uff0c\u5355\u4e2a LLM Agent \u4e5f\u5e94\u8be5\u628a\u4e0d\u540c\u804c\u8d23\u4ea4\u7ed9\u4e13\u95e8\u7684\u5b50 Agent\u3002<\/p>\n<p>LangGraph \u662f LangChain \u63a8\u51fa\u7684\u4e00\u4e2a\u57fa\u4e8e\u56fe\u7ed3\u6784\u7684\u5de5\u4f5c\u6d41\u7f16\u6392\u6846\u67b6\uff0c\u4e13\u95e8\u4e3a\u591a Agent \u7cfb\u7edf\u8bbe\u8ba1\u3002\u4e0e\u4f20\u7edf\u7684\u7ebf\u6027\u94fe\u5f0f\u8c03\u7528\u4e0d\u540c\uff0c\u5b83\u5141\u8bb8 Agent \u4e4b\u95f4\u6709\u5faa\u73af\u3001\u5206\u652f\u548c\u6761\u4ef6\u5224\u65ad\uff0c\u66f4\u63a5\u8fd1\u771f\u5b9e\u4e16\u754c\u7684\u4e1a\u52a1\u6d41\u7a0b\u3002<\/p>\n<h2>\u67b6\ufffd\ufffd\u8bbe\u8ba1\uff1a\u4e09\u4f4d\u4e00\u4f53\u7684 Agent \u56e2\u961f<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u6784\u5efa\u4e00\u4e2a\u6280\u672f\u77e5\u8bc6\u5e93\u95ee\u7b54\u7cfb\u7edf\uff0c\u5305\u542b\u4e09\u4e2a\u89d2\u8272\uff1a<\/p>\n<ul>\n<li><strong>Researcher Agent<\/strong>\uff1a\u8d1f\u8d23\u641c\u7d22\u77e5\u8bc6\u5e93\u4e2d\u7684\u76f8\u5173\u6587\u6863<\/li>\n<li><strong>Writer Agent<\/strong>\uff1a\u6839\u636e\u641c\u7d22\u7ed3\u679c\u64b0\u5199\u7ed3\u6784\u5316\u7684\u56de\u7b54<\/li>\n<li><strong>Reviewer Agent<\/strong>\uff1a\u5ba1\u67e5\u56de\u7b54\u8d28\u91cf\uff0c\u51b3\u5b9a\u662f\u5426\u901a\u8fc7\u6216\u8fd4\u56de\u4fee\u6539<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u8bbe\u8ba1\u4e0e <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/fsdata.site\/2026\u5e74-java\u540e\u7aef\u5f00\u53d1\u5b8c\u6574\u6280\u672f\u6808\u6307\u5357\/\">Java \u540e\u7aef\u6280\u672f\u6808\u4e2d\u7684\u5fae\u670d\u52a1\u5206\u5de5\u7406\u5ff5<\/a> \u6709\u5f02\u66f2\u540c\u5de5\u4e4b\u5999\u2014\u2014\u6bcf\u4e2a\u7ec4\u4ef6\u53ea\u505a\u597d\u4e00\u4ef6\u4e8b\u3002<\/p>\n<h2>\u4ee3\u7801\u5b9e\u73b0<\/h2>\n<pre><code class=\"language-python\">from langchain_core.messages import HumanMessage, AIMessage\nfrom langgraph.graph import StateGraph, MessagesState\nfrom typing import TypedDict\n\n# \u5b9a\u4e49\u5de5\u4f5c\u6d41\u72b6\u6001\nclass AgentState(TypedDict):\n    messages: list\n    confidence: float\n    review_rounds: int\n\n# Researcher Node\ndef researcher_node(state: AgentState):\n    research_prompt = \"\"\"You are a technical knowledge base researcher.\nSearch for relevant documentation about the user's query.\nReturn all findings as structured notes.\"\"\"\n    messages = state[\"messages\"] + [\n        {\"role\": \"system\", \"content\": research_prompt}\n    ]\n    # \u5b9e\u9645\u9879\u76ee\u4e2d\u63a5\u5165\u5411\u91cf\u68c0\u7d22\n    response = {\"role\": \"assistant\", \"content\": \"Found 3 relevant documents...\"}\n    return {\"messages\": messages + [response]}\n\n# Writer Node\ndef writer_node(state: AgentState):\n    write_prompt = \"\"\"Based on the research findings, compose\na clear and well-structured answer to the user's question.\"\"\"\n    messages = state[\"messages\"] + [\n        {\"role\": \"system\", \"content\": write_prompt}\n    ]\n    response = {\"role\": \"assistant\", \"content\": \"Here is your answer...\"}\n    return {\"messages\": messages + [response]}\n\n# Reviewer Node\ndef reviewer_node(state: AgentState):\n    review_prompt = \"\"\"Review the generated answer for accuracy,\ncompleteness, and readability. Return approve or revise.\"\"\"\n    messages = state[\"messages\"] + [\n        {\"role\": \"system\", \"content\": review_prompt}\n    ]\n    # \u6a21\u62df\u8bc4\u5206\n    confidence = 0.85\n    return {\"confidence\": confidence, \"review_rounds\": state.get(\"review_rounds\", 0) + 1}\n\n# \u6784\u5efa\u56fe\nworkflow = StateGraph(AgentState)\nworkflow.add_node(\"researcher\", researcher_node)\nworkflow.add_node(\"writer\", writer_node)\nworkflow.add_node(\"reviewer\", reviewer_node)\n\n# \u8bbe\u7f6e\u5165\u53e3\nworkflow.set_entry_point(\"researcher\")\nworkflow.add_edge(\"researcher\", \"writer\")\nworkflow.add_edge(\"writer\", \"reviewer\")\n\n# \u6761\u4ef6\u8fb9\uff1a\u6839\u636e\u5ba1\u67e5\u7ed3\u679c\u51b3\u5b9a\u4e0b\u4e00\u6b65\ndef route_review(state: AgentState):\n    if state[\"confidence\"] >= 0.8 and state.get(\"review_rounds\", 0) < 3:\n        return \"final\"\n    return \"revise\"\n\nworkflow.add_conditional_edges(\n    \"reviewer\", route_review,\n    {\"final\": None, \"revise\": \"writer\"}  # None = \u7ed3\u675f\n)\n\napp = workflow.compile()\n<\/code><\/pre>\n<h2>\u8fd0\u884c\u5de5\u4f5c\u6d41<\/h2>\n<pre><code class=\"language-python\">result = app.invoke({\n    \"messages\": [{\n        \"role\": \"user\",\n        \"content\": \"\u5982\u4f55\u7406\u89e3 Spring Boot \u4e2d\u7684 Bean \u751f\u547d\u5468\u671f\uff1f\"\n    }]\n})\nprint(result[\"messages\"][-1][\"content\"])\n<\/code><\/pre>\n<h2>\u5173\u952e\u8981\u70b9\u603b\u7ed3<\/h2>\n<ol>\n<li><strong>\u5faa\u73af\u673a\u5236<\/strong>\uff1aReviewer \u4e0d\u901a\u8fc7\u65f6\u53ef\u4ee5\u8fd4\u56de Writer \u91cd\u65b0\u5199\uff0c\u8fd9\u5728\u7ebf\u6027\u94fe\u4e2d\u65e0\u6cd5\u5b9e\u73b0<\/li>\n<li><strong>\u72b6\u6001\u5171\u4eab<\/strong>\uff1amessages \u5217\u8868\u5728\u6240\u6709\u8282\u70b9\u95f4\u4f20\u9012\uff0c\u540e\u4e00\u4e2a\u8282\u70b9\u80fd\u770b\u5230\u4e4b\u524d\u7684\u5168\u90e8\u4e0a\u4e0b\u6587<\/li>\n<li><strong>\u9000\u51fa\u6761\u4ef6<\/strong>\uff1a\u901a\u8fc7 confidence \u548c review_rounds \u63a7\u5236\u8fed\u4ee3\u4e0a\u9650\uff0c\u907f\u514d\u65e0\u9650\u5faa\u73af<\/li>\n<\/ol>\n<p>\u5982\u679c\u4f60\u7684\u9879\u76ee\u6d89\u53ca CI\/CD \u6d41\u7a0b\u81ea\u52a8\u5316\uff0c\u53ef\u4ee5\u53c2\u8003\u6211\u4eec\u7684 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/fsdata.site\/cicd-tools-comparison\/\">DevOps CI\/CD \u5de5\u5177\u5bf9\u6bd4<\/a>\u6587\u7ae0\u6765\u9009\u62e9\u5408\u9002\u7684\u6d41\u6c34\u7ebf\u65b9\u6848\u3002\u591a Agent \u7cfb\u7edf\u4e2d\u7684\u6bcf\u4e2a Agent \u90fd\u53ef\u4ee5\u770b\u4f5c\u4e00\u4e2a\u81ea\u52a8\u5316\u7684\u5fae\u670d\u52a1\u5355\u5143\u3002<\/p>\n<p>LangGraph \u7684\u6838\u5fc3\u4ef7\u503c\u5728\u4e8e\u300c\u628a\u590d\u6742\u51b3\u7b56\u903b\u8f91\u663e\u5f0f\u5316\u300d\u2014\u2014\u4e0d\u662f\u9ed1\u76d2\u5f0f\u7684 Prompt \u5806\u53e0\uff0c\u800c\u662f\u53ef\u89c2\u6d4b\u3001\u53ef\u8c03\u8bd5\u3001\u53ef\u91cd\u73b0\u7684\u4ee3\u7801\u5316\u5de5\u4f5c\u6d41\u3002\u8fd9\u5728 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/fsdata.site\/docker\u5bb9\u5668\u5316\u90e8\u7f72\u5b9e\u6218\uff1a\u4ece\u5b89\u88c5\u5230\u4e0a\u7ebf\u5168\u6d41\u7a0b\/\">Docker \u5bb9\u5668\u5316\u90e8\u7f72<\/a>\u4e2d\u540c\u6837\u9002\u7528\uff1a\u6bcf\u4e2a\u5bb9\u5668\u53ea\u8d1f\u8d23\u4e00\u4ef6\u4e8b\uff0c\u5bb9\u5668\u4e4b\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u7531\u7f16\u6392\u6587\u4ef6\u6e05\u6670\u5b9a\u4e49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LangGraph \u591a\u667a\u80fd\u4f53\u7f16\u6392\u5b9e\u6218\uff1a\u624b\u628a\u624b\u6559\u4f60\u6784\u5efa Researcher-Writer-Reviewer \u534f\u4f5c\u7cfb\u7edf\uff0c\u5b9e\u73b0\u77e5\u8bc6\u5e93\u95ee\u7b54\u7684\u81ea\u52a8\u8d28\u91cf\u5ba1\u67e5\u3002<\/p>\n","protected":false},"author":2,"featured_media":213,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[20,32,30,49,52],"class_list":["post-174","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-news","tag-ai-agent","tag-langgraph","tag-llm","tag-agent","tag-52"],"_links":{"self":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=174"}],"version-history":[{"count":4,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":237,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions\/237"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/media\/213"}],"wp:attachment":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}