/AI & 자동화/Building Multi-Agent Systems (MAS) and Automating Workflows with LangChain & CrewAI
AI & AutomationMultiAgentSystemCrewAI

Building Multi-Agent Systems (MAS) and Automating Workflows with LangChain & CrewAI

Going beyond the limits of a single agent, this in-depth guide covers how to build a Multi-Agent System (MAS) in which multiple specialist agents collaborate using CrewAI and LangChain. It presents practical architecture design and code for

Building Multi-Agent Systems (MAS) and Automating Workflows with LangChain & CrewAI

[Practical Guide] Building Multi-Agent Systems (MAS) and Automating Workflows with LangChain & CrewAI

As LLM technology has grown explosively, we have now reached the stage of building “business process automation engines” rather than mere “chatbots.”

The hottest keyword recently is undoubtedly Agent. But you have probably already experienced this: no matter how smart a single agent is, it is difficult to perfectly handle complex business goals that require multiple stages of specialized knowledge and collaboration—such as writing a marketing plan—all at once.

This article is a practical guide to breaking through that limitation: building a Multi-Agent System (Multi-Agent System, MAS). Focusing on CrewAI and LangChain, we look at how multiple specialist agents collaborate to compose automated workflows, from architecture design through code implementation.


🚀 1. Introduction: Why Isn’t a Single Agent Enough? (Problem Statement and Motivation)

When You Need Complex Task Processing Beyond Simple Q&A

Early LLM applications mainly performed single-purpose tasks such as Q&A or summarization. That is like hiring one very capable personal assistant.

Actual corporate business processes are much more complex. For example, a request such as “Create a market entry strategy for new product A” goes through a multi-step process like this:

  1. Market Analysis Agent: Collects the latest trend data and writes a competitor analysis report. (Tool use)
  2. Marketing Strategy Agent: Based on the analysis results, defines target customer personas and key messages. (Reasoning and generation)
  3. Content Agent: Based on the defined messages, writes blog drafts and press release drafts. (Generation)
  4. Final Review Agent: Aggregates the three outputs, checks logical flow and tone and manner, and completes the final report. (Verification and integration)

To achieve a single goal, you need a structure in which actors with different expertise exchange work sequentially or in parallel. That is the core concept of a Multi-Agent System (MAS).

💡 Defining the MAS Concept

MAS is a system architecture composed of multiple independent or interacting AI agents, where each agent takes on a specific role, decomposes complex goals, and collaborates to produce the final output.

🖼️ Architecture Comparison: Single Agent vs. MAS

(※ In an actual blog, we strongly recommend inserting this part as a visual diagram.)

CategorySingle AgentMulti-Agent System (MAS)
Data FlowInput $\rightarrow$ LLM $\rightarrow$ Output (linear)Input $\rightarrow$ Agent A $\rightarrow$ (output) $\rightarrow$ Agent B $\rightarrow$ (output) $\rightarrow$ ... $\rightarrow$ Final Output (networked)
StrengthsEase of implementation, fast prototypingAbility to handle complexity, high reliability, modularity
WeaknessesRole limitations, unable to handle complex tasksIncreased design complexity, orchestration logic required

🧠 2. Understanding the Basic Principles of Multi-Agent Systems (MAS)

To successfully build a MAS, simply listing agents is not enough. You need to establish the rules of collaboration.

1. Role Assignment

First, define the expert roles (Role) needed to achieve the overall goal. Each agent should have a clear persona, specialized knowledge, and an expected output (Output Format).

2. Communication Protocol Design

Defining how agents converse and exchange information is key.

  • Sequential workflow: A performs a task and passes the result to B, who then performs the next task. (Most common; suitable for pipeline structures.)
  • Parallel workflow: A and B perform their respective tasks simultaneously, then C synthesizes both results to draw a final conclusion. (Useful when review from multiple perspectives is needed.)

📊 Comparison Table: Chaining vs. Collaboration

CategorySimple ChainingCollaboration / MAS
Structure$A \rightarrow B \rightarrow C$ (one-way pipeline)$A \leftrightarrow B \leftrightarrow C$ (interaction and feedback)
Information FlowOnly the final output of the previous stage is passedMulti-dimensional information exchange including intermediate outputs, feedback, revision requests, etc.
AdvantagesIntuitive and fast to implementOptimized for complex problem solving, high completeness
DisadvantagesDifficult to correct errors in intermediate stagesOrchestration logic design is complex
Suitable ScenariosSimple data transformation, sequential report writingMarket research, writing proposals, software requirements analysis

