Cookbook
Storylines · for AI agents

並列ステップ — 複数の処理を実行してから継続する

AND結合:複数のサブフローが任意の順序で実行され、それぞれに独自のチェックがあります。すべてが完了した後にのみ継続します。

MCP tools:create_storylinevalidate_storyline

いくつかのステップは単一の行ではありません — それらは「これらすべてを任意の順序で実行し、それぞれに固有のフォローアップを行い、すべてが完了するまで待ってから次に進む」というものです。ビザ申請がその典型例です:パスポート、銀行明細書、招待状はそれぞれ収集と異なるレビューが必要ですが、これら3つすべてが承認されるまで提出することはできません。これは並列ノード(フォーク / 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": []}
  ]}
)

申請者は3つの書類を任意の順序で提出できます;それぞれが承認されると collect に戻ります。 submit3つのブランチすべてが完了するまで到達できません — エンジンはその後で結合出口のみを選択します。

各ブランチに必要な分のフローを割り当ててください — 有効期限が近づいているパスポートの場合、戻る前に「更新して再アップロード」ノードをループさせることができます;銀行のブランチでは、残高追加の明細書を要求できます。ブランチの key は一意に保ってください。その後、公開前に validate_storyline を実行してください — これは、ブランチがない並列ノード、存在しないノードを指しているブランチ、または結合出口がない場合をフラグ付けします。