Skip to content

Commit 78984cb

Browse files
committed
Author 4 pattern-todo candidates: agent-factory, agent-capability-manifest, recursive-language-model, latent-space-reasoning
Promotes the four open pattern-todo candidates into full GoF/POSA entries with all sections, a Mermaid diagram, mirrored back-edges, verification-todo rows, and code examples (pseudo + framework). - agent-factory (governance-observability): manufacture agent instances from a versioned template atomically, registry-backed identity, fleet-wide propagation instead of per-instance drift. Examples: pseudo + CrewAI. - agent-capability-manifest (multi-agent): each agent publishes a versioned self-description (A2A Agent Card) at a well-known location; callers discover and bind by capability. Examples: pseudo + Google ADK (A2A). - recursive-language-model (reasoning): prompt-as-environment + recursive self-invocation over snippets, beyond the context window (MIT RLM, 2512.24601). Examples: pseudo + OpenAI Agents SDK. - latent-space-reasoning (reasoning): reason in continuous hidden-state space, feeding the last hidden state back as the next input embedding (Coconut). Examples: pseudo skeleton + training-curriculum pseudo. 8 mirrored complements/alternative-to back-edges added. Lint clean across all 16 rules at 421 patterns; examples lint 0 errors; all reference URLs verified live.
1 parent 2f0b311 commit 78984cb

11 files changed

Lines changed: 869 additions & 7 deletions

INDEX.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Pattern Index
22

3-
417 patterns across 14 categories.
3+
421 patterns across 14 categories.
44

55
## Reasoning
66

@@ -11,7 +11,9 @@
1111
- [Generate-and-Test Strategy](patterns/generate-and-test-strategy.md) *(a.k.a. Multi-Hypothesis with Constraint Verification, Hypothesize-then-Test)* — Generate multiple candidate solutions in parallel, then systematically test each against declared constraints rather than committing to the first plausible one — adapted from Langley & Simon's cognitive-science research on human expert problem-solving.
1212
- [Graph of Thoughts](patterns/graph-of-thoughts.md) *(a.k.a. GoT, DAG Reasoning)* — Model reasoning as an arbitrary DAG so thoughts can be merged, refined, and aggregated across branches.
1313
- [Large Reasoning Model (LRM) Paradigm](patterns/large-reasoning-model-paradigm.md) *(a.k.a. LRM, Reasoning-Tuned Model, Inference-Time Reasoning)* — Route reasoning-heavy tasks to a reasoning-tuned model that trades inference time for deliberation, rather than to a fast LLM that exhibits premature-closure.
14+
- [Latent-Space Reasoning](patterns/latent-space-reasoning.md) *(a.k.a. Continuous-Thought Reasoning, Coconut, Latent Chain-of-Thought)* — Let the model reason in continuous hidden-state space instead of decoding each step to text, feeding the last hidden state back as the next input embedding, so one latent step can hold several continuations.
1415
- [Least-to-Most Prompting](patterns/least-to-most.md) *(a.k.a. L2M, Easy-First Decomposition)* — Decompose a hard problem into an ordered list of easier subproblems, then solve them sequentially with each answer feeding the next.
16+
- [Recursive Language Model](patterns/recursive-language-model.md) *(a.k.a. RLM, Prompt-as-Environment Recursion, Recursive Inference)* — Treat an over-long prompt as an environment the model navigates by code, letting it partition and recursively call itself over snippets, so it answers over inputs far larger than its context window.
1517
- [ReST-EM](patterns/rest-em.md) *(a.k.a. Reinforced Self-Training, Self-Training Loop)* — Iterate generate → reward-filter → fine-tune to bootstrap reasoning capabilities without human-labelled data.
1618
- [Self-Ask](patterns/self-ask.md) *(a.k.a. Decompose-Ask, Sub-Question Prompting)* — Have the model emit explicit follow-up sub-questions, answer them (optionally via search), then compose the final answer.
1719
- [Socratic Questioning Agent](patterns/socratic-questioning-agent.md) *(a.k.a. Dialog-Driven Agent, Socratic/対話駆動 エージェント, SocraticAI)* — Drive the agent toward its goal by asking the user a sequence of strategic, open-ended questions that surface the user's own latent knowledge, goal, or context — rather than producing an answer directly.
@@ -155,6 +157,7 @@
155157
## Multi-Agent
156158

