> For the complete documentation index, see [llms.txt](https://organization-bht.gitbook.io/it/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://organization-bht.gitbook.io/it/ai/5-langgraph-agent/undefined.md). Agents can also search and read this documentation through its [MCP server](https://organization-bht.gitbook.io/it/~gitbook/mcp).

# 서브그래프와 병렬처리

## 서브그래프

* 독립적으로 컴파일된 그래프를 다른 그래프의 노드로 포함시키는 랭그래프 구성 패턴.
* 복잡한 에이전트의 워크플로우를 부분적으로 나누거나, 여러 프로젝트에서 공통으로 사용하는 검즘 워크플로우를 재사용하고 싶을때 사용한다.

{% hint style="info" %}
**서브그래프 상태공유**

* 서브그래프는 메인그래프의 키값과 겹치는 키가 있는 경우 자동으로 매핑되며, 겹치는 키가 없는 경우 이는 메인그래프와 공유되지 않는다.
* 겹치는 키가 없을때 상태공유가 필요하다면, 노드함수 안에서 수동으로 상태를 변환해줘야 한다.
  {% endhint %}

#### **서브그래프 수동상태변환**

<figure><img src="https://3572862491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUON3CGxVeoUR2YdtAhxl%2Fuploads%2F0FkA6LThgKyuEPVLVjwS%2Fimage.png?alt=media&amp;token=a08902e9-9c49-4278-9e7a-352ab535ca1b" alt=""><figcaption></figcaption></figure>

## 동적 병렬 처리(Send API)

* **Send API**는 랭그래프를 병렬로 실행가능하게 하는 도구로, Send(node\_name, state)객체를 반환하면 지정한 노드가 지정한 상태로 병렬 실행 된다.
* SendAPI는 병렬처리를 Map-Reduce패턴 방식으로 처리한다.

{% hint style="info" %}
**Map-Reduce패턴**

* Map(분배) : 리스트의 각 항목을 별도 작업으로 분배하는 단계
* Process(처리) : 각 항목을 병렬로 처리하는 단계
* Reduce(수집) : 모든 처리 결과를 수집하여 합치는 단계(리듀서함수 사용)
  {% endhint %}

<figure><img src="https://3572862491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUON3CGxVeoUR2YdtAhxl%2Fuploads%2F9HhtEFHSFvBvUR856WfY%2Fimage.png?alt=media&amp;token=298be799-d43c-438e-ba08-204d34589274" alt=""><figcaption></figcaption></figure>
