A node that determines the next node in the DAG dynamically. The logic function must return a list with a `target_node` field.
Super class
HydraR::AgentNode -> AgentRouterNode
Methods
Method new()
Initialize AgentRouterNode
Usage
AgentRouterNode$new(id, router_fn, label = NULL, params = list())Examples
if (FALSE) { # \dontrun{
# Routing based on an LLM sentiment classification
classifier <- function(state) {
sentiment <- state$get("analyst_output")
if (grepl("Positive", sentiment)) {
list(target_node = "celebrate", status = "success")
} else {
list(target_node = "investigate", status = "success")
}
}
node_router <- AgentRouterNode$new(
id = "sentiment_router",
router_fn = classifier
)
# Run with dummy state
res <- node_router$run(AgentState$new(list(analyst_output = "Positive results!")))
message("Targeting node: ", res$target_node)
} # }