157159
- [Actor-Model Agents](patterns/actor-model-agents.md) *(a.k.a. Actor Agents, Mailbox Agents, Message-Passing Agents)* — Implement each agent as an independent actor with its own mailbox, processing asynchronous messages one at a time and never sharing mutable state with peers.
160+
- [Agent Capability Manifest](patterns/agent-capability-manifest.md) *(a.k.a. Agent Card, Agent Capability Descriptor, Well-Known Agent Manifest)* — Let each agent publish a standardized self-description — identity, skills, endpoint, and auth needs — at a well-known location, so others discover it and bind by capability at runtime instead of through hardcoded coupling.
158161
- [Agent-as-Tool Embedding](patterns/agent-as-tool-embedding.md) *(a.k.a. Sub-Agent as Function, Nested Agent, Agent Wrapped in a Tool Signature)* — Wrap a sub-agent (with its own loop, prompt, and tool palette) behind a single function-shaped tool signature, so the parent agent calls it like any other tool and never sees the sub-agent's internal turns.
159162
- [Blackboard](patterns/blackboard.md) *(a.k.a. Shared Workspace, Collaboration Whiteboard)* — Give multiple agents a shared, queryable workspace they can read from and write to as they collaborate.
160163
- [CAMEL Role-Playing](patterns/camel-role-playing.md) *(a.k.a. Inception Prompting, AI-User AI-Assistant)* — Have two agents role-play a user-assistant interaction to autonomously complete a task neither could solve alone.
@@ -306,6 +309,7 @@
306309
## Governance & Observability
307310

308311
- [Agent Evaluator](patterns/agent-evaluator.md) *(a.k.a. Agent-Performance Testing Harness, Dedicated Agent-Test Agent)* — A dedicated agent or harness whose sole job is running tests against another agent's outputs to evaluate performance; distinct from eval-harness (offline batch) and llm-as-judge (per-output).
312+
- [Agent Factory](patterns/agent-factory.md) *(a.k.a. Agent Template Factory, Fleet Agent Provisioning)* — Manufacture agent instances from a versioned template that renders model, tools, and prompt atomically, with registry-backed identities, so a fleet stays consistent and one template change propagates instead of drifting per instance.
309313
- [Agent Middleware Chain](patterns/agent-middleware-chain.md) *(a.k.a. Agent Interceptor Pipeline, Pre/Post Middleware)* — Wrap every model call, tool call, and memory access in a composable pre/execute/post interceptor pipeline so cross-cutting concerns attach without touching agent or orchestrator code.
310314
- [Agent Resumption](patterns/agent-resumption.md) *(a.k.a. Durable Execution, Pause-and-Resume, Long-Running Agent State)* — Persist agent execution state so a long-running run survives restarts, deploys, or user disconnects.
311315
- [Agent-as-a-Judge](patterns/agent-as-judge.md) *(a.k.a. Trajectory Evaluator, Judge Agent)* — Evaluate an agent's full trajectory (steps, tool calls, intermediate states) by another agent rather than scoring only the final output.

examples-src/governance-observability.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,34 @@
10011001
"last_updated": "2026-05-26"
10021002
}
10031003
]
1004+
},
1005+
{
1006+
"pattern_id": "agent-factory",
1007+
"intent": "Render an agent instance atomically from a versioned template, register it with its version, and propagate a template change across the fleet.",
1008+
"examples": [
1009+
{
1010+
"framework": "pseudo",
1011+
"framework_label": "Pseudo-code",
1012+
"language": "pseudo",
1013+
"intent": "Framework-agnostic skeleton: atomic render from a versioned template, registry-backed identity, and one-place fleet propagation.",
1014+
"code": "# Versioned template = one unit: model + tools + prompt + policy\nTEMPLATE = {\n \"version\": \"v7\",\n \"model\": \"gpt-5\",\n \"tools\": [\"search\", \"ticket.create\"],\n \"prompt\": \"support_agent.md\",\n \"policy\": {\"max_refund\": 100},\n}\n\nfunction render_instance(template, params): # ATOMIC: all-or-nothing\n inst = build(model=template.model, tools=template.tools,\n prompt=fill(template.prompt, params), policy=template.policy)\n inst.id = registry.new_id()\n registry.put(inst.id, template_version=template.version, params=params)\n return inst\n\nfunction provision(template, param_list):\n return [render_instance(template, p) for p in param_list]\n\nfunction propagate(template): # fleet-wide update from ONE place\n for inst in registry.instances_on_older_version(template.version):\n new = render_instance(template, inst.params) # re-render atomically\n migrate_state(old=inst, new=new) # preserve memory / in-flight work\n registry.replace(inst.id, new, template_version=template.version)\n\n# Drift is queryable: the registry knows which version every instance runs.",
1015+
"verified": false,
1016+
"verified_date": null,
1017+
"last_updated": "2026-05-26"
1018+
},
1019+
{
1020+
"framework": "crewai",
1021+
"framework_label": "CrewAI",
1022+
"language": "python",
1023+
"intent": "CrewAI agents are defined declaratively in agents.yaml; the same template instantiates many consistent per-customer agents, and editing the YAML re-renders them.",
1024+
"source_url": "https://docs.crewai.com/concepts/agents",
1025+
"sdk_version": "crewai>=0.70.0",
1026+
"code": "# config/agents.yaml — the versioned template (one unit per agent type):\n# support_agent:\n# role: \"Customer Support for {customer}\"\n# goal: \"Resolve {customer} tickets within policy\"\n# llm: gpt-5\n# tools: [search_tool, ticket_tool]\n\nfrom crewai import Agent\nfrom crewai.project import CrewBase, agent\n\nclass SupportFactory(CrewBase):\n agents_config = \"config/agents.yaml\" # versioned template\n\n @agent\n def support_agent(self) -> Agent:\n # One template renders every per-customer instance from the same definition.\n return Agent(config=self.agents_config[\"support_agent\"])\n\n# Provision a fleet: same template, per-instance params.\nfleet = [SupportFactory().support_agent() for customer in customers]\n# Bumping agents.yaml re-renders every instance consistently, instead of editing each.",
1027+
"verified": false,
1028+
"verified_date": null,
1029+
"last_updated": "2026-05-26"
1030+
}
1031+
]
10041032
}
10051033
]
10061034
}

