{
"cells": [
{
"cell_type": "markdown",
"id": "812c8b84",
"metadata": {
"papermill": {
"duration": 0.005001,
"end_time": "2026-05-27T11:41:59.202245+00:00",
"exception": false,
"start_time": "2026-05-27T11:41:59.197244+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"# 11 · Meta-Controller — LLM router that picks the right *architecture* per task\n",
"\n",
"> **TL;DR.** A router LLM classifies each incoming task and dispatches to the **most appropriate architecture** from a roster — `ToolUse` for one-shot lookups, `ReAct` for multi-hop research, `Planning` for decomposable comparisons, `Reflection` for quality-sensitive writing/code, etc. This is the **most composable** architecture in the repo: every other architecture is treated as a black-box callable via the common `Architecture.run(task)` contract.\n",
">\n",
"> **Reach for it when** you serve a mix of task types and no single architecture is the right default for all of them (a real user-facing AI product almost always).\n",
"> **Avoid when** all your tasks are the same shape — a fixed architecture is cheaper and more predictable.\n",
"\n",
"| Property | Value |\n",
"|---|---|\n",
"| Origin | RouterChain / LangChain LCEL `RunnableBranch` pattern |\n",
"| Coordination | Single routing LLM call → dispatch to chosen architecture |\n",
"| External tools needed? | Depends on the routed architecture |\n",
"| Cost | 1 router call + 1 architecture run (the architecture may itself make many calls) |\n",
"| Composability | **Highest** — uses every other architecture as a black box |\n",
"\n",
"This is the first notebook that fully exploits the `Architecture` base class's `run(task)` contract. The router treats `Reflection`, `ToolUse`, `ReAct`, and `Planning` as interchangeable black boxes."
]
},
{
"cell_type": "markdown",
"id": "4363a83a",
"metadata": {
"papermill": {
"duration": 0.003001,
"end_time": "2026-05-27T11:41:59.210101+00:00",
"exception": false,
"start_time": "2026-05-27T11:41:59.207100+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 2 · Architecture at a glance\n",
"\n",
"```mermaid\n",
"flowchart LR\n",
" A([task]) --> R[Route
LLM with structured-output
Literal[arch names]]\n",
" R --> X{which arch?}\n",
" X -->|tool_use| T[ToolUse.run]\n",
" X -->|react| Re[ReAct.run]\n",
" X -->|planning| P[Planning.run]\n",
" X -->|reflection| Rf[Reflection.run]\n",
" T --> Z([answer])\n",
" Re --> Z\n",
" P --> Z\n",
" Rf --> Z\n",
"\n",
" style R fill:#fff3e0,stroke:#f57c00\n",
" style X fill:#fce4ec,stroke:#c2185b\n",
"```\n",
"\n",
"**Two real nodes**: a Router that classifies the task and an Execute node that dispatches to the chosen sub-architecture. The four leaf boxes aren't graph nodes — they're external `Architecture` instances called from inside `_execute`."
]
},
{
"cell_type": "markdown",
"id": "4f06eaae",
"metadata": {
"papermill": {
"duration": 0.003,
"end_time": "2026-05-27T11:41:59.217105+00:00",
"exception": false,
"start_time": "2026-05-27T11:41:59.214105+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 3 · Theory\n",
"\n",
"### 3.1 · Why route at all?\n",
"\n",
"Different tasks have different shapes. \"What's the population of France?\" needs one tool call, not a 3-step plan. \"Write a polished Python function\" needs Reflection's iterate-on-draft loop, not a tool call. \"Compare X and Y on dimensions A, B, C\" needs Planning's decomposition, not a single ReAct step.\n",
"\n",
"A fixed architecture is the *wrong default* for some fraction of incoming tasks. Meta-Controller picks the right one per task — at the cost of one extra LLM call per request.\n",
"\n",
"### 3.2 · Routing as structured output\n",
"\n",
"The router uses `with_structured_output` with a **dynamic Literal** built from the actual roster:\n",
"\n",
"```python\n",
"next_t = Literal[tuple(self.roster.keys())]\n",
"RouterDecision = create_model(\n",
" \"RouterDecision\",\n",
" chosen_arch=(next_t, Field(description=\"...\")),\n",
" reason=(str, Field(description=\"One sentence why\")),\n",
")\n",
"```\n",
"\n",
"This is the same dynamic-schema pattern Multi-Agent (notebook 05) uses for its Supervisor. The dynamic Literal means the router *cannot* hallucinate an architecture that isn't in the roster.\n",
"\n",
"### 3.3 · The composability win — every architecture is a callable\n",
"\n",
"Every architecture in this library subclasses `Architecture` (defined in `architectures/base.py`):\n",
"\n",
"```python\n",
"class Architecture(ABC):\n",
" @abstractmethod\n",
" def run(self, task: str) -> ArchitectureResult: ...\n",
"```\n",
"\n",
"That single contract is what makes Meta-Controller possible. The router doesn't know whether it's calling `Reflection` or `ReAct` or `Planning` — it just calls `.run(task)` and gets back an `ArchitectureResult` with `.output`. Adding a new architecture to the roster is one line.\n",
"\n",
"This is the same design idea that lets a Unix shell pipe `find` into `grep` into `wc` — common interface, infinite composition.\n",
"\n",
"### 3.4 · Where Meta-Controller sits\n",
"\n",
"| Pattern | Routes between | Cost |\n",
"|---|---|---|\n",
"| Multi-Agent (nb 05) | role-specialised **agents** | 1 supervisor call + N specialist sub-runs |\n",
"| Blackboard (nb 07) | role-specialised agents (self-electing) | N bid calls + 1 sub-run per round |\n",
"| **Meta-Controller** *(this notebook)* | **whole architectures** | **1 route call + 1 architecture run** |\n",
"| Adaptive RAG (nb 26) | retrieval strategies | 1 route + 1 retrieval pipeline |\n",
"| Ensemble (nb 13) | nothing — runs all in parallel | N × architecture runs + aggregator |\n",
"\n",
"The choice between Meta-Controller and Multi-Agent: **route by task-shape (Meta-Controller) when different *patterns* fit different tasks. Route by domain-expertise (Multi-Agent) when different *specialists* know different facts.**\n",
"\n",
"### 3.5 · What goes wrong (you'll see in § 9)\n",
"\n",
"1. **Wrong route.** Router picks ReAct for a task that needs Reflection (or vice versa). The downstream architecture then does the wrong job. Mitigation: tighter architecture descriptions; or fall back to Reflection-after-routing.\n",
"2. **Router preference bias.** Llama tends to pick `react` or `planning` for almost everything because they \"sound\" more agentic. Watch §9 routing distribution across diverse tasks.\n",
"3. **Cost blowup.** A Planning route can itself make 20+ LLM calls. The router is cheap; the route target may not be.\n",
"4. **No retry on route failure.** If the chosen architecture returns garbage, Meta-Controller doesn't re-route. Extension idea: wrap with PEV (nb 06) for retry.\n"
]
},
{
"cell_type": "markdown",
"id": "c60e7687",
"metadata": {
"papermill": {
"duration": 0.003189,
"end_time": "2026-05-27T11:41:59.224292+00:00",
"exception": false,
"start_time": "2026-05-27T11:41:59.221103+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 4 · Setup"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "38ec09a0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T11:41:59.236855Z",
"iopub.status.busy": "2026-05-27T11:41:59.236855Z",
"iopub.status.idle": "2026-05-27T11:42:01.459921Z",
"shell.execute_reply": "2026-05-27T11:42:01.459921Z"
},
"papermill": {
"duration": 2.232622,
"end_time": "2026-05-27T11:42:01.460924+00:00",
"exception": false,
"start_time": "2026-05-27T11:41:59.228302+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"
Provider: nebius · Model: meta-llama/Llama-3.3-70B-Instruct ─────────────────────────────────────────────────────\n", "\n" ], "text/plain": [ "\u001b[1;36mProvider: nebius · Model: meta-llama/Llama-\u001b[0m\u001b[1;36m3.3\u001b[0m\u001b[1;36m-70B-Instruct\u001b[0m \u001b[92m─────────────────────────────────────────────────────\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Default roster: tool_use, react, planning, reflection \n",
"\n"
],
"text/plain": [
"Default roster: \u001b[1mtool_use, react, planning, reflection\u001b[0m \n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from agentic_architectures import get_llm, enable_langsmith, settings\n",
"from agentic_architectures.architectures import MetaController\n",
"from agentic_architectures.architectures.meta_controller import ARCHITECTURE_DESCRIPTIONS\n",
"from agentic_architectures.ui import print_md, print_header, print_step\n",
"\n",
"enable_langsmith()\n",
"print_header(f\"Provider: {settings.llm_provider} · Model: {settings.llm_model}\")\n",
"print_md(f\"Default roster: **{', '.join(ARCHITECTURE_DESCRIPTIONS.keys())}**\")"
]
},