Generates a closure that can resolve Mermaid node labels into fully
instantiated AgentNode objects based on inline annotations.
Details
The factory supports the following type= parameters in Mermaid labels:
llm: Creates anAgentLLMNode. Requiresroleorrole_id.logic: Creates anAgentLogicNode. Requireslogic_id.router: Creates anAgentRouterNode. Requireslogic_id.map: Creates anAgentMapNode. Requireslogic_idandmap_key.
Examples
if (FALSE) { # \dontrun{
# 'Low Code' workflow: resolve complex attributes from a Mermaid string
mermaid_src <- '
graph TD
A["Data Fetcher | type=llm | role=Expert Bioinformatician | model=gpt-4o"]
B["Quality Gate | type=logic | logic_id=validate_data"]
C["Reporter | type=llm | role=Technical Writer | driver=claude_cli"]
A --> B
B --> C
'
# 1. Register the required logic in the registry
register_logic("validate_data", function(state) {
raw <- state$get("A")
if (nchar(raw) > 100) list(status="success") else list(status="failed")
})
# 2. Create the DAG using the automatic factory
factory <- auto_node_factory()
dag <- mermaid_to_dag(mermaid_src, node_factory = factory)
# Result: n1 is an AgentLLMNode (OpenAI), n2 is Logic, n3 is AgentLLMNode (Claude)
} # }