Appearance
Build Support Swarm Example
This page embeds the full source for examples/build_support_swarm.py.
python
"""Example: build a swarm definition from generated graph JSON and inspect the resulting runtime snapshot."""
from pprint import pprint
from swarmforge.authoring import (
META_PROMPT_EDGE,
META_PROMPT_NODE,
META_PROMPT_SWARM,
build_swarm_definition,
)
from swarmforge.evaluation import build_graph_snapshot, build_swarm_scenario_generation_context
generated = {
"nodes": [
{
"node_key": "triage",
"name": "Triage",
"persona": "",
"is_entry_node": True,
"sub_agents": [
{
"sub_agent": "billing",
"handoff_description": "Transfer after confirming the request is about charges, invoices, or payments.",
"required_variables": ["account_id"],
},
{
"sub_agent": "technical",
"handoff_description": "Transfer after confirming the request is about app behavior, errors, or device issues.",
"required_variables": ["affected_device_model"],
},
],
},
{
"node_key": "billing",
"name": "Billing",
"persona": "Calm and direct",
"is_entry_node": False,
},
{
"node_key": "technical",
"name": "Technical",
"persona": "Structured and concise",
"is_entry_node": False,
},
],
}
swarm = build_swarm_definition(generated, swarm_id="support", name="Support Swarm")
graph_snapshot = build_graph_snapshot(swarm)
print("Prompt templates:")
print(f"- node: {META_PROMPT_NODE[:80]}...")
print(f"- edge: {META_PROMPT_EDGE[:80]}...")
print(f"- swarm: {META_PROMPT_SWARM[:80]}...")
print()
print("Runtime snapshot:")
pprint(graph_snapshot)
print()
print("Scenario generation context:")
print(build_swarm_scenario_generation_context(graph_snapshot))Run:
bash
python examples/build_support_swarm.py