
{
"cell_type": "markdown",
"id": "cc61eeee",
"metadata": {
"papermill": {
"duration": 0.003997,
"end_time": "2026-05-27T11:42:01.470108+00:00",
"exception": false,
"start_time": "2026-05-27T11:42:01.466111+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 5 · Library walkthrough\n",
"\n",
"Source: [`src/agentic_architectures/architectures/meta_controller.py`](../src/agentic_architectures/architectures/meta_controller.py).\n",
"\n",
"Three key pieces:\n",
"\n",
"1. **`_default_roster(llm)`** — builds the default `dict[str, Architecture]` with sane budgets for each architecture (`ToolUse(max_rounds=3)`, `Planning(max_replans=1)`, etc.). Override at construction time to use a custom roster.\n",
"2. **`ARCHITECTURE_DESCRIPTIONS`** — the only thing the router sees about each architecture. These descriptions are the steering signal; if you change them, routing changes.\n",
"3. **`_route`** — calls a dynamic-Literal structured-output schema. The router's `chosen_arch` field is constrained to roster keys at runtime.\n",
"4. **`_execute`** — looks up `self.roster[chosen_arch]` and calls its `.run(task)`. Architecture composability in one line."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8966e21c",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T11:42:01.479629Z",
"iopub.status.busy": "2026-05-27T11:42:01.478617Z",
"iopub.status.idle": "2026-05-27T11:42:01.492144Z",
"shell.execute_reply": "2026-05-27T11:42:01.492144Z"
},
"papermill": {
"duration": 0.021045,
"end_time": "2026-05-27T11:42:01.494160+00:00",
"exception": false,
"start_time": "2026-05-27T11:42:01.473115+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Architecture descriptions the router sees:\n",
"\n",
" --- tool_use ---\n",
" One-shot fact lookup using web search. Best for: 'What is X?' / 'Who founded Y?' / 'Current price of Z?'. Single tool call usually suffices.\n",
"\n",
" --- react ---\n",
" Multi-hop research with explicit Thought before each Action. Best for: questions that require chaining multiple lookups where each step depends on the previous result (e.g. 'When did the CEO of X's company join Y?').\n",
"\n",
" --- planning ---\n",
" Decompose a task into ordered steps upfront, execute each. Best for: comparisons, multi-aspect reports, anything with obvious decomposition (e.g. 'Compare X and Y on dimensions A, B, C').\n",
"\n",
" --- reflection ---\n",
" Generate → critique → refine loop. NO external tools. Best for: quality-sensitive creative or code tasks where the model should iterate (e.g. 'Write a Python function that ...', 'Polish this paragraph').\n"
]
}
],
"source": [
"from agentic_architectures.architectures.meta_controller import ARCHITECTURE_DESCRIPTIONS\n",
"print('Architecture descriptions the router sees:')\n",
"for name, desc in ARCHITECTURE_DESCRIPTIONS.items():\n",
" print(f'\\n --- {name} ---')\n",
" print(f' {desc}')"
]
},
{
"cell_type": "markdown",
"id": "e7c5d896",
"metadata": {
"papermill": {
"duration": 0.004014,
"end_time": "2026-05-27T11:42:01.502448+00:00",
"exception": false,
"start_time": "2026-05-27T11:42:01.498434+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 6 · State\n",
"\n",
"| Field | Type | Set by |\n",
"|---|---|---|\n",
"| `task` | `str` | caller |\n",
"| `chosen_arch` | `str` | `_route` |\n",
"| `routing_reason` | `str` | `_route` |\n",
"| `sub_result` | `dict` (output + metadata + arch name) | `_execute` |"
]
},