INNER CODE UNIT · TypeScript
executeBranch
Kong/volcano-agent-sdk · src/patterns.ts:32
export async function executeBranch(
condition: (history: StepResult[]) => boolean,
branches: { true: (agent: AgentBuilder) => AgentBuilder; false: (agent: AgentBuilder) => AgentBuilder },
history: StepResult[],
createSubAgent: () => AgentBuilder
): Promise<StepResult[]> {
const shouldTakeTrue = condition(history);
const branch = shouldTakeTrue ? branches.true : branches.false;
const subAgent = branch(createSubAgent());
return await subAgent.run();
}
export async function executeSwitch<T>(
selector: (history: StepResult[]) => T,
cases: Record<string, (agent: AgentBuilder) => AgentBuilder> & { default?: (agent: AgentBuilder) => AgentBuilder },
history: StepResult[],
createSubAgent: () => AgentBuilder