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

推荐订阅源

H
Help Net Security
T
ThreatConnect
SecWiki News
SecWiki News
F
Future of Privacy Forum
AWS News Blog
AWS News Blog
C
Cisco Blogs
A
Arctic Wolf
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Scott Helme
Scott Helme
V
V2EX
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
K
Kaspersky official blog
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
NISL@THU
NISL@THU
Microsoft Azure Blog
Microsoft Azure Blog
量子位
The Hacker News
The Hacker News
Stack Overflow Blog
Stack Overflow Blog
Security Latest
Security Latest
M
Microsoft Research Blog - Microsoft Research
Google Online Security Blog
Google Online Security Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
I
InfoQ
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
Cisco Talos Blog
Cisco Talos Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Troy Hunt's Blog
F
Fox-IT International blog
S
Security @ Cisco Blogs
博客园 - 司徒正美
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Comments on: Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LINUX DO - 最新话题
GbyAI
GbyAI
Project Zero
Project Zero
腾讯CDC
T
Tailwind CSS Blog

DEV Community

Sustainable AI Starts with Efficient AI Find Remove duplicated files in Google Drive How to Detect GPU Waste in a Kubernetes Cluster The Privacy Bug in My First Chrome Extension (And How to Avoid It) Serverless Mental Models: What They Don't Tell You Before You Build Preventing GPT hallucination in automated content pipelines: how I structure Make.com flows with data injection Hmm, where were we? AI Visibility Tools, Math Proofs, and Stripped Guardrails Shape Developer Landscape How AI and Electronics Are Changing Healthcare Devices: The Future of Smart Healthcare Author: Shivam Wakade | Founder, PrivSR Making Claude Sound Like Optimus Prime Understanding Reinforcement Learning with Human Feedback Part 5: Training the Reward Model with Loss Functions Learning Progress Pt.20 How Secure LoRa Communication Devices Work: Building the Future of Private and Long-Range Connectivity Author: Shivam Wakade | Founder, PrivSR How I Rebuilt an RPG Map Editor with Rust, React, and WASM Building a System That Automates YouTube Post-Production Building a 100% Serverless Digital Asset Packager in the Browser Game Recommended AI What is Human-In-The-Loop (HITL)? Deep Dive: React Server Components in TanStack Start Migrating off Google Analytics: Umami vs Plausible vs Fathom Building a Portfolio That Actually Demonstrates Software Engineering Async/Await in JavaScript: From Callbacks to Clean Code (2026) Benchmarking LLM Structured Outputs Angular 21 Multiselect Dropdown: A Migration-Friendly Component with Live Functional Tests ShareBox v5 — GPU transcoding, Netflix-style grid, and why I don't need Plex anymore TOML Schema is live Handling Duplicate Shopify Webhook Events (And Why You Must) Original Kubernetes Dashboard — retired upstream, upgraded to Angular 21. لماذا أسست ترينافو للتجار العرب الذين تتجاهلهم المنصات الغربية Construyendo un recomendador de películas en Python: de los datos al modelo When APIs Lie: A Lesson in Defensive Debugging Pope Leo XIV's AI Encyclical: What Builders Must Know (2026) Donna v0.3.0 HTB — MonitorsFour | Writeup The Free Tool You Trust Is the One You Should Fear the Most HTB — MonitorsFour | Writeup Fr 97. Embeddings and Vector Search: Semantic Search That Works Deep Dive: Building "Gravity Paint" - A Tactile Physics Instrument with React, Matter.js, and p5.js ABAP Unit Testing with Test Doubles and Mocking Frameworks: A Senior Architects Guide to Isolating Dependencies in SAP S/4HANA LeetCode Solution: 5. Longest Palindromic Substring kovax-react 0.8: Tailwind v4 preset, FormField adapters, ColorModeScript, and Storybook I built an AI résumé tool that refuses to lie about your experience The hat Azure Entra ID User & Role Management — Step-by-Step Practical Guide With A Simple Excercise The AI-Native Company: How a Single Founder Can Build Global Organizations Powered by AWS and an Ecosystem of Artificial Intelligences Building a Lightweight Remote MCP Knowledge Base on Cloudflare Workers Why I built Trinavo for the MENA merchants Western platforms ignore The N+1 Query That Killed Our Database, And How I Fixed It Docstrings vs Markdown Docs: What Should Developers Actually Write? Training Data Provenance: The Manifest Diff That Explains the Hash Add SVGIcons MCP to Claude Code and Find SVG Icons from Your Terminal 3 CLI Tools You Can Buy with Crypto — No KYC, No Subscriptions COSS Weekly: OpenClaw competitor NanoClaw Raises $12M, Dust Raises $40M, Sonar Acquires Gitar, and more How to know if you actually need mobile proxies (without buying any) Building Cursor for Community: A Buildathon Built on Time Pressure How we built a PII masking layer for LLM APIs — local detection, reversible tokens, one line to integrate Why MLFQ Was Way Ahead of Its Time Add Runtime Limits to Claude Agent Workflows I Built a Prompt Injection Detector with 98% Recall on Unseen Attacks. Here's Why Data Beat Architecture. 8 Vite Config Options Every Developer Should Know (Vite 8) Feature Flags That Forgot to Leave Why Trust Infrastructure Is Becoming the Hidden Layer of Donation Platforms XyPriss: Rethinking Core Performance and Zero-Trust Architecture in Modern Backends Designing Configuration for Scalable Treasure Hunts SSH Login Delays: The 10-Second Wait That Drives Us Crazy Building Production Multi-Agent Workflows in n8n: What 50 Deployments Taught Us A 3-layer memory system that gives Claude Code persistent context across sessions. Trishul SNMP Suite 2.0.1: Better MIBs, Traps, and SNMP Labs How I built a production AI SaaS as a solo developer Auto-labelling 1.2M robotics frames with VLMs: a failover story India’s Laws Were Not Built for AI — And Courts Are Filling the Gap skill-insp: A Skill That Scores Other Skills Clprolf Minimalist Messaging in the Age of AI What's actually in a good .cursorrules file? I built 10 of them — here's what I learned Building Strong Python Basics – Loops, Functions and Logic How to Choose the Right Tech Stack for Your Project I built a free multi-tab JSON editor — here's what I learned HTTP Headers Every Developer Should Know (2026) Building Cross-Platform Digital Products: Challenges and Best Practices Data Privacy in the Age of AI: How Product Teams Can Build Trust with Users What Would WordPress Look Like If It Were Designed Today? Why Backup Success Does Not Mean Database Recoverability Local AI Office Assistant That Never Sends Your Documents to the Cloud Building TaskForge: Translating Enterprise Chaos into an Open-Source Scheduler Tesla P40 in a Homelab: 24GB of Inference on a Budget Llama 4: Meta's Latest — Scout, Maverick, and the MoE Revolution George Hotz called AI code 'slop.' He's half right. Como Construir um Fluxo de Trabalho Baseado em Engenharia de Prompt e Automação We Audited Our Agent Tool-Call Traces. Half Our Eval Data Was Garbage. The Hidden Cost of Downtime: How SRE Error Budgets Protect National Economic Infrastructure Getting started with openHUMANS can be an exciting venture for developers looking to create innovative applications in the realm of human-ce Stack Overflow: A Powerful Community for Developers and Learners From Language Models to Humanoid Minds ✨ Road to Senior #2: How Computers Think in Numbers Why LLM debugging fails on fragmented repository context How to Deploy a LangGraph Agent on AWS Bedrock AgentCore An outreach kit for solo founders whose drafts can't hallucinate Open Satchel is live Amy Kwalwasser and the Growing Importance of Quantum Risk Modeling
LangGraph 워크플로우 템플릿 (v38)
matias yoon · 2026-05-26 · via DEV Community

