Skip to content

Generate from a Description

ChainBuilder.from_description asks an LLM to plan a chain for a task, then parses the plan through ReasoningChain.from_dict, so the usual validation applies (cycle detection, dependency references, reference-syntax warnings).

from mmar_carl import ChainBuilder
chain = await ChainBuilder.from_description(
task="Outline the key arguments in the text, then condense them to 3 bullets.",
llm_client=client,
max_steps=4,
max_retries=2, # self-correct on validation errors
available_tools=["fetch", "summarise"],
)

It is an async classmethod.

Since 0.5.0 the planning prompt is rendered from the live step catalog (get_step_catalog().generation_prompt(...)), so it describes every registered step type, with a compact card per type and the $... reference grammar. available_tools and available_skills are listed for tool and agent_skill steps. capability_library (a CapabilityLibrary) adds a curated list of tools and skills to the prompt. MAESTRO does not use this helper; it has its own generator.

ParameterTypeDefaultPurpose
taskstrrequiredWhat the chain should do.
llm_clientAnyrequiredAn LLMClientBase, or any object with async get_response_with_retries(prompt, retries=…) or get_response(prompt).
available_skillslist[str] | NoneNoneSkill names the planner may use in agent_skill steps.
available_toolslist[str] | NoneNoneTool names the planner is told to use in tool steps.
capability_libraryCapabilityLibrary | NoneNoneExtra tool and skill descriptions for the prompt (EvoC).
max_stepsint10Upper bound on planned steps (ValueError if exceeded).
max_workersint | str"auto"Worker setting on the resulting chain.
extra_instructionsstr""Free text appended to the planning prompt.
max_retriesint2Self-correction rounds when the plan fails to parse or validate.

The reply may be wrapped in a ```json fence; it is stripped.

The planner trail is written into chain.metadata for offline diagnosis: planner_prompt and planner_reply (both truncated), planner_attempts (one entry per attempt with its prompt, reply and validation error), and generated_from_description.