Skip to Content
B Berry Docs
Reference

Composition patterns

The same maintained guide available through berry guide patterns.

Source reference · cd46e0e78d73Read Markdown

These are design patterns for Berry compositions. Choose a pattern for a concrete problem, then combine only the responsibilities the task needs. A direct answer or one deterministic operation can remain a single routine.

Selection and loading

Invoke choose_pattern with the design problem, constraints or a pattern name. It returns one exact guide through ordinary load. Broad, ambiguous, comparative or multi-pattern requests select this catalog; use the references below to load individual guides. An explicit pattern request takes precedence over a guessed alternative. Reading a guide neither executes its examples nor grants Tools.

How to read an example

Each fenced markdown block is a complete central routine source. Names beginning with example_ identify example routines, not installed capabilities. Some examples show one round, expansion or policy boundary of a larger algorithm; the guide states which participants and controller responsibilities remain to be supplied. These are not complete deployable implementations of every research system.

Supply the named helper routines with the contracts described next to the example, or declare an actual host Tool as a composition requirement and obtain its grant. Use the receiving Tool definitions and native authoring reference; never infer a host API from an example name. A source declares its full logical name in frontmatter; use its final segment as the filename. For example, patterns/react.md declares name: patterns.react. Directories do not assign names. The bundle's plugin.json declares public agents with stable IDs, titles, descriptions and callable entries, plus reusable exports. Agents require package name/version; libraries omit agents. Routine frontmatter remains the technical call contract. Tool requirements are derived from the connected definitions against the supplied runtime catalog. The repository compiles all these examples and checks their classifier mappings. Compilation establishes syntax and links, not live task quality.

Use tools for nested calls, next for transfers, finite classification outputs for semantic decisions, and code for exact data transformations or algorithms. Carry original requests and exact evidence explicitly through next.input. State is for records that must survive invocations; native context and History retain their own owners. Model choice, execution limits and grants come from the receiving preparation and invocation.

Action and planning

  • [[patterns.react]]
  • [[patterns.least_to_most]]
  • [[patterns.plan_and_solve]]
  • [[patterns.plan_and_act]]
  • [[patterns.rewoo]]
  • [[patterns.llm_compiler]]
  • [[patterns.code_act]]
  • [[patterns.pal]]
  • [[patterns.chain_of_thought]]
  • [[patterns.self_consistency]]
  • [[patterns.best_of_n]]
  • [[patterns.tree_of_thoughts]]
  • [[patterns.graph_of_thoughts]]
  • [[patterns.lats]]
  • [[patterns.alphaevolve]]

Verification and refinement

  • [[patterns.self_refine]]
  • [[patterns.reflexion]]
  • [[patterns.critic]]
  • [[patterns.chain_of_verification]]

Retrieval

  • [[patterns.retrieval_augmented_generation]]
  • [[patterns.ircot]]
  • [[patterns.self_rag]]

Multiple model participants

  • [[patterns.multiagent_debate]]
  • [[patterns.mixture_of_agents]]

Memory and reuse

  • [[patterns.memgpt]]
  • [[patterns.voyager]]
  • [[patterns.agentic_context_engineering]]
  • [[patterns.recursive_language_models]]

Composition building blocks

  • [[patterns.prompt_chaining]]
  • [[patterns.routing]]
  • [[patterns.parallelization]]
  • [[patterns.orchestrator_workers]]
  • [[patterns.evaluator_optimizer]]

Combining patterns

A planner can delegate to a ReAct executor, use Best-of-N for a candidate choice, run CRITIC verification and retain a Reflexion lesson. Each layer should have one explicit purpose, input/output contract and acceptance boundary. Keep independent candidates separate and identify which exact candidate was checked.

Verification boundaries

Verify the final composition against realistic inputs and actual effects. Controlled calls establish data flow and lifecycle; live evaluations establish only the measured model/task combination. Research benchmarks do not establish equivalent quality for another model, workload or Tool set.

A loaded pattern cannot bypass permissions, renew deadlines or authorize an effect replay. Missing review evidence preserves completed work. An indivisible oversized classification input refuses under shared admission; do not summarize or discard its original source to obtain a verdict. Search over effectful trajectories requires a genuine environment reset/branch contract. Parallel routines still share any granted mutable files or State.

On this page