LangGraph 워크플로우 템플릿 (v38)

Python 개발자를 위한 LangGraph 기반 AI 에이전트 워크플로우 템플릿

LangChain과 LangGraph를 사용한 Python 기반 AI 에이전트 개발을 위한 실전 가이드입니다. 이 템플릿은 실제 개발자들이 겪는 문제를 해결하기 위해 설계되었습니다.

1. LangGraph 아키텍처 개요

LangGraph는 상태 기반 워크플로우 시스템으로, 다음과 같은 핵심 구성 요소로 구성됩니다:

핵심 구성 요소:

  • Nodes: 워크플로우의 단계
  • Edges: 노드 간의 연결
  • State: 워크플로우의 상태 관리
  • Checkpointing: 상태 저장 및 복원
from langgraph.graph import StateGraph, END
from typing import TypedDict, Annotated
import operator

class GraphState(TypedDict):
    messages: Annotated[list, operator.add]
    context: str

# 그래프 생성
workflow = StateGraph(GraphState)

Enter fullscreen mode Exit fullscreen mode

2. 템플릿 1: 간단한 RAG 에이전트 (검색 → 생성 → 검증)

대부분의 LLM 응용 프로그램은 RAG(검색 기반 생성) 패턴을 기반으로 합니다:

from langchain_core.prompts import PromptTemplate
from langchain_openai import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser

class RAGAgent:
    def __init__(self, llm):
        self.llm = llm
        self.retriever = self._setup_retriever()
        self.prompt = PromptTemplate.from_template(
            "주어진 컨텍스트를 사용하여 질문에 답하세요:\n\n{context}\n\n질문: {question}"
        )

    def retrieve(self, state):
        question = state["messages"][-1].content
        docs = self.retriever.invoke(question)
        context = "\n\n".join([doc.page_content for doc in docs])
        return {"context": context}

    def generate(self, state):
        chain = self.prompt | self.llm | StrOutputParser()
        result = chain.invoke({
            "question": state["messages"][-1].content,
            "context": state["context"]
        })
        return {"messages": [result]}

    def validate(self, state):
        # 간단한 검증 로직
        if len(state["messages"][-1].content) < 10:
            return {"messages": ["질문에 대한 충분한 정보가 없습니다."]}
        return {"messages": [state["messages"][-1].content]}

# 워크플로우 정의
def create_rag_workflow():
    workflow = StateGraph(GraphState)

    workflow.add_node("retrieve", RAGAgent.retrieve)
    workflow.add_node("generate", RAGAgent.generate)
    workflow.add_node("validate", RAGAgent.validate)

    workflow.set_entry_point("retrieve")
    workflow.add_edge("retrieve", "generate")
    workflow.add_edge("generate", "validate")
    workflow.add_edge("validate", END)

    return workflow.compile()

Enter fullscreen mode Exit fullscreen mode

3. 템플릿 2: 다중 도구 에이전트 (계획 → 실행 → 관찰 → 결정)

복잡한 작업을 처리하는 다중 도구 에이전트:

from langchain.tools import Tool
from langchain_core.messages import ToolMessage
import json

class MultiToolAgent:
    def __init__(self):
        # 예시 도구들
        self.tools = [
            Tool(
                name="weather",
                func=lambda location: f"{location}의 날씨는 맑습니다.",
                description="날씨 정보 조회"
            ),
            Tool(
                name="calculator",
                func=lambda expression: f"결과: {eval(expression)}",
                description="수학 계산"
            )
        ]

    def plan(self, state):
        # 작업 계획 생성
        plan = {
            "tasks": [
                {"name": "weather", "params": {"location": "서울"}},
                {"name": "calculator", "params": {"expression": "2+2"}}
            ]
        }
        return {"plan": plan}

    def execute(self, state):
        # 도구 실행
        results = []
        for task in state["plan"]["tasks"]:
            tool = next(t for t in self.tools if t.name == task["name"])
            result = tool.func(**task["params"])
            results.append(result)
        return {"execution_results": results}

    def observe(self, state):
        # 결과 관찰 및 분석
        return {"analysis": "모든 작업이 완료되었습니다."}

    def decide(self, state):
        # 결정 로직
        if len(state["execution_results"]) > 0:
            return {"messages": ["작업이 성공적으로 완료되었습니다."]}
        return {"messages": ["작업 실패."]}

Enter fullscreen mode Exit fullscreen mode

4. 템플릿 3: 인간-중개 워크플로우 (일시정지 → 검토 → 계속)

사람의 개입이 필요한 중요한 결정을 위한 워크플로우:

class HumanInLoopAgent:
    def __init__(self):
        self.user_feedback = None

    def pause_for_review(self, state):
        # 사용자 검토를 위한 일시정지
        return {"status": "pending_review"}

    def review(self, state):
        # 사용자 검토 처리
        if self.user_feedback is not None:
            return {"messages": [self.user_feedback]}
        return {"messages": ["사용자 검토가 필요합니다."]}

    def continue_workflow(self, state):
        # 워크플로우 재개
        return {"status": "processing"}

# 사용자 피드백 설정
def set_user_feedback(feedback):
    agent = HumanInLoopAgent()
    agent.user_feedback = feedback
    return agent

Enter fullscreen mode Exit fullscreen mode

5. 템플릿 5: 병렬 실행 에이전트 (분기 → 처리 → 집계)

대량 데이터를 병렬로 처리:

from concurrent.futures import ThreadPoolExecutor
import asyncio

class ParallelAgent:
    def __init__(self, max_workers=4):
        self.max_workers = max_workers

    def fan_out(self, state):
        # 입력 데이터 분기
        data_chunks = [
            {"chunk_id": i, "data": f"chunk_{i}"}
            for i in range(4)
        ]
        return {"chunks": data_chunks}

    def process_chunk(self, chunk_data):
        # 개별 청크 처리
        time.sleep(0.1)  # 시뮬레이션
        return {"result": f"processed_{chunk_data['data']}"}

    async def parallel_process(self, state):
        # 병렬 처리
        with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
            futures = [
                executor.submit(self.process_chunk, chunk)
                for chunk in state["chunks"]
            ]
            results = [future.result() for future in futures]
        return {"processed_results": results}

    def aggregate(self, state):
        # 결과 집계
        aggregated = {
            "total_count": len(state["processed_results"]),
            "results": [r["result"] for r in state["processed_results"]]
        }
        return {"messages": [f"{aggregated['total_count']}개 처리 완료"]}

Enter fullscreen mode Exit fullscreen mode

6. 상태 관리 패턴

효율적인 상태 관리:

from langgraph.checkpoint.memory import MemorySaver
from langgraph.checkpoint import BaseCheckpointSaver

class StateManager:
    def __init__(self):
        # 메모리 체크포인트 사용
        self.checkpointer = MemorySaver()

    def get_state(self, thread_id):
        # 상태 조회
        return self.checkpointer.get(thread_id)

    def update_state(self, thread_id, new_state):
        # 상태 업데이트
        self.checkpointer.put(thread_id, new_state)

    def rollback(self, thread_id, version):
        # 이전 버전으로 롤백
        pass

# 상태 저장 설정
def setup_workflow_with_checkpoint():
    workflow = StateGraph(GraphState)
    workflow.add_checkpoint(MemorySaver())
    return workflow

Enter fullscreen mode Exit fullscreen mode

7. 스트리밍 및 실시간 업데이트

실시간 처리 지원:


python
from langchain_core.callbacks import BaseCallbackHandler

class StreamingHandler(BaseCallbackHandler):
    def on_chain_start(self, serialized, inputs, **kwargs):
        print("체인 시작")

    def on_chain_end(self, outputs, **kwargs):
        print("체인 종료")

    def on_llm_new_token(self, token, **kwargs):
        print(f"토큰: {token}", end="", flush=True)

class StreamingAgent:
    def __init__(self):
        self.streaming_handler = StreamingHandler()

    def stream_response(self, query):
        # 스트리밍 응답
        llm = ChatOpenAI(callbacks=[self.streaming_handler])
        response = llm.invoke(query)
        return response

# 사용 예시
async def stream_example():


---

📥 **Get the full guide on Gumroad**: https://gumroad.com/l/auto ($5)

Enter fullscreen mode Exit fullscreen mode