Skip to content

Commit 255ad25

Browse files
committed
docs: multi-agent quickstart examples and emergent agency patterns
Add single-agent, multi-agent dependency graph, and emergent self-improvement examples to EXAMPLES.md cookbook. Add hierarchical delegation with dynamic dispatch and emergent agent creation section to AGENCY_API.md.
1 parent 57e416d commit 255ad25

2 files changed

Lines changed: 194 additions & 1 deletion

File tree

docs/getting-started/EXAMPLES.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
10. [Agency Streaming](#10-agency-streaming)
1919
11. [Query Router](#11-query-router)
2020
12. [Query Router Host Hooks](#12-query-router-host-hooks)
21+
13. [Single Agent — Minimal](#13-single-agent--minimal)
22+
14. [Multi-Agent Team with Dependency Graph](#14-multi-agent-team-with-dependency-graph)
23+
15. [Emergent Self-Improvement Agent](#15-emergent-self-improvement-agent)
2124

2225
---
2326

@@ -679,6 +682,97 @@ Runnable source: `packages/agentos/examples/query-router-host-hooks.mjs`
679682

680683
---
681684

685+
## 13. Single Agent — Minimal
686+
687+
The simplest entry point: one agent, one tool, one call.
688+
689+
```typescript
690+
import { agent } from '@framers/agentos';
691+
692+
const researcher = agent({
693+
model: 'openai:gpt-4o',
694+
instructions: 'You are a research assistant. Search the web and summarize findings.',
695+
tools: [webSearchTool],
696+
maxSteps: 5,
697+
});
698+
699+
const result = await researcher.generate('What are the latest advances in RAG?');
700+
console.log(result.text);
701+
```
702+
703+
---
704+
705+
## 14. Multi-Agent Team with Dependency Graph
706+
707+
Declare dependencies between agents and let the orchestrator schedule them
708+
automatically. Agents with no dependencies run first; downstream agents receive
709+
their predecessors' outputs as context.
710+
711+
```typescript
712+
import { agency } from '@framers/agentos';
713+
714+
const team = agency({
715+
agents: {
716+
researcher: {
717+
model: 'openai:gpt-4o',
718+
instructions: 'Find relevant research papers and data.',
719+
tools: [webSearchTool, arxivTool],
720+
},
721+
analyst: {
722+
model: 'openai:gpt-4o',
723+
instructions: 'Analyze the research and extract key insights.',
724+
},
725+
writer: {
726+
model: 'openai:gpt-4o',
727+
instructions: 'Write a clear, well-structured summary.',
728+
dependsOn: ['researcher', 'analyst'],
729+
},
730+
},
731+
strategy: 'graph', // auto-detected from dependsOn
732+
});
733+
734+
const result = await team.generate(
735+
'Compare RAG vs fine-tuning for domain-specific LLM applications'
736+
);
737+
console.log(result.text);
738+
```
739+
740+
---
741+
742+
## 15. Emergent Self-Improvement Agent
743+
744+
Enable the emergent subsystem so the agent can forge new tools, adapt its own
745+
personality, and manage its skill set at runtime. Guard the mutation surface
746+
with `maxDeltaPerSession` and skill allowlists.
747+
748+
```typescript
749+
import { agent } from '@framers/agentos';
750+
751+
const adaptiveAgent = agent({
752+
model: 'openai:gpt-4o',
753+
instructions: 'You are a helpful assistant that learns and adapts.',
754+
tools: [forgeTool, adaptPersonalityTool, manageSkillsTool, selfEvaluateTool],
755+
emergent: {
756+
enabled: true,
757+
selfImprovement: {
758+
enabled: true,
759+
personality: { maxDeltaPerSession: 0.15 },
760+
skills: { allowlist: ['*'] },
761+
},
762+
},
763+
});
764+
765+
// The agent can now:
766+
// - Forge new tools at runtime
767+
// - Adapt its personality based on task requirements
768+
// - Enable/disable skills dynamically
769+
// - Evaluate its own performance and adjust
770+
const result = await adaptiveAgent.generate('Help me write a creative story');
771+
console.log(result.text);
772+
```
773+
774+
---
775+
682776
## Related Guides
683777

684778
- [GETTING_STARTED.md](./GETTING_STARTED.md) — installation and first steps

docs/orchestration/AGENCY_API.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ streaming events on the sequential strategy.
2929
12. [Observability and Callbacks](#observability-and-callbacks)
3030
13. [Structured Output with Zod](#structured-output-with-zod)
3131
14. [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

717816
The following example combines all major features in one agency configuration.

0 commit comments

Comments
 (0)