R6 class representing an orchestration layer for multi-agent systems. Features:
Comprehensive delegation tracing
Automatic delegate_task tool generation
Depth and context limits with guardrails
Result aggregation and summarization
new()Initialize a new Flow.
Flow$new(
session,
model = NULL,
registry = NULL,
max_depth = 5,
max_steps_per_agent = 10,
max_context_tokens = 4000,
enable_guardrails = TRUE
)sessionA ChatSession object.
modelOptional default model ID to use. If NULL, inherits from session.
registryOptional AgentRegistry for agent lookup.
max_depthMaximum delegation depth. Default 5.
max_steps_per_agentMaximum ReAct steps per agent. Default 10.
max_context_tokensMaximum context tokens per delegation. Default 4000.
enable_guardrailsEnable safety guardrails. Default TRUE.
depth()Get the current call stack depth.
Flow$depth()Integer depth.
current()Get the current active agent.
Flow$current()The currently active Agent, or NULL.
session()Get the shared session.
Flow$session()The ChatSession object.
set_global_context()Set the global context (the user's original goal).
Flow$set_global_context(context)contextCharacter string describing the overall goal.
Invisible self for chaining.
global_context()Get the global context.
Flow$global_context()The global context string.
delegate()Delegate a task to another agent with enhanced tracking.
Flow$delegate(agent, task, context = NULL, priority = "normal")agentThe Agent to delegate to.
taskThe task instruction.
contextOptional additional context.
priorityTask priority: "high", "normal", "low". Default "normal".
The text result from the delegate agent.
generate_delegate_tool()Generate the delegate_task tool for manager agents.
Flow$generate_delegate_tool()Creates a single unified tool that can delegate to any registered agent. This is more efficient than generating separate tools per agent.
A Tool object for delegation.
run()Run a primary agent with enhanced orchestration.
Flow$run(agent, task, use_unified_delegate = TRUE)agentThe primary/manager Agent to run.
taskThe user's task/input.
use_unified_delegateUse single delegate_task tool. Default TRUE.
The final result from the primary agent.
get_delegation_history()Get delegation history.
Flow$get_delegation_history(agent_name = NULL, limit = NULL)agent_nameOptional filter by agent name.
limitMaximum number of records to return.
A list of delegation records.
delegation_stats()Get delegation statistics.
Flow$delegation_stats()A list with counts, timing, and success rates.
clear_history()Clear delegation history.
Flow$clear_history()Invisible self for chaining.
clone()The objects of this class are cloneable with this method.
Flow$clone(deep = FALSE)deepWhether to make a deep clone.