Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.
Feature/pipe builder improve (#317)
Louis Choquel6cfa6897387e
diff --git a/.badges/tests.json b/.badges/tests.jsonindex 5353808dd..baa674784 100644--- a/.badges/tests.json+++ b/.badges/tests.json@@ -1,7 +1,7 @@{"schemaVersion": 1,"label": "tests",- "message": "1051",+ "message": "1055","color": "blue","cacheSeconds": 300}\ No newline at end of filediff --git a/.pipelex/inference/deck/base_deck.toml b/.pipelex/inference/deck/base_deck.tomlindex 900235960..73653e70c 100644--- a/.pipelex/inference/deck/base_deck.toml+++ b/.pipelex/inference/deck/base_deck.toml@@ -23,7 +23,13 @@ cheap_llm_for_object = "gpt-4o-mini"base_llm_for_text = "gpt-4o-mini"base_llm_for_object = "gpt-4o-mini"-llm_to_engineer = ["claude-4.1-opus", "gemini-2.5-pro"]+smart_llm = [+ "claude-4.5-sonnet",+ "claude-4.1-opus",+ "claude-4-sonnet",+ "gpt-5",+ "gemini-2.5-pro",+]llm_for_large_codebase = ["gemini-2.5-pro", "claude-4-sonnet", "gpt-5"]# Image generation aliases@@ -71,7 +77,7 @@ llm_to_enrich = { llm_handle = "base-claude", temperature = 0.1 }llm_for_question_and_excerpt_reformulation = { llm_handle = "gpt-4o", temperature = 0.9 }# Engineering skills-llm_to_engineer = { llm_handle = "base-claude", temperature = 0.2 }+llm_to_engineer = { llm_handle = "smart_llm", temperature = 0.2 }llm_to_write = { llm_handle = "base-gemini", temperature = 0.2 }llm_to_pipelex = { llm_handle = "base-claude", temperature = 0.2 }@@ -126,4 +132,3 @@ img_gen_for_diagram = { img_gen_handle = "base-img-gen", quality = "medium", guiimg_gen_for_mockup = { img_gen_handle = "base-img-gen", quality = "medium", guidance_scale = 6.5, is_moderated = true, safety_tolerance = 3 }img_gen_for_product = { img_gen_handle = "best-img-gen", quality = "high", guidance_scale = 8.5, is_moderated = true, safety_tolerance = 2 }img_gen_for_testing = { img_gen_handle = "fast-img-gen", nb_steps = 4, guidance_scale = 4.0, is_moderated = true, safety_tolerance = 4 }-diff --git a/docs/pages/configuration/config-technical/inference-backend-config.md b/docs/pages/configuration/config-technical/inference-backend-config.mdindex 8bb35043e..9baf86ad6 100644--- a/docs/pages/configuration/config-technical/inference-backend-config.md+++ b/docs/pages/configuration/config-technical/inference-backend-config.md@@ -187,6 +187,13 @@ base-claude = "claude-4-sonnet"base-gpt = "gpt-5"base-gemini = "gemini-2.5-flash"base-mistral = "mistral-medium"+smart_llm = [+ "claude-4.5-sonnet",+ "claude-4.1-opus",+ "claude-4-sonnet",+ "gpt-5",+ "gemini-2.5-pro",+]# OCR aliasesbest-ocr = "mistral-ocr"@@ -198,7 +205,7 @@ best-img-gen = "flux-pro/v1.1-ultra"fast-img-gen = "fast-lightning-sdxl"# Aliases can also define fallback chains-llm_to_engineer = ["claude-4.1-opus", "gemini-2.5-pro"]+llm_to_engineer = { llm_handle = "smart_llm", temperature = 0.2 }```### LLM Presetsdiff --git a/pipelex/cli/commands/build_cmd.py b/pipelex/cli/commands/build_cmd.pyindex ba13a3cce..f4c8dd889 100644--- a/pipelex/cli/commands/build_cmd.py+++ b/pipelex/cli/commands/build_cmd.py@@ -12,12 +12,14 @@ from pipelex.libraries.pipelines.builder.builder_loop import BuilderLoopfrom pipelex.pipelex import Pipelexfrom pipelex.pipeline.execute import execute_pipelinefrom pipelex.tools.misc.file_utils import ensure_directory_for_file_path, save_text_to_path+from pipelex.tools.misc.json_utils import save_as_json_to_pathbuild_app = typer.Typer(help="Build artifacts like pipelines", no_args_is_help=True)"""Today's example:-pipelex build pipe "Given a scanned invoice, extract employee and articles"+pipelex build pipe "Given an expense report, apply company rules"+pipelex build partial "Given an expense report, apply company rules" -o results/generated.jsonOther ideas:pipelex build pipe "Take a photo as input, and render the opposite of the photo"@@ -124,3 +126,52 @@ def build_pipe_cmd(typer.echo(typer.style(f"\n✅ Pipeline built in {end_time - start_time:.2f} seconds", fg=typer.colors.GREEN))get_report_delegate().generate_report()+++@build_app.command("partial")+def build_partial_cmd(+ brief: Annotated[+ str,+ typer.Argument(help="Brief description of what the pipeline should do"),+ ],+ output_path: Annotated[+ str,+ typer.Option("--output", "-o", help="Path to save the generated PLX file"),+ ] = "./results/generated_pipeline.plx",+ no_output: Annotated[+ bool,+ typer.Option("--no-output", help="Skip saving the pipeline to file"),+ ] = False,+) -> None:+ Pipelex.make(relative_config_folder_path="../../../pipelex/libraries", from_file=True)+ typer.echo("=" * 70)+ typer.echo(typer.style("🔥 Starting pipe builder... 🚀", fg=typer.colors.GREEN))+ typer.echo("")++ async def run_pipeline():+ if no_output:+ typer.echo(typer.style("\n⚠️ Pipeline will not be saved to file (--no-output specified)", fg=typer.colors.YELLOW))+ elif not output_path:+ typer.echo(typer.style("\n🛑 Cannot save a pipeline to an empty file name", fg=typer.colors.RED))+ raise typer.Exit(1)+ else:+ ensure_directory_for_file_path(file_path=output_path)++ pipe_output = await execute_pipeline(+ pipe_code="pipe_builder",+ input_memory={"brief": brief},+ )+ # Save to file unless explicitly disabled with --no-output+ if no_output:+ typer.echo(typer.style("\n⚠️ Pipeline not saved to file (--no-output specified)", fg=typer.colors.YELLOW))+ return+ json_output = pipe_output.main_stuff.content.smart_dump()+ save_as_json_to_path(object_to_save=json_output, path=output_path)+ typer.echo(typer.style(f"\n✅ Pipeline saved to: {output_path}", fg=typer.colors.GREEN))++ start_time = time.time()+ asyncio.run(run_pipeline())+ end_time = time.time()+ typer.echo(typer.style(f"\n✅ Pipeline built in {end_time - start_time:.2f} seconds", fg=typer.colors.GREEN))++ get_report_delegate().generate_report()diff --git a/pipelex/config_template/inference/backends/anthropic.toml b/pipelex/config_template/inference/backends/anthropic.tomlindex a7b98c0c0..e0daf1c3a 100644--- a/pipelex/config_template/inference/backends/anthropic.toml+++ b/pipelex/config_template/inference/backends/anthropic.toml@@ -43,23 +43,6 @@ outputs = ["text", "structured"]max_prompt_images = 100costs = { input = 15.0, output = 75.0 }-# --- Claude 3.5 Series ---------------------------------------------------------["claude-3.5-sonnet"]-model_id = "claude-3-5-sonnet-20240620"-max_tokens = 8192-inputs = ["text", "images"]-outputs = ["text", "structured"]-max_prompt_images = 100-costs = { input = 3.0, output = 15.0 }--["claude-3.5-sonnet-v2"]-model_id = "claude-3-5-sonnet-20241022"-max_tokens = 8192-inputs = ["text", "images"]-outputs = ["text", "structured"]-max_prompt_images = 100-costs = { input = 3.0, output = 15.0 }-# --- Claude 3.7 Series --------------------------------------------------------["claude-3.7-sonnet"]model_id = "claude-3-7-sonnet-20250219"@@ -95,3 +78,11 @@ outputs = ["text", "structured"]max_prompt_images = 100costs = { input = 3.0, output = 15.0 }+# --- Claude 4.5 Series --------------------------------------------------------+["claude-4.5-sonnet"]+model_id = "claude-sonnet-4-5-20250929"+max_tokens = 64000+inputs = ["text", "images"]+outputs = ["text", "structured"]+max_prompt_images = 100+costs = { input = 3.0, output = 15.0 }diff --git a/pipelex/config_template/inference/backends/bedrock.toml b/pipelex/config_template/inference/backends/bedrock.tomlindex 3c354bb0b..e572302c8 100644--- a/pipelex/config_template/inference/backends/bedrock.toml+++ b/pipelex/config_template/inference/backends/bedrock.toml@@ -53,24 +53,6 @@ outputs = ["text"]costs = { input = 3.0, output = 15.0 }# --- Claude LLMs ---------------------------------------------------------------["claude-3.5-sonnet"]-sdk = "bedrock_anthropic"-model_id = "us.anthropic.claude-3-5-sonnet-20240620-v1:0"-max_tokens = 8192-inputs = ["text", "images"]-outputs = ["text", "structured"]-max_prompt_images = 100-costs = { input = 3.0, output = 15.0 }--["claude-3.5-sonnet-v2"]-sdk = "bedrock_anthropic"-model_id = "anthropic.claude-3-5-sonnet-20241022-v2:0"-max_tokens = 8192-inputs = ["text", "images"]-outputs = ["text", "structured"]-max_prompt_images = 100-costs = { input = 3.0, output = 15.0 }-["claude-3.7-sonnet"]sdk = "bedrock_anthropic"model_id = "us.anthropic.claude-3-7-sonnet-20250219-v1:0"@@ -107,3 +89,13 @@ outputs = ["text", "structured"]max_prompt_images = 100costs = { input = 3.0, output = 15.0 }+# anthropic.claude-sonnet-4-5-20250929-v1:0,Anthropic,arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-sonnet-4-5-20250929-v1:0,++["claude-4.5-sonnet"]+sdk = "bedrock_anthropic"+model_id = "us.anthropic.claude-sonnet-4-5-20250929-v1:0"+max_tokens = 8192+inputs = ["text", "images"]+outputs = ["text", "structured"]+max_prompt_images = 100+costs = { input = 3.0, output = 15.0 }diff --git a/pipelex/config_template/inference/backends/pipelex_inference.toml b/pipelex/config_template/inference/backends/pipelex_inference.tomlindex 2c326cfce..d850714e8 100644--- a/pipelex/config_template/inference/backends/pipelex_inference.toml+++ b/pipelex/config_template/inference/backends/pipelex_inference.toml@@ -88,6 +88,12 @@ inputs = ["text", "images"]outputs = ["text", "structured"]costs = { input = 15, output = 75 }+["claude-4.5-sonnet"]+model_id = "pipelex/claude-4.5-sonnet"+inputs = ["text", "images"]+outputs = ["text", "structured"]+costs = { input = 3, output = 15 }+# --- Gemini LLMs --------------------------------------------------------------["gemini-2.0-flash"]model_id = "gemini/gemini-2.0-flash"@@ -127,4 +133,3 @@ costs = { input = 0.3, output = 0.5 }# We are still working in giving you acces to OCR and image generation models# and to the best models from Mistral through the Pipelex Inference backend.-diff --git a/pipelex/config_template/inference/deck/base_deck.toml b/pipelex/config_template/inference/deck/base_deck.tomlindex 900235960..73653e70c 100644--- a/pipelex/config_template/inference/deck/base_deck.toml+++ b/pipelex/config_template/inference/deck/base_deck.toml@@ -23,7 +23,13 @@ cheap_llm_for_object = "gpt-4o-mini"base_llm_for_text = "gpt-4o-mini"base_llm_for_object = "gpt-4o-mini"-llm_to_engineer = ["claude-4.1-opus", "gemini-2.5-pro"]+smart_llm = [+ "claude-4.5-sonnet",+ "claude-4.1-opus",+ "claude-4-sonnet",+ "gpt-5",+ "gemini-2.5-pro",+]llm_for_large_codebase = ["gemini-2.5-pro", "claude-4-sonnet", "gpt-5"]# Image generation aliases@@ -71,7 +77,7 @@ llm_to_enrich = { llm_handle = "base-claude", temperature = 0.1 }llm_for_question_and_excerpt_reformulation = { llm_handle = "gpt-4o", temperature = 0.9 }# Engineering skills-llm_to_engineer = { llm_handle = "base-claude", temperature = 0.2 }+llm_to_engineer = { llm_handle = "smart_llm", temperature = 0.2 }llm_to_write = { llm_handle = "base-gemini", temperature = 0.2 }llm_to_pipelex = { llm_handle = "base-claude", temperature = 0.2 }@@ -126,4 +132,3 @@ img_gen_for_diagram = { img_gen_handle = "base-img-gen", quality = "medium", guiimg_gen_for_mockup = { img_gen_handle = "base-img-gen", quality = "medium", guidance_scale = 6.5, is_moderated = true, safety_tolerance = 3 }img_gen_for_product = { img_gen_handle = "best-img-gen", quality = "high", guidance_scale = 8.5, is_moderated = true, safety_tolerance = 2 }img_gen_for_testing = { img_gen_handle = "fast-img-gen", nb_steps = 4, guidance_scale = 4.0, is_moderated = true, safety_tolerance = 4 }-diff --git a/pipelex/config_template/inference/routing_profiles.toml b/pipelex/config_template/inference/routing_profiles.tomlindex cd264a177..88727fd4f 100644--- a/pipelex/config_template/inference/routing_profiles.toml+++ b/pipelex/config_template/inference/routing_profiles.toml@@ -37,6 +37,10 @@ default = "pipelex_inference""gpt-image-1" = "openai""mistral-ocr" = "mistral"+[profiles.all_bedrock]+description = "Use Bedrock backend for all its supported models"+default = "bedrock"+[profiles.all_anthropic]description = "Use Anthropic backend for all its supported models"default = "anthropic"@@ -48,6 +52,7 @@ default = "google"[profiles.all_azure_openai]description = "Use Azure OpenAI backend for all its supported models"default = "azure_openai"+[profiles.custom_routing]description = "Custom routing"default = "pipelex_inference"@@ -72,8 +77,6 @@ description = "Route models to various backends""gpt-5-chat" = "azure_openai""claude-4-sonnet" = "pipelex_inference"-"claude-3.5-sonnet" = "bedrock"-"claude-3.5-sonnet-v2" = "anthropic""claude-3.7-sonnet" = "blackboxai""gemini-2.5-flash-lite" = "pipelex_inference"diff --git a/pipelex/core/pipes/pipe_blueprint.py b/pipelex/core/pipes/pipe_blueprint.pyindex 13555a97f..b63ee8a04 100644--- a/pipelex/core/pipes/pipe_blueprint.py+++ b/pipelex/core/pipes/pipe_blueprint.py@@ -17,6 +17,22 @@ class AllowedPipeCategories(StrEnum):def value_list(cls) -> list[str]:return list(cls)+ @property+ def is_controller(self) -> bool:+ match self:+ case AllowedPipeCategories.PIPE_CONTROLLER:+ return True+ case AllowedPipeCategories.PIPE_OPERATOR:+ return False++ @classmethod+ def is_controller_by_str(cls, category_str: str) -> bool:+ try:+ category = cls(category_str)+ return category.is_controller+ except ValueError:+ return False+class AllowedPipeTypes(StrEnum):# Pipe Operatorsdiff --git a/pipelex/libraries/pipelines/builder/builder.py b/pipelex/libraries/pipelines/builder/builder.pyindex aac29c82f..7e5d05085 100644--- a/pipelex/libraries/pipelines/builder/builder.py+++ b/pipelex/libraries/pipelines/builder/builder.py@@ -311,13 +311,13 @@ async def validate_bundle_spec(pipelex_bundle_spec: PipelexBundleSpec):async def reconstruct_bundle_with_pipe_fixes_from_memory(working_memory: WorkingMemory) -> PipelexBundleSpec:pipelex_bundle_spec = working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)fixed_pipes_list = cast("ListContent[PipeSpecUnion]", working_memory.get_stuff(name="fixed_pipes").content)- return await reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec=pipelex_bundle_spec, fixed_pipes=fixed_pipes_list.items)+ return reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec=pipelex_bundle_spec, fixed_pipes=fixed_pipes_list.items)-async def reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec: PipelexBundleSpec, fixed_pipes: list[PipeSpecUnion]) -> PipelexBundleSpec:+def reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec: PipelexBundleSpec, fixed_pipes: list[PipeSpecUnion]) -> PipelexBundleSpec:if not pipelex_bundle_spec.pipe:msg = "No pipes section found in bundle spec"- raise PipeBuilderError(msg)+ raise PipelexBundleUnexpectedError(msg)for fixed_pipe_blueprint in fixed_pipes:pipe_code = fixed_pipe_blueprint.the_pipe_codediff --git a/pipelex/libraries/pipelines/builder/builder_errors.py b/pipelex/libraries/pipelines/builder/builder_errors.pyindex 0568c0e6f..1e8437249 100644--- a/pipelex/libraries/pipelines/builder/builder_errors.py+++ b/pipelex/libraries/pipelines/builder/builder_errors.py@@ -186,5 +186,9 @@ class PipelexBundleError(PipelexError):)+class PipelexBundleNoFixForError(PipelexError):+ """Raised when no fix is found for a static validation error."""++class PipelexBundleUnexpectedError(PipelexError):"""Raised when an unexpected error occurs during validation."""diff --git a/pipelex/libraries/pipelines/builder/builder_loop.py b/pipelex/libraries/pipelines/builder/builder_loop.pyindex 462b5493e..4d197f4f9 100644--- a/pipelex/libraries/pipelines/builder/builder_loop.py+++ b/pipelex/libraries/pipelines/builder/builder_loop.py@@ -1,4 +1,4 @@-from pipelex import log, pretty_print+from pipelex import pretty_printfrom pipelex.client.protocol import ImplicitMemoryfrom pipelex.core.pipes.pipe_blueprint import AllowedPipeCategoriesfrom pipelex.exceptions import StaticValidationErrorType@@ -10,7 +10,11 @@ from pipelex.libraries.pipelines.builder.builder import (reconstruct_bundle_with_pipe_fixes,validate_bundle_spec,)-from pipelex.libraries.pipelines.builder.builder_errors import PipelexBundleError+from pipelex.libraries.pipelines.builder.builder_errors import (+ PipelexBundleError,+ PipelexBundleNoFixForError,+ PipelexBundleUnexpectedError,+)from pipelex.pipeline.execute import execute_pipelinefrom pipelex.tools.misc.file_utils import save_text_to_path@@ -33,34 +37,56 @@ class BuilderLoop:await validate_bundle_spec(pipelex_bundle_spec=pipelex_bundle_spec)except PipelexBundleError as bundle_error:pretty_print(bundle_error.as_structured_content(), title="Pipelex Bundle Error")- log.error("Some pipes are failing, we should fix them but it's not implemented yet: ", bundle_error.message)+ pipelex_bundle_spec = self._fix_bundle_error(bundle_error=bundle_error, pipelex_bundle_spec=pipelex_bundle_spec)++ return pipelex_bundle_spec++ def _fix_bundle_error(self, bundle_error: PipelexBundleError, pipelex_bundle_spec: PipelexBundleSpec) -> PipelexBundleSpec:+ fixed_pipes: list[PipeSpecUnion] = []- fixed_pipes: list[PipeSpecUnion] = []+ # Fix static validation errors for PipeController inputs+ if bundle_error.static_validation_error:+ static_error = bundle_error.static_validation_error+ if not static_error.pipe_code:+ msg = "Static validation error had no pipe code"+ raise PipelexBundleUnexpectedError(message=msg) from bundle_error+ if not pipelex_bundle_spec.pipe:+ msg = "Static validation error pipelex_bundle_spec had no pipe section"+ raise PipelexBundleUnexpectedError(message=msg) from bundle_error+ pipe_spec = pipelex_bundle_spec.pipe.get(static_error.pipe_code)+ if not pipe_spec:+ msg = f"Static validation error pipelex_bundle_spec had no pipe spec for considered pipe code: '{static_error.pipe_code}'"+ raise PipelexBundleUnexpectedError(message=msg) from bundle_error+ match static_error.error_type:+ case StaticValidationErrorType.MISSING_INPUT_VARIABLE | StaticValidationErrorType.EXTRANEOUS_INPUT_VARIABLE:+ if not AllowedPipeCategories.is_controller_by_str(category_str=pipe_spec.category):+ msg = (+ f"Static validation error pipelex_bundle_spec had a pipe spec for "+ f"considered pipe code: '{static_error.pipe_code}' but it was not a PipeController. "+ "We don't support fixing this error yet."+ )+ raise PipelexBundleNoFixForError(message=msg) from bundle_error- # Fix static validation errors for PipeController inputs- if bundle_error.static_validation_error:- static_error = bundle_error.static_validation_error- if static_error.error_type in (- StaticValidationErrorType.MISSING_INPUT_VARIABLE,- StaticValidationErrorType.EXTRANEOUS_INPUT_VARIABLE,- ):- if static_error.pipe_code and pipelex_bundle_spec.pipe:- pipe_spec = pipelex_bundle_spec.pipe.get(static_error.pipe_code)- if pipe_spec and pipe_spec.category == AllowedPipeCategories.PIPE_CONTROLLER:- pipe = get_required_pipe(pipe_code=static_error.pipe_code)- needed_inputs = pipe.needed_inputs()- # Build the new inputs dict from needed_inputs- new_inputs: dict[str, str] = {}- for named_requirement in needed_inputs.named_input_requirements:- new_inputs[named_requirement.variable_name] = named_requirement.concept.code- # Update the pipe spec inputs- pipe_spec.inputs = new_inputs- fixed_pipes.append(pipe_spec)+ pipe = get_required_pipe(pipe_code=static_error.pipe_code)+ needed_inputs = pipe.needed_inputs()+ # Build the new inputs dict from needed_inputs+ new_inputs: dict[str, str] = {}+ for named_requirement in needed_inputs.named_input_requirements:+ new_inputs[named_requirement.variable_name] = named_requirement.concept.code+ # Update the pipe spec inputs+ pipe_spec.inputs = new_inputs+ fixed_pipes.append(pipe_spec)+ case StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT:+ msg = "Static validation error had inadequate input concept. We don't support fixing this error yet."+ raise PipelexBundleNoFixForError(message=msg) from bundle_error+ case StaticValidationErrorType.TOO_MANY_CANDIDATE_INPUTS:+ msg = "Static validation error had too many candidate inputs. We don't support fixing this error yet."+ raise PipelexBundleNoFixForError(message=msg) from bundle_error- if fixed_pipes:- pipelex_bundle_spec = await reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec=pipelex_bundle_spec, fixed_pipes=fixed_pipes)- pretty_print(pipelex_bundle_spec, title="Pipelex Bundle Spec • 2nd iteration")- plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())- save_text_to_path(text=plx_content, path="results/generated_pipeline_2nd_iteration.plx")+ if fixed_pipes:+ pipelex_bundle_spec = reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec=pipelex_bundle_spec, fixed_pipes=fixed_pipes)+ pretty_print(pipelex_bundle_spec, title="Pipelex Bundle Spec • 2nd iteration")+ plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())+ save_text_to_path(text=plx_content, path="results/generated_pipeline_2nd_iteration.plx")return pipelex_bundle_spec