🛠️ 3. Hands-on Agent Orchestration Using Frameworks (Centered on CrewAI)

In the actual implementation stage, frameworks such as LangChain or CrewAI help you implement these complex collaboration rules in code. Among them, CrewAI is highly regarded as a very powerful tool for building MAS because Role and Task definitions are intuitive.

🎯 Example Scenario: Marketing Plan Writing Workflow

We assume a scenario of writing a marketing plan for new product X and deploy three agents.

  1. Market Analyst: Analyzes the latest market trends and extracts key keywords.
  2. Strategy Planner: Based on the analyzed keywords, defines target personas and core values.
  3. Content Writer: Using the defined values, writes an attractive plan draft.

💻 Hands-on Code Snippet (CrewAI-based)

The following is a basic structure in which three agents collaborate sequentially. (You need to install crewai and related libraries to run it.)

Python
from crewai import Agent, Task, Crew, Process
# from langchain_openai import ChatOpenAI # LLM 설정 부분

# 1. 에이전트 정의 (각 역할 부여)
analyst = Agent(
    role='시장 분석가',
    goal='최신 시장 트렌드와 경쟁사 분석을 통해 핵심 인사이트를 도출한다.',
    backstory='데이터 분석에 능하며, 시장의 흐름을 읽는 전문가.',
    llm=llm # LLM 객체 사용
)

strategist = Agent(
    role='전략 기획자',
    goal='분석된 인사이트를 바탕으로 구체적인 시장 진입 전략을 수립한다.',
    backstory='비즈니스 모델 설계와 실행 가능한 로드맵 제시가 전문.',
    llm=llm
)

writer = Agent(
    role='카피라이터',
    goal='수립된 전략을 바탕으로 설득력 있는 최종 기획서 초안을 작성한다.',
    backstory='뛰어난 글쓰기 능력과 고객의 마음을 움직이는 문장력이 있다.',
    llm=llm
)

# 2. 태스크 정의 (순차적 실행)
task1 = Task(
    description='최근 3개월간의 시장 트렌드와 주요 경쟁사 3곳의 강점을 분석하고, 우리 제품이 포지셔닝해야 할 핵심 키워드 5개를 추출하시오.',
    agent=analyst
)

task2 = Task(
    description='Task 1의 키워드와 시장 분석 결과를 바탕으로, 가장 효과적인 시장 진입 전략(MVP 정의 포함)을 3단계 로드맵으로 제시하시오.',
    agent=strategist,
    context=[task1] # 이전 결과물(Context)을 다음 작업에 활용
)

task3 = Task(
    description='Task 2의 로드맵을 기반으로, 투자자들에게 발표할 수 있는 설득력 있는 기획서 초안(서론, 본론, 결론 포함)을 작성하시오.',
    agent=writer,
    context=[task2] # 이전 결과물(Context)을 다음 작업에 활용
)

# 3. 워크플로우 실행
crew = Crew(
    tasks=[task1, task2, task3],
    agents=[analyst, strategist, writer],
    process=Process.sequential # 순차적으로 실행 (가장 일반적)
)

result = crew.kickoff()
print("--- 최종 기획서 초안 ---")
print(result)

💡 Key Concept Explanation: The Importance of Using Context

The most important part of the code above is the Context concept of passing the result of the previous task as input to the next task, as in context=[task1].

  • Simple invocation: Each agent works independently.
  • Using Context: Agent A performs market analysis $\rightarrow$ that result $\rightarrow$ Agent B formulates strategy based on that analysis $\rightarrow$ that result $\rightarrow$ Agent C writes the final report based on that strategy.

Through this sequential flow, you can achieve synergy as if multiple experts were holding meetings to produce a single high-quality output.

This structure is the most powerful pattern for complex, multi-stage problem solving (Complex Problem Solving).

확인 정보
✦ ✦ ✦
편집 검토 · Editorial Review

Nodelog는 모든 콘텐츠의 내용과 출처를 공개 전에 검토합니다. 환경(OS·버전)에 따라 결과가 달라질 수 있는 기술 정보는 공식 문서와 함께 확인하며, 검토 기준과 정정 원칙은 편집 정책에서 안내합니다. 오류를 발견하시면 이메일로 제보해 주세요 — 확인 후 신속히 정정합니다.

편집 책임 · Nodelog 기술 편집팀·발행 · ·업데이트 ·
관련 공식 문서LangChain 공식 문서

Comments

Be the first to comment.