
{
"cell_type": "markdown",
"id": "42fbd2a6",
"metadata": {
"papermill": {
"duration": 0.003615,
"end_time": "2026-05-27T11:42:01.510089+00:00",
"exception": false,
"start_time": "2026-05-27T11:42:01.506474+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 7 · Build the graph"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "306232ea",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T11:42:01.520979Z",
"iopub.status.busy": "2026-05-27T11:42:01.520232Z",
"iopub.status.idle": "2026-05-27T11:42:05.441265Z",
"shell.execute_reply": "2026-05-27T11:42:05.440271Z"
},
"papermill": {
"duration": 3.928157,
"end_time": "2026-05-27T11:42:05.442265+00:00",
"exception": false,
"start_time": "2026-05-27T11:42:01.514108+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGoAAAFNCAIAAABnnW36AAAQAElEQVR4nOydCUAUZf/Hn5k9YbnvSwQEFDwQRdNUNBE1zfAq77fU1LzN0PSvVni8lmb1ZppSaWWaqeVt3uVt4n2jcomIIDcL7Dnzf3YXlwV3Z4+H1YF9Psk2+xxzfPe55rl+XJqmAcZSuACDAJYPCSwfElg+JLB8SGD5kECVL/NWVdr1i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HcxAvDycnDkJcFtwdHi5o0t+eZUF+a1CqO6ODgH2KXejIb2ACZl5/weMDEsUpTXyoGTvFz9eTd+fshaNTcP/dYXikblxRkYnjzZhkc2pSfcbuqRSwbpxmjA7UjgXL84iDTo5g9x2V38pNHqWK3pq6+bB0AsYDKQnnm9ccOTrz/LGxiVkRLZlhl35Xu3QD7NQmPIFevYCfQkBEXSh/feaqQKqK6uXRJcAdmYvn8vsOb8tNulFMU4Au5jp4iz6YuHEGDsYlXmCUuzS+XimWwU8AnSDh4mhnTgnRBnV1681T5lZPFZcUyOJ4JRwZUNlUJopZFakJjapDW+apvUilB17FIaPq8UUJtmqj2FcHzVnxodUWpcSK5pJ2IDG3t2G2w2Smu1qXrsUP00QNZSZ5UUqHQ7aFVPYTK5FO1y7NHfe4RCZqgSa0xdFr9RxB1NVB1/1J1HWG/Kk3VXK36Es/ZQIJ3YSfkOXtwmkbY15fZYTYuympAsN3cCcvB8iGB5UMCy4cElg8JLB8S/w8AAP//sodwJQAAAAZJREFUAwD53C3b+LSvpAAAAABJRU5ErkJggg==",
"text/plain": [
"› [Q1] → routed to: TOOL_USE\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1mQ1\u001b[0m\u001b[1m]\u001b[0m\u001b[1m → routed to: TOOL_USE\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
What is the latest stable version of Rust as of today?\n",
"\n"
],
"text/plain": [
"What is the latest stable version of Rust as of today?\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"› reason\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m reason\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
This task requires a one-shot fact lookup to find the latest stable version of Rust as of today.\n",
"\n"
],
"text/plain": [
"This task requires a one-shot fact lookup to find the latest stable version of Rust as of today.\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"› output (truncated)\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m output \u001b[0m\u001b[1m(\u001b[0m\u001b[1mtruncated\u001b[0m\u001b[1m)\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
The latest stable version of Rust as of today is not explicitly stated in the search results. However, the first \n",
"result from the Rust Programming Language Forum mentions the release of dtact v0.2.2 and rssn-advanced v0.1.0, \n",
"which may indicate that the latest stable version of Rust is not specified i\n",
"\n"
],
"text/plain": [
"The latest stable version of Rust as of today is not explicitly stated in the search results. However, the first \n",
"result from the Rust Programming Language Forum mentions the release of dtact v0.\u001b[1;36m2.2\u001b[0m and rssn-advanced v0.\u001b[1;36m1.0\u001b[0m, \n",
"which may indicate that the latest stable version of Rust is not specified i\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"› [Q2] → routed to: REFLECTION\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1mQ2\u001b[0m\u001b[1m]\u001b[0m\u001b[1m → routed to: REFLECTION\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Write a Python function that returns the n-th Fibonacci number, optimized for n up to 10^6.\n", "\n" ], "text/plain": [ "Write a Python function that returns the n-th Fibonacci number, optimized for n up to \u001b[1;36m10\u001b[0m^\u001b[1;36m6\u001b[0m.\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
› reason\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m reason\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
This task requires generating and refining code to solve a specific problem, which is best suited for the \n",
"reflection architecture.\n",
"\n"
],
"text/plain": [
"This task requires generating and refining code to solve a specific problem, which is best suited for the \n",
"reflection architecture.\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"› output (truncated)\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m output \u001b[0m\u001b[1m(\u001b[0m\u001b[1mtruncated\u001b[0m\u001b[1m)\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
## Optimized Fibonacci Function in Python\n",
"### Overview\n",
"\n",
"The Fibonacci sequence is a series of numbers where a number is the addition of the last two numbers, starting with\n",
"0 and 1. This function uses matrix exponentiation to efficiently calculate the n-th Fibonacci number, making it \n",
"suitable for lar\n",
"\n"
],
"text/plain": [
"## Optimized Fibonacci Function in Python\n",
"### Overview\n",
"\n",
"The Fibonacci sequence is a series of numbers where a number is the addition of the last two numbers, starting with\n",
"\u001b[1;36m0\u001b[0m and \u001b[1;36m1\u001b[0m. This function uses matrix exponentiation to efficiently calculate the n-th Fibonacci number, making it \n",
"suitable for lar\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"› [Q3] → routed to: PLANNING\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1mQ3\u001b[0m\u001b[1m]\u001b[0m\u001b[1m → routed to: PLANNING\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Compare the population, GDP, and area of Japan and Germany. Pick which is larger on each dimension.\n",
"\n"
],
"text/plain": [
"Compare the population, GDP, and area of Japan and Germany. Pick which is larger on each dimension.\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"› reason\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m reason\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
This task requires comparing multiple aspects of two countries, which can be decomposed into ordered steps upfront,\n",
"making planning the most suitable architecture.\n",
"\n"
],
"text/plain": [
"This task requires comparing multiple aspects of two countries, which can be decomposed into ordered steps upfront,\n",
"making planning the most suitable architecture.\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"› output (truncated)\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m output \u001b[0m\u001b[1m(\u001b[0m\u001b[1mtruncated\u001b[0m\u001b[1m)\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Japan has a larger GDP than Germany. However, the population and area of Japan and Germany cannot be compared as \n",
"the necessary information is not available.\n",
"\n"
],
"text/plain": [
"Japan has a larger GDP than Germany. However, the population and area of Japan and Germany cannot be compared as \n",
"the necessary information is not available.\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"› [Q4] → routed to: REACT\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m[\u001b[0m\u001b[1mQ4\u001b[0m\u001b[1m]\u001b[0m\u001b[1m → routed to: REACT\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Who founded OpenAI, and which company did its CEO previously co-found before joining OpenAI?\n",
"\n"
],
"text/plain": [
"Who founded OpenAI, and which company did its CEO previously co-found before joining OpenAI?\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"› reason\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m reason\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
This task requires chaining multiple lookups where each step depends on the previous result, making the react \n",
"architecture the best fit.\n",
"\n"
],
"text/plain": [
"This task requires chaining multiple lookups where each step depends on the previous result, making the react \n",
"architecture the best fit.\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"› output (truncated)\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1m output \u001b[0m\u001b[1m(\u001b[0m\u001b[1mtruncated\u001b[0m\u001b[1m)\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Thought: Based on the information gathered, it appears that Sam Altman, the CEO of OpenAI, co-founded a company \n",
"called Loopt before joining OpenAI. Loopt was a location-based social networking service that allowed users to \n",
"share their real-time locations with friends. This information can be used to\n",
"\n"
],
"text/plain": [
"Thought: Based on the information gathered, it appears that Sam Altman, the CEO of OpenAI, co-founded a company \n",
"called Loopt before joining OpenAI. Loopt was a location-based social networking service that allowed users to \n",
"share their real-time locations with friends. This information can be used to\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"Routing distribution across the 4 tasks ───────────────────────────────────────────────────────────────────────────\n", "\n" ], "text/plain": [ "\u001b[1;36mRouting distribution across the \u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;36m tasks\u001b[0m \u001b[92m───────────────────────────────────────────────────────────────────────────\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " tool_use: 1\n", " reflection: 1\n", " planning: 1\n", " react: 1\n" ] } ], "source": [ "TASKS = [\n", " (\"Q1\", \"What is the latest stable version of Rust as of today?\"),\n", " (\"Q2\", \"Write a Python function that returns the n-th Fibonacci number, optimized for n up to 10^6.\"),\n", " (\"Q3\", \"Compare the population, GDP, and area of Japan and Germany. Pick which is larger on each dimension.\"),\n", " (\"Q4\", \"Who founded OpenAI, and which company did its CEO previously co-found before joining OpenAI?\"),\n", "]\n", "\n", "results = []\n", "for tag, task in TASKS:\n", " r = arch.run(task)\n", " results.append((tag, task, r))\n", " print_step(f\"[{tag}] → routed to: {r.metadata['chosen_arch'].upper()}\", task[:120])\n", " print_step(\" reason\", r.metadata['routing_reason'])\n", " print_step(\" output (truncated)\", r.output[:300])\n", " print()\n", "\n", "print_header(\"Routing distribution across the 4 tasks\")\n", "from collections import Counter\n", "dist = Counter(r.metadata['chosen_arch'] for _, _, r in results)\n", "for arch_name, n in dist.most_common():\n", " print(f\" {arch_name}: {n}\")" ] }, { "cell_type": "markdown", "id": "fecc07fa", "metadata": { "papermill": { "duration": 0.012415, "end_time": "2026-05-27T11:45:06.719583+00:00", "exception": false, "start_time": "2026-05-27T11:45:06.707168+00:00", "status": "completed" }, "tags": [] }, "source": [ "### 8.0 · What just happened, briefly\n", "\n", "Three things to inspect:\n", "\n", "- **Routing diversity.** If all 4 tasks routed to the same architecture, the router has a preference bias (see § 3.5). Healthy: 3-4 distinct architectures chosen across 4 diverse tasks.\n", "- **Routing quality.** Read the reasons — are they specific to the task, or generic? Generic reasons suggest the router doesn't really understand the architectures.\n", "- **Output quality vs route.** Did the chosen architecture's output actually fit the task? A correctly-routed task should produce a *recognisably* different output than a mis-routed one." ] }, { "cell_type": "markdown", "id": "03b1db6c", "metadata": { "papermill": { "duration": 0.008466, "end_time": "2026-05-27T11:45:06.740371+00:00", "exception": false, "start_time": "2026-05-27T11:45:06.731905+00:00", "status": "completed" }, "tags": [] }, "source": [ "## 9 · What we just observed\n", "\n", "The cells above ran Meta-Controller against **4 deliberately diverse tasks** to see whether the LLM router actually discriminates between architecture shapes.\n", "\n", "### 9.1 · Routing decisions captured live\n", "\n", "| Task | Routed to | Task preview | Router reason |\n", "|---|---|---|---|\n", "| Q1 | `tool_use` | What is the latest stable version of Rust as of today? | This task requires a one-shot fact lookup to find the latest stable version of Rust as of today. |\n", "| Q2 | `reflection` | Write a Python function that returns the n-th Fibonacci number, optimized for n | This task requires generating and refining code to solve a specific problem, which is best suited for the reflection architecture. |\n", "| Q3 | `planning` | Compare the population, GDP, and area of Japan and Germany. Pick which is larger | This task requires comparing multiple aspects of two countries, which can be decomposed into ordered steps upfront, making planning the most suitable |\n", "| Q4 | `react` | Who founded OpenAI, and which company did its CEO previously co-found before joi | This task requires chaining multiple lookups where each step depends on the previous result, making the react architecture the best fit. |\n", "\n", "### 9.2 · Architecture-choice distribution\n", "\n", "| Architecture | Times chosen |\n", "|---|---|\n", "| `tool_use` | 1 |\n", "| `reflection` | 1 |\n", "| `planning` | 1 |\n", "| `react` | 1 |\n", "\n", "### 9.3 · Patterns surfaced in this run\n", "\n", "- **Healthy routing diversity** — 4 tasks split across 4 distinct architectures. The router genuinely discriminates between task shapes.\n", "\n", "- **Routing accuracy against author's expectations**: 4/4 tasks routed as the author would have. \n", "\n", "### 9.4 · The takeaway\n", "\n", "A *healthy* Meta-Controller run has:\n", "\n", "1. **Routing diversity** — different task shapes go to different architectures.\n", "2. **Specific reasons** — the router justifies each choice with task-specific language, not generic praise.\n", "3. **Output quality matches the route** — Reflection routes produce polished code; ToolUse routes produce concise factual answers; Planning routes produce structured multi-part outputs.\n", "\n", "When all 4 tasks route to the same architecture, Meta-Controller's overhead is wasted — just call that architecture directly. The router's value is **only** realized when traffic is diverse and routing distributes work." ] }, { "cell_type": "markdown", "id": "47e110ef", "metadata": { "papermill": { "duration": 0.009529, "end_time": "2026-05-27T11:45:06.759945+00:00", "exception": false, "start_time": "2026-05-27T11:45:06.750416+00:00", "status": "completed" }, "tags": [] }, "source": [ "## 10 · Try other providers / customise the roster\n", "\n", "Meta-Controller needs **structured output** (the dynamic Literal router). Most providers support it. You can also customise the roster — below, we make a roster that only contains *fast* architectures (no Reflection, no Planning) for latency-critical paths." ] }, { "cell_type": "code", "execution_count": 5, "id": "ae8d6917", "metadata": { "execution": { "iopub.execute_input": "2026-05-27T11:45:06.797432Z", "iopub.status.busy": "2026-05-27T11:45:06.797432Z", "iopub.status.idle": "2026-05-27T11:45:27.074956Z", "shell.execute_reply": "2026-05-27T11:45:27.072956Z" }, "papermill": { "duration": 20.307088, "end_time": "2026-05-27T11:45:27.075957+00:00", "exception": false, "start_time": "2026-05-27T11:45:06.768869+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
Custom 2-arch roster: tool_use OR react only ──────────────────────────────────────────────────────────────────────\n", "\n" ], "text/plain": [ "\u001b[1;36mCustom \u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;36m-arch roster: tool_use OR react only\u001b[0m \u001b[92m──────────────────────────────────────────────────────────────────────\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
› task: What is the current weather in Tokyo right now?\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1mtask: What is the current weather in Tokyo right now?\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
routed to: tool_use\n",
" output: The current weather in Tokyo is 24°C with a low of 21°C and a high of 25°C....\n",
"\n"
],
"text/plain": [
" routed to: tool_use\n",
" output: The current weather in Tokyo is \u001b[1;36m24\u001b[0m°C with a low of \u001b[1;36m21\u001b[0m°C and a high of \u001b[1;36m25\u001b[0m°C\u001b[33m...\u001b[0m.\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"› task: What is the latest stable Python release version?\n", "\n" ], "text/plain": [ "\u001b[1;35m›\u001b[0m \u001b[1mtask: What is the latest stable Python release version?\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
routed to: tool_use\n",
" output: The latest stable Python release version is Python 3.12....\n",
"\n"
],
"text/plain": [
" routed to: tool_use\n",
" output: The latest stable Python release version is Python \u001b[1;36m3.12\u001b[0m\u001b[33m...\u001b[0m.\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"from agentic_architectures.architectures import ToolUse, ReAct\n",
"\n",
"print_header(\"Custom 2-arch roster: tool_use OR react only\")\n",
"fast_arch = MetaController(\n",
" roster={\n",
" \"tool_use\": ToolUse(llm=get_llm(), max_rounds=4),\n",
" \"react\": ReAct(llm=get_llm(), max_rounds=4),\n",
" },\n",
")\n",
"for task in [\n",
" \"What is the current weather in Tokyo right now?\",\n",
" \"What is the latest stable Python release version?\",\n",
"]:\n",
" r = fast_arch.run(task)\n",
" print_step(\n",
" f\"task: {task[:80]}\",\n",
" f\" routed to: {r.metadata['chosen_arch']}\\n output: {r.output[:200]}...\"\n",
" )\n",
" print()"
]
},