병렬 단계 — 여러 작업을 수행한 후 계속 진행
AND-조인: 여러 하위 흐름이 임의의 순서로 실행되며, 각 흐름은 자체 검사를 수행합니다. 모든 흐름이 완료된 후에만 계속 진행합니다.
create_storylinevalidate_storyline어떤 단계들은 한 줄로 표현되지 않습니다. 이들은 "이 모든 작업을 수행하되, 순서는 상관없으며, 각 작업마다 고유한 후속 작업이 있고, 모든 작업이 완료될 때까지 다음 단계로 진행하지 않는다"는 의미입니다. 비자 신청이 그 대표적인 사례입니다. 여권, 은행 거래 내역서, 초청장 각각은 수집과 서로 다른 검토가 필요하지만, 세 가지 모두 통과해야 제출할 수 있습니다. 이것이 병렬 노드(포크 / AND-조인)이며, 이는 일급 노드 타입입니다. 완료 플래그를 수동으로 연결할 필요가 없습니다.
작동 방식
parallel 노드는 여러 필수 분기를 선언하며, 각 분기는 자체 서브 플로우의 진입점을 가리킵니다. 엔진은 완료되지 않은 분기들을 선택지로 제시하고, 완료를 내장된 방식으로 추적합니다(분기로 진입하면 완료로 기록되고, 병렬 노드로 돌아오면 해당 분기가 완료된 것으로 처리됨). 엔진은 모든 분기가 완료되면 노드의 조인 종료 — 즉, to_node_key가 있는 첫 번째 종료 — 를 자동으로 선택합니다. 해당 조건을 직접 평가할 필요는 없으며, 라벨은 단순히 인간을 위한 것입니다. 각 분기는 자체적인 확인 사항과 루프를 가진 완전한 다중 노드 서브 플로우가 될 수 있으며, 그 마지막 단계는 단순히 병렬 노드로 돌아가는 일반 종료 경로를 사용합니다.
create_storyline(
agent_name="Visa", key="visa-docs", name="Visa documents",
graph={"nodes": [
{"node_key": "collect", "title": "Collect all documents", "type": "parallel",
"flags": {"is_entry": True},
"parallel": {"branches": [
{"key": "passport", "label": "Passport", "to_node_key": "p1"},
{"key": "bank", "label": "Bank statement", "to_node_key": "b1"},
{"key": "invite", "label": "Invitation letter","to_node_key": "i1"}
]},
"exits": [{"kind": "ai", "label": "all documents cleared", "to_node_key": "submit",
"ai_criteria": "all required documents have been checked"}]},
{"node_key": "p1", "title": "Check passport", "task": "Verify validity ≥ 6 months; if not, tell the user what to renew.",
"exits": [{"kind": "ai", "label": "passport ok", "to_node_key": "collect", "ai_criteria": "passport is valid and legible"}]},
{"node_key": "b1", "title": "Check bank statement", "task": "Confirm 3 months of history and a sufficient balance.",
"exits": [{"kind": "ai", "label": "bank ok", "to_node_key": "collect", "ai_criteria": "statement covers 3 months and meets the threshold"}]},
{"node_key": "i1", "title": "Check invitation", "task": "Confirm host details and dates match the trip.",
"exits": [{"kind": "ai", "label": "invite ok", "to_node_key": "collect", "ai_criteria": "invitation is consistent with the trip"}]},
{"node_key": "submit", "title": "Submit application", "task": "Package the cleared documents and submit.",
"flags": {"is_terminal": True}, "exits": []}
]}
)신청자는 세 가지 문서를 어떤 순서로든 제공할 수 있으며, 각 문서는 검토를 통과하면 collect로 돌아옵니다. submit은 세 가지 분기가 모두 완료될 때까지 접근할 수 없습니다 — 엔진은 그 시점에만 조인 종료 경로를 선택합니다.
각 분기에 필요한 만큼의 자체 흐름을 제공하십시오. 만료 임박 여권은 돌아오기 전에 "갱신 및 다시 업로드" 노드를 통해 루프를 돌 수 있으며, 은행 분기는 잔액 추가 요청을 할 수 있습니다. 분기의 key는 고유하게 유지하십시오. 그런 다음 게시 전에 validate_storyline을 호출하십시오 — 이는 분기가 없는 병렬 노드, 누락된 노드를 가리키는 분기, 또는 조인 종료 경로가 없는 경우를 플래그로 표시합니다.