Hierarchical manager
A manager agent assigns work to named workers until it declares the goal done.
The manager replies with JSON naming the next worker (coder, tester or writer) and its task, or done with the final answer. The script runs the chosen worker, records the result and shows the manager everything finished so far. The loop stops after six rounds, so a manager that never finishes fails loudly instead of running forever.
What it maps to
Hierarchical process and delegation: the manager decides who works next; the script enforces the worker list and the round limit. See the concept map.
Script: hierarchical-manager.lms
# Hierarchical manager: a manager assigns work to named workers until it declares the goal done.
import "agentic.lms";
goal = ARGV.get(0, "a one-line shell command that counts TODO lines in a repository, with a short usage note");
manager = agent("manager", "split the goal into worker tasks, then accept the result");
workers = {
coder: agent("coder", "write one small shell command"),
tester: agent("tester", "name two edge cases and how to check them"),
writer: agent("writer", "write a two-sentence usage note")
};
schema = {type: "object", required: ["assign", "task"], properties: {
assign: {type: "string", enum: ["coder", "tester", "writer", "done"]}, task: {type: "string"}}};
done = [];
for (round in range(0, 6)) {
d = ask_json(manager, f"Goal: {goal}\nFinished work: {json_stringify(done)}\nAssign the next worker, or assign done with the final answer as task.", schema);
if (d == null || d.assign == "done") {
println(d == null ? "(dry run)" : d.task);
exit(0);
}
push(done, {worker: d.assign, task: d.task, result: ask(workers.get(d.assign, null), d.task)});
println(f"round {round + 1}: {d.assign}");
}
error("manager did not finish within 6 rounds");
exit(1);
It imports the shared helpers from examples/agentic.lms, shown on the recipe index.
Run it
export OLLAMA_API_KEY=...
LLM_MODEL=ollama-cloud/deepseek-v4.1-flash lmscript examples/hierarchical-manager.lms
Output (offline mock)
The site check runs this recipe against examples/mock-model.lms, a deterministic stand-in for the model, and compares this output.
round 1: coder round 2: tester round 3: writer git grep -n TODO | wc -l -- run it from the repository root; binary files and untracked files are not counted.
Live run
Recorded on 2026-11-01 with ollama-cloud/deepseek-v4.1-flash. It made 3 model calls and used 1217 tokens. Live replies differ from run to run.
round 1: coder ```sh git grep -In -E '\bTODO\b' | wc -l ``` **Usage:** Run from the repository root (or any subdirectory to scope the count there). It counts lines—not TODO occurrences—in git-tracked text files that contain the whole word `TODO`, respecting `.gitignore`; binary files are skipped via `-I`. Add `FIXME` with `-E '\b(TODO|FIXME)\b'` if you want both.
Previous: Sequential crew · Next: Tool agent
Try it: download examples/hierarchical-manager.lms and examples/agentic.lms into an examples/ directory, export the key for your provider, then run the command above. Pass a goal as the first argument.