Skip to content

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.

Add func-registry and mistral-medium

Thomas Hebrard02b7bce60564
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73803017b..e4c080884 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,13 @@
# Changelog
+## [v0.9.6] - 2025-09-16
+
+### Added
+
+- Added `FuncRegistryUtils` to register functions in a pipelex folder that have a specific signature.
+- Added `mistral-medium` and `mistral-medium-2508` to the LLM deck.
+- Added handle for `gemini-2.5-flash` to the LLM deck.
+
## [v0.9.5] - 2025-09-12
### Highlight
diff --git a/pipelex/cogt/llm/llm_models/llm_family.py b/pipelex/cogt/llm/llm_models/llm_family.py
index dc53d18f6..d927352f6 100644
--- a/pipelex/cogt/llm/llm_models/llm_family.py
+++ b/pipelex/cogt/llm/llm_models/llm_family.py
@@ -75,6 +75,7 @@ class LLMFamily(StrEnum):
MISTRAL_8X7B = "mistral-8x7b"
MISTRAL_LARGE = "mistral-large"
MISTRAL_SMALL = "mistral-small"
+ MISTRAL_MEDIUM = "mistral-medium"
MISTRAL_CODESTRAL = "mistral-codestral"
MINISTRAL = "ministral"
PIXTRAL = "pixtral"
@@ -128,6 +129,7 @@ class LLMFamily(StrEnum):
| LLMFamily.MISTRAL_8X7B
| LLMFamily.MISTRAL_LARGE
| LLMFamily.MISTRAL_SMALL
+ | LLMFamily.MISTRAL_MEDIUM
| LLMFamily.MISTRAL_CODESTRAL
| LLMFamily.MINISTRAL
| LLMFamily.PIXTRAL
diff --git a/pipelex/libraries/library_manager.py b/pipelex/libraries/library_manager.py
index 1651b462e..f9cfeb094 100644
--- a/pipelex/libraries/library_manager.py
+++ b/pipelex/libraries/library_manager.py
@@ -28,6 +28,7 @@ from pipelex.exceptions import (
from pipelex.libraries.library_config import LibraryConfig
from pipelex.libraries.library_manager_abstract import LibraryManagerAbstract
from pipelex.tools.class_registry_utils import ClassRegistryUtils
+from pipelex.tools.func_registry_utils import FuncRegistryUtils
from pipelex.tools.misc.file_utils import find_files_in_dir
from pipelex.tools.misc.json_utils import deep_update
from pipelex.tools.misc.toml_utils import TOMLValidationError, load_toml_from_path, validate_toml_file
@@ -243,6 +244,7 @@ class LibraryManager(LibraryManagerAbstract):
# Register classes in the directories
for library_dir in dirs_to_use:
ClassRegistryUtils.register_classes_in_folder(folder_path=str(library_dir))
+ FuncRegistryUtils.register_funcs_in_folder(folder_path=str(library_dir))
if library_file_paths is not None:
all_plx_paths = library_file_paths
diff --git a/pipelex/libraries/llm_deck/base_llm_deck.toml b/pipelex/libraries/llm_deck/base_llm_deck.toml
index 726851f7e..cddfbc0d0 100644
--- a/pipelex/libraries/llm_deck/base_llm_deck.toml
+++ b/pipelex/libraries/llm_deck/base_llm_deck.toml
@@ -13,6 +13,8 @@ llm_external_handles = []
gpt-4o-2024-11-20 = { llm_name = "gpt-4o", llm_version = "2024-11-20" }
base-claude = "claude-4-sonnet"
base-gpt = "gpt-5"
+base-gemini = "gemini-2.5-flash"
+base-mistral = "mistral-medium"
best-gpt = "gpt-5"
best-claude = "claude-4-1-opus"
@@ -47,6 +49,9 @@ llm_for_testing_gen_object = { llm_handle = "base_llm_for_object", temperature =
####################################################################################################
# LLM Presets — Specific skills
+# Cheap llm
+llm_cheap = { llm_handle = "base-gemini", temperature = 0.1 }
+
# Generation skills
llm_for_factual_writing = { llm_handle = "base-gpt", temperature = 0.1 }
llm_for_creative_writing = { llm_handle = "best-claude", temperature = 0.9 }
@@ -81,7 +86,6 @@ llm_to_extract_invoice_from_scan = { llm_handle = "best-claude", temperature = 0
llm_to_extract_legal_terms = { llm_handle = "best-claude", temperature = 0.1 }
llm_to_extract_tables = { llm_handle = "best-claude", temperature = 0.1 }
-
####################################################################################################
# LLM Choices
####################################################################################################
diff --git a/pipelex/libraries/llm_integrations/mistral.toml b/pipelex/libraries/llm_integrations/mistral.toml
index c99cdd8bc..d27135fc2 100644
--- a/pipelex/libraries/llm_integrations/mistral.toml
+++ b/pipelex/libraries/llm_integrations/mistral.toml
@@ -68,3 +68,16 @@ is_vision_supported = true
cost_per_million_tokens_usd = { input = 2.0, output = 6.0 }
platform_llm_id = { mistral = "pixtral-large-latest" }
+[mistral-medium.mistral-medium.latest]
+max_tokens = 128000
+is_gen_object_supported = true
+cost_per_million_tokens_usd = { input = 0.4, output = 2.0 }
+platform_llm_id = { mistral = "mistral-medium-latest" }
+
+
+[mistral-medium.mistral-medium."2508"]
+max_tokens = 128000
+is_gen_object_supported = true
+cost_per_million_tokens_usd = { input = 0.4, output = 2.0 }
+platform_llm_id = { mistral = "mistral-medium-2508" }
+
diff --git a/pipelex/plugins/openai/openai_llm_worker.py b/pipelex/plugins/openai/openai_llm_worker.py
index a5a47f6f7..ef82a408d 100644
--- a/pipelex/plugins/openai/openai_llm_worker.py
+++ b/pipelex/plugins/openai/openai_llm_worker.py
@@ -115,6 +115,7 @@ class OpenAILLMWorker(LLMWorkerInternalAbstract):
| LLMFamily.MISTRAL_8X7B
| LLMFamily.MISTRAL_LARGE
| LLMFamily.MISTRAL_SMALL
+ | LLMFamily.MISTRAL_MEDIUM
| LLMFamily.MISTRAL_CODESTRAL
| LLMFamily.MINISTRAL
| LLMFamily.PIXTRAL
@@ -220,6 +221,7 @@ class OpenAILLMWorker(LLMWorkerInternalAbstract):
| LLMFamily.MISTRAL_8X7B
| LLMFamily.MISTRAL_LARGE
| LLMFamily.MISTRAL_SMALL
+ | LLMFamily.MISTRAL_MEDIUM
| LLMFamily.MISTRAL_CODESTRAL
| LLMFamily.MINISTRAL
| LLMFamily.PIXTRAL
diff --git a/pipelex/tools/func_registry_utils.py b/pipelex/tools/func_registry_utils.py
new file mode 100644
index 000000000..1b8c6b98d
--- /dev/null
+++ b/pipelex/tools/func_registry_utils.py
@@ -0,0 +1,151 @@
+import inspect
+from pathlib import Path
+from typing import Any, Callable, List, get_type_hints
+
+from pipelex.core.memory.working_memory import WorkingMemory
+from pipelex.core.stuffs.stuff_content import StuffContent
+from pipelex.tools.func_registry import func_registry
+from pipelex.tools.typing.module_inspector import import_module_from_file
+
+
+class FuncRegistryUtils:
+ @classmethod
+ def register_funcs_in_folder(
+ cls,
+ folder_path: str,
+ is_recursive: bool = True,
+ ) -> None:
+ """
+ Registers all functions in Python files within a folder that have:
+ - Exactly 1 parameter named "working_memory" with type WorkingMemory
+ - Return type that is a subclass of StuffContent
+
+ The function name is used as the registry key.
+
+ Args:
+ folder_path: Path to folder containing Python files
+ is_recursive: Whether to search recursively in subdirectories
+ """
+ python_files = cls._find_files_in_dir(
+ dir_path=folder_path,
+ pattern="*.py",
+ is_recursive=is_recursive,
+ )
+
+ for python_file in python_files:
+ cls._register_funcs_in_file(file_path=str(python_file))
+
+ @classmethod
+ def _register_funcs_in_file(cls, file_path: str) -> None:
+ """Processes a Python file to find and register eligible functions."""
+ try:
+ module = import_module_from_file(file_path)
+
+ # Find functions that match criteria
+ functions_to_register = cls._find_functions_in_module(module)
+
+ for func in functions_to_register:
+ func_registry.register_function(
+ func=func,
+ name=func.__name__,
+ should_warn_if_already_registered=True,
+ )
+ except Exception as e:
+ # Log error but continue processing other files
+ print(f"Error processing file {file_path}: {e}")
+
+ @classmethod
+ def _find_functions_in_module(cls, module: Any) -> List[Callable[..., Any]]:
+ """
+ Finds all functions in a module that match the criteria:
+ - Exactly 1 parameter named "working_memory" with type WorkingMemory
+ - Return type that is a subclass of StuffContent
+ """
+ functions: List[Callable[..., Any]] = []
+ module_name = module.__name__
+
+ # Find all functions in the module (not imported ones)
+ for _, obj in inspect.getmembers(module, inspect.isfunction):
+ # Skip functions imported from other modules
+ if obj.__module__ != module_name:
+ continue
+
+ if cls._is_eligible_function(obj):
+ functions.append(obj)
+
+ return functions
+
+ @classmethod
+ def _is_eligible_function(cls, func: Callable[..., Any]) -> bool:
+ """
+ Checks if a function matches the criteria:
+ - Exactly 1 parameter named "working_memory" with type WorkingMemory
+ - Return type that is a subclass of StuffContent
+ """
+ try:
+ # Get function signature
+ sig = inspect.signature(func)
+ params = list(sig.parameters.values())
+
+ # Check parameter count and name
+ if len(params) != 1:
+ return False
+
+ param = params[0]
+ if param.name != "working_memory":
+ return False
+
+ # Get type hints
+ type_hints = get_type_hints(func)
+
+ # Check parameter type
+ if "working_memory" not in type_hints:
+ return False
+
+ param_type = type_hints["working_memory"]
+ if param_type != WorkingMemory:
+ return False
+
+ # Check return type
+ if "return" not in type_hints:
+ return False
+
+ return_type = type_hints["return"]
+
+ # Check if return type is a subclass of StuffContent
+ try:
+ if inspect.isclass(return_type) and issubclass(return_type, StuffContent):
+ return True
+ # Handle generic types like ListContent[SomeType]
+ if hasattr(return_type, "__origin__"):
+ origin = getattr(return_type, "__origin__")
+ if inspect.isclass(origin) and issubclass(origin, StuffContent):
+ return True
+ except TypeError:
+ # Handle cases where issubclass fails on generic types
+ pass
+
+ return False
+
+ except Exception:
+ # If we can't analyze the function, skip it
+ return False
+
+ @classmethod
+ def _find_files_in_dir(cls, dir_path: str, pattern: str, is_recursive: bool) -> List[Path]:
+ """
+ Find files matching a pattern in a directory.
+
+ Args:
+ dir_path: Directory path to search in
+ pattern: File pattern to match (e.g. "*.py")
+ is_recursive: Whether to search recursively in subdirectories
+
+ Returns:
+ List of matching Path objects
+ """
+ path = Path(dir_path)
+ if is_recursive:
+ return list(path.rglob(pattern))
+ else:
+ return list(path.glob(pattern))
diff --git a/tests/test_pipelines/test_file_func_registry.py b/tests/test_pipelines/test_file_func_registry.py
index 42b043727..73a317db4 100644
--- a/tests/test_pipelines/test_file_func_registry.py
+++ b/tests/test_pipelines/test_file_func_registry.py
@@ -4,7 +4,6 @@ from pydantic import Field
from pipelex.core.memory.working_memory import WorkingMemory
from pipelex.core.stuffs.stuff_content import ListContent, StructuredContent
-from pipelex.tools.func_registry import func_registry
class FilePath(StructuredContent):
@@ -44,6 +43,3 @@ def read_file_content(working_memory: WorkingMemory) -> ListContent[CodebaseFile
)
return ListContent[CodebaseFileContent](items=codebase_files)
-
-
-func_registry.register_function(read_file_content, name="read_file_content")
diff --git a/tests/unit/pipelex/tools/test_func_registry_utils.py b/tests/unit/pipelex/tools/test_func_registry_utils.py
new file mode 100644
index 000000000..e93b84b47
--- /dev/null
+++ b/tests/unit/pipelex/tools/test_func_registry_utils.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python3
+"""Test script for FuncRegistryUtils"""
+
+import tempfile
+from pathlib import Path
+
+from pydantic import Field
+
+from pipelex.core.stuffs.stuff_content import StructuredContent
+from pipelex.tools.func_registry import func_registry
+from pipelex.tools.func_registry_utils import FuncRegistryUtils
+
+
+class FilePath(StructuredContent):
+ """A path to a file in the codebase."""
+
+ path: str = Field(description="Path to the file")
+
+
+class CodebaseFileContent(StructuredContent):
+ """Content of a codebase file."""
+
+ file_path: str = Field(description="Path to the codebase file")
+ file_content: str = Field(description="Content of the codebase file")
+
+
+def test_func_registry_utils():
+ """Test the FuncRegistryUtils implementation."""
+
+ # Create a temporary directory and file with the example function
+ with tempfile.TemporaryDirectory() as temp_dir:
+ test_file = Path(temp_dir) / "test_functions.py"
+
+ # Write the example function to the test file
+ test_file.write_text("""
+from typing import List
+
+from pydantic import Field
+
+from pipelex.core.memory.working_memory import WorkingMemory
+from pipelex.core.stuffs.stuff_content import ListContent, StructuredContent
+
+
+class FilePath(StructuredContent):
+ path: str = Field(description="Path to the file")
+
+
+class CodebaseFileContent(StructuredContent):
+ file_path: str = Field(description="Path to the codebase file")
+ file_content: str = Field(description="Content of the codebase file")
+
+
+def read_file_content(working_memory: WorkingMemory) -> ListContent[CodebaseFileContent]:
+ '''Read the content of related codebase files.'''
+
+ file_paths_list = working_memory.get_stuff_as_list("related_file_paths", item_type=FilePath)
+
+ codebase_files: List[CodebaseFileContent] = []
+ for file_path in file_paths_list.items:
+ try:
+ with open(file_path.path, "r", encoding="utf-8") as file:
+ content = file.read()
+ codebase_files.append(CodebaseFileContent(file_path=file_path.path, file_content=content))
+ except Exception as e:
+ codebase_files.append(
+ CodebaseFileContent(file_path=file_path.path, file_content=f"# File not found or unreadable: {file_path.path}\\n# Error: {str(e)}")
+ )
+
+ return ListContent[CodebaseFileContent](items=codebase_files)
+
+
+def invalid_function_wrong_param_name(other_param: WorkingMemory) -> StructuredContent:
+ '''This should not be registered - wrong parameter name.'''
+ pass
+
+
+def invalid_function_wrong_param_type(working_memory: str) -> StructuredContent:
+ '''This should not be registered - wrong parameter type.'''
+ pass
+
+
+def invalid_function_wrong_return_type(working_memory: WorkingMemory) -> str:
+ '''This should not be registered - wrong return type.'''
+ return "test"
+
+
+def invalid_function_too_many_params(working_memory: WorkingMemory, extra_param: str) -> StructuredContent:
+ '''This should not be registered - too many parameters.'''
+ pass
+""")
+
+ # Clear the registry to start fresh
+ func_registry.teardown()
+
+ # Test the registration
+ FuncRegistryUtils.register_funcs_in_folder(folder_path=temp_dir, is_recursive=False)
+
+ # Check that only the valid function was registered
+ assert func_registry.has_function("read_file_content"), "read_file_content should be registered"
+ assert not func_registry.has_function("invalid_function_wrong_param_name"), "invalid_function_wrong_param_name should not be registered"
+ assert not func_registry.has_function("invalid_function_wrong_param_type"), "invalid_function_wrong_param_type should not be registered"
+ assert not func_registry.has_function("invalid_function_wrong_return_type"), "invalid_function_wrong_return_type should not be registered"
+ assert not func_registry.has_function("invalid_function_too_many_params"), "invalid_function_too_many_params should not be registered"
+
+ # Verify we can get the function
+ registered_func = func_registry.get_function("read_file_content")
+ assert registered_func is not None, "Registered function should be retrievable"
+ assert registered_func.__name__ == "read_file_content", "Function name should match"
+
+ print("✅ All tests passed!")
+ print(f"✅ Successfully registered function: {registered_func.__name__}")
+
+
+if __name__ == "__main__":
+ test_func_registry_utils()