
{
"cell_type": "markdown",
"id": "7618931a",
"metadata": {
"papermill": {
"duration": 0.021691,
"end_time": "2026-05-27T11:45:27.114396+00:00",
"exception": false,
"start_time": "2026-05-27T11:45:27.092705+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 11 · Failure modes, safety, extensions\n",
"\n",
"### 11.1 · Where this breaks\n",
"\n",
"| Failure | Mechanism | Mitigation |\n",
"|---|---|---|\n",
"| **Wrong route** | Router picks an architecture that's poorly fit to the task | Tighter architecture descriptions; or a verifier on the output that triggers re-routing |\n",
"| **Preference bias** | Router always picks `react` (or `planning`) regardless of task | Inspect routing distribution; adjust descriptions to balance |\n",
"| **Cost surprise** | A Planning route makes 20+ calls; the router didn't anticipate | Track total LLM calls per route and surface to caller |\n",
"| **Roster drift** | Add a new architecture but forget to register it / describe it | Single roster dict + descriptions is single source of truth |\n",
"| **No re-route on failure** | Chosen arch returns garbage; Meta-Controller still returns it | Wrap with PEV (nb 06) verifier; or add a confidence check |\n",
"\n",
"### 11.2 · Production safety\n",
"\n",
"- **Track route distribution** — if 90% of traffic routes to one architecture, you don't need the router (just use that architecture directly).\n",
"- **Set per-architecture timeouts** — a Planning route hanging on a stuck sub-agent shouldn't take down the whole request.\n",
"- **Audit the router** — log every `(task, chosen_arch, reason)` tuple. Cheaper than re-debugging.\n",
"\n",
"### 11.3 · Three extensions\n",
"\n",
"1. **PEV around the chosen architecture.** Wrap the route+execute in a verifier (PEV nb 06) that re-routes if the chosen architecture's output is unsatisfactory.\n",
"2. **Few-shot router prompt.** Add 5-10 example `(task, correct_arch)` pairs to the router prompt to reduce preference bias.\n",
"3. **Multi-level routing.** First route by task category, then route within each category (e.g. \"research → which retrieval strategy?\"). Hierarchical Meta-Controller.\n",
"\n",
"### 11.4 · What to read next\n",
"\n",
"- [**05 · Multi-Agent**](./05_multi_agent.ipynb) — routes between *agents* (domain experts) instead of architectures.\n",
"- [**07 · Blackboard**](./07_blackboard.ipynb) — distributed routing, no central router.\n",
"- [**13 · Ensemble**](./13_ensemble.ipynb) — when in doubt, run all architectures in parallel and aggregate.\n",
"- [**26 · Adaptive RAG**](./26_adaptive_rag.ipynb) — Meta-Controller specialised for RAG complexity routing.\n",
"\n",
"### 11.5 · References\n",
"\n",
"1. LangChain `RouterChain` and `RunnableBranch` — [docs](https://python.langchain.com/docs/concepts/runnables/#runnablebranch)\n",
"2. Multi-agent supervisor pattern — [LangGraph tutorial](https://langchain-ai.github.io/langgraph/tutorials/multi_agent/agent_supervisor/)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
},
"papermill": {
"default_parameters": {},
"duration": 211.649632,
"end_time": "2026-05-27T11:45:28.431181+00:00",
"environment_variables": {},
"exception": null,
"input_path": "all-agentic-architectures/notebooks/11_meta_controller.ipynb",
"output_path": "all-agentic-architectures/notebooks/11_meta_controller.ipynb",
"parameters": {},
"start_time": "2026-05-27T11:41:56.781549+00:00",
"version": "2.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}