examples-src/multi-agent.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,34 @@
16721672
"last_updated": "2026-05-24"
16731673
}
16741674
]
1675+
},
1676+
{
1677+
"pattern_id": "agent-capability-manifest",
1678+
"intent": "An agent serves a versioned capability manifest at a well-known path; a caller discovers it and binds by capability instead of hardcoding the endpoint.",
1679+
"examples": [
1680+
{
1681+
"framework": "pseudo",
1682+
"framework_label": "Pseudo-code",
1683+
"language": "pseudo",
1684+
"intent": "Framework-agnostic skeleton: serve a manifest at a well-known location; discover by capability and bind at runtime.",
1685+
"code": "# Provider agent serves its manifest at a well-known location:\nMANIFEST = {\n \"name\": \"currency-agent\",\n \"version\": \"1.2.0\",\n \"skills\": [\"currency.convert\", \"currency.rate\"],\n \"endpoint\": \"https://fx.example/agent\",\n \"auth\": {\"scheme\": \"oauth2\", \"scopes\": [\"fx.read\"]},\n}\nserve(\"/.well-known/agent-card.json\", MANIFEST)\n\n# Caller discovers by capability and binds at runtime (no hardcoded endpoint):\nfunction find_and_call(need, payload):\n for url in candidate_agents():\n m = http_get(url + \"/.well-known/agent-card.json\")\n if need in m.skills and supports(m.auth):\n token = authenticate(m.auth)\n return http_post(m.endpoint, payload, token=token) # bind by capability\n raise NoCapableAgent(need)\n\nresult = find_and_call(\"currency.convert\", {\"from\": \"USD\", \"to\": \"EUR\", \"amount\": 100})",
1686+
"verified": false,
1687+
"verified_date": null,
1688+
"last_updated": "2026-05-26"
1689+
},
1690+
{
1691+
"framework": "google-adk",
1692+
"framework_label": "Google ADK (A2A)",
1693+
"language": "python",
1694+
"intent": "Google ADK exposes an agent over A2A, which serves a standard Agent Card (capability manifest) at /.well-known/agent-card.json for other agents to discover.",
1695+
"source_url": "https://google.github.io/adk-docs/a2a/",
1696+
"sdk_version": "google-adk>=1.0.0",
1697+
"code": "from google.adk.agents import Agent\nfrom google.adk.a2a import to_a2a\n\ncurrency_agent = Agent(\n name=\"currency_agent\",\n model=\"gemini-2.5-flash\",\n instruction=\"Convert currencies and quote rates.\",\n tools=[convert, rate],\n)\n\n# Expose over A2A: serves a capability manifest (Agent Card) at the well-known path,\n# so any A2A client can discover the agent's skills, endpoint, and auth and bind to it.\na2a_app = to_a2a(currency_agent, port=8001)\n# GET http://localhost:8001/.well-known/agent-card.json -> {name, skills, url, ...}",
1698+
"verified": false,
1699+
"verified_date": null,
1700+
"last_updated": "2026-05-26"
1701+
}
1702+
]
16751703
}
16761704
]
16771705
}

