@@ -29,7 +29,8 @@ streaming events on the sequential strategy.
292912 . [ Observability and Callbacks] ( #observability-and-callbacks )
303013 . [ Structured Output with Zod] ( #structured-output-with-zod )
313114 . [ Nested Agencies] ( #nested-agencies )
32- 15 . [ Full-Featured Example] ( #full-featured-example )
32+ 15 . [ Hierarchical Delegation — Manager Dispatches Dynamically] ( #hierarchical-delegation--manager-dispatches-dynamically )
33+ 16 . [ Full-Featured Example] ( #full-featured-example )
3334
3435---
3536
@@ -712,6 +713,104 @@ through all layers. `close()` propagates inward — the outer agency calls
712713
713714---
714715
716+ ## Hierarchical Delegation — Manager Dispatches Dynamically
717+
718+ In the hierarchical strategy, a coordinator agent receives delegation tools for
719+ every specialist in the roster. The coordinator decides which agents to invoke,
720+ in what order, and how to merge their outputs -- all at runtime. Combine with
721+ ` emergent ` so the coordinator can also synthesise new specialists on the fly
722+ when the static roster is insufficient.
723+
724+ ``` typescript
725+ import { agency } from ' @framers/agentos' ;
726+
727+ // Hierarchical agency where manager delegates dynamically
728+ const dynamicTeam = agency ({
729+ agents: {
730+ manager: {
731+ model: ' openai:gpt-4o' ,
732+ instructions:
733+ ' You coordinate the team. Delegate research, analysis, and writing tasks to specialists.' ,
734+ },
735+ researcher: {
736+ model: ' openai:gpt-4o' ,
737+ instructions: ' Find information from web and academic sources.' ,
738+ tools: [webSearchTool , arxivTool ],
739+ },
740+ analyst: {
741+ model: ' openai:gpt-4o' ,
742+ instructions: ' Analyze data and extract insights.' ,
743+ },
744+ writer: {
745+ model: ' openai:gpt-4o' ,
746+ instructions: ' Write polished content based on research and analysis.' ,
747+ },
748+ },
749+ strategy: ' hierarchical' ,
750+ // manager gets delegate_to_researcher, delegate_to_analyst, delegate_to_writer tools
751+ });
752+
753+ const result = await dynamicTeam .generate (
754+ ' Write a comprehensive report on the state of AI agents in 2026'
755+ );
756+ console .log (result .text );
757+ ```
758+
759+ ### Adding Emergent Agent Creation
760+
761+ Enable ` emergent ` so the manager can spawn ad-hoc specialists when the
762+ predefined roster does not cover a sub-task. A judge agent evaluates the
763+ synthesised agent before it runs.
764+
765+ ``` typescript
766+ const emergentTeam = agency ({
767+ agents: {
768+ manager: {
769+ model: ' openai:gpt-4o' ,
770+ instructions:
771+ ' Coordinate the team. If a task requires a specialist not in the roster, request one.' ,
772+ },
773+ researcher: {
774+ model: ' openai:gpt-4o' ,
775+ instructions: ' Research topics using web and academic sources.' ,
776+ tools: [webSearchTool , arxivTool ],
777+ },
778+ writer: {
779+ model: ' openai:gpt-4o' ,
780+ instructions: ' Produce polished, well-structured content.' ,
781+ },
782+ },
783+ strategy: ' hierarchical' ,
784+ emergent: {
785+ enabled: true ,
786+ tier: ' session' , // synthesised agents discarded after generate() returns
787+ judge: true , // a judge agent evaluates emergent agents before use
788+ },
789+ hitl: {
790+ approvals: { beforeEmergent: true },
791+ handler : async (request ) => {
792+ console .log (` Emergent agent requested: ${request .description } ` );
793+ return { approved: true };
794+ },
795+ },
796+ controls: {
797+ maxEmergentAgents: 3 , // cap the number of runtime-synthesised agents
798+ },
799+ on: {
800+ emergentForge : (e ) =>
801+ console .log (` [FORGE] ${e .agentName } — approved: ${e .approved } ` ),
802+ },
803+ });
804+
805+ // The manager may spawn a "data-visualiser" or "statistician" agent on the fly
806+ const report = await emergentTeam .generate (
807+ ' Analyze the 2026 State of AI survey data and produce an executive brief with charts'
808+ );
809+ console .log (report .text );
810+ ```
811+
812+ ---
813+
715814## Full-Featured Example
716815
717816The following example combines all major features in one agency configuration.
0 commit comments