examples-src/reasoning.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,60 @@
607607
"last_updated": "2026-05-24"
608608
}
609609
]
610+
},
611+
{
612+
"pattern_id": "recursive-language-model",
613+
"intent": "Hold the over-long input as data in a REPL; the model writes code to partition it and recursively calls itself over chosen snippets, bounded by depth.",
614+
"examples": [
615+
{
616+
"framework": "pseudo",
617+
"framework_label": "Pseudo-code",
618+
"language": "pseudo",
619+
"intent": "Framework-agnostic skeleton: prompt-as-environment, model-chosen partition, depth-bounded recursive self-calls, then combine.",
620+
"code": "# The long input lives as DATA in a code environment, not in the prompt.\nfunction rlm(query, env, depth=0, max_depth=3):\n if depth >= max_depth or fits_in_window(env.size()):\n return llm(prompt=query, context=env.read()) # base case\n\n # Root model writes code to inspect + partition the input it can see.\n plan = llm_code(query, env.preview()) # e.g. grep / slice\n snippets = env.run(plan.partition_code) # model-chosen split\n\n partials = []\n for s in snippets: # recurse over chosen pieces\n sub_env = env.view(s)\n partials.append(rlm(plan.subquery(s), sub_env, depth + 1, max_depth))\n\n return llm(prompt=plan.combine_prompt, context=partials) # combine results\n# Only the snippets the model selects ever enter any single call.",
621+
"verified": false,
622+
"verified_date": null,
623+
"last_updated": "2026-05-26"
624+
},
625+
{
626+
"framework": "openai-agents-sdk",
627+
"framework_label": "OpenAI Agents SDK",
628+
"language": "python",
629+
"intent": "Wire the recursion as tools: the over-long input is stored as data, the agent loads only chosen slices, and recurses over snippets.",
630+
"source_url": "https://openai.github.io/openai-agents-python/tools/",
631+
"sdk_version": "openai-agents>=0.1.0",
632+
"code": "from agents import Agent, Runner, function_tool\n\nENV = {} # holds over-long inputs as data, keyed by id\n\n@function_tool\ndef load(blob_id: str, slice_spec: str) -> str:\n \"\"\"Return only the requested slice of a stored over-long input.\"\"\"\n return ENV[blob_id].slice(slice_spec) # only the chosen snippet enters context\n\n@function_tool\ndef recurse(blob_id: str, slice_spec: str, subquestion: str) -> str:\n \"\"\"Recursively answer a subquestion over one slice of the input.\"\"\"\n snippet = ENV[blob_id].slice(slice_spec)\n return Runner.run_sync(root, f\"{subquestion}\\n\\n{snippet}\").final_output\n\nroot = Agent(\n name=\"rlm\",\n instructions=(\"The input is too big for the context window. Use load() to peek and \"\n \"grep, partition it, recurse() over snippets, then combine.\"),\n tools=[load, recurse],\n)",
633+
"verified": false,
634+
"verified_date": null,
635+
"last_updated": "2026-05-26"
636+
}
637+
]
638+
},
639+
{
640+
"pattern_id": "latent-space-reasoning",
641+
"intent": "Feed the last hidden state back as the next input embedding for N latent steps, then decode only the final answer; train the model to use latent steps.",
642+
"examples": [
643+
{
644+
"framework": "pseudo",
645+
"framework_label": "Pseudo-code",
646+
"language": "pseudo",
647+
"intent": "Framework-agnostic skeleton: the continuous-thought inference loop — feed the hidden state back instead of decoding to a token.",
648+
"code": "# Reason in latent space: no intermediate decoding to tokens.\nfunction latent_reason(question, n_latent_steps):\n h = encode(question) # hidden state after reading the question\n for _ in range(n_latent_steps):\n # 'continuous thought': the last hidden state IS the next input embedding,\n # NOT decoded to a word token, so it can encode several next steps at once.\n h = model.step(input_embedding=h) # feed the hidden state straight back\n return decode(h) # only the final answer becomes text",
649+
"verified": false,
650+
"verified_date": null,
651+
"last_updated": "2026-05-26"
652+
},
653+
{
654+
"framework": "pseudo",
655+
"framework_label": "Pseudo-code (training)",
656+
"language": "pseudo",
657+
"intent": "Composition with training: a curriculum gradually replaces text reasoning steps with latent ones so the model learns to use continuous thoughts.",
658+
"code": "# Curriculum (Coconut-style): stage k replaces the first k text reasoning steps\n# with latent steps; the rest stay as text supervision.\nfor stage in range(0, max_steps + 1):\n for (question, cot_steps, answer) in dataset:\n text_tail = cot_steps[stage:] # remaining steps stay as text\n target = render(question, latent_steps=stage, text=text_tail, answer=answer)\n loss = train_step(target) # learn to reason with `stage` latent steps\n\n# At inference: run all reasoning as continuous thoughts, decode only the answer.\n# Trade-off: faster, searchier reasoning -- but no human-readable trace to audit.",
659+
"verified": false,
660+
"verified_date": null,
661+
"last_updated": "2026-05-26"
662+
}
663+
]
610664
}
611665
]
612666
}

0 commit comments

Comments
 (0)