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.

ok

thomashebrardc4de42b6f9cf
diff --git a/pipelex/client/api_serializer.py b/pipelex/client/api_serializer.py
index 580a86351..72fb88518 100644
--- a/pipelex/client/api_serializer.py
+++ b/pipelex/client/api_serializer.py
@@ -6,6 +6,7 @@ from typing import Any, cast
from pipelex.client.protocol import PipelineInputs
from pipelex.core.memory.working_memory import WorkingMemory
+from pipelex.core.stuffs.stuff import DictStuff
class ApiSerializer:
@@ -34,10 +35,10 @@ class ApiSerializer:
content_dict = stuff.content.model_dump(serialize_as_any=True)
clean_content = cls._clean_and_format_content(content_dict)
- pipeline_inputs[stuff_name] = {
- "concept": stuff.concept.code,
- "content": clean_content,
- }
+ pipeline_inputs[stuff_name] = DictStuff(
+ concept=stuff.concept.code,
+ content=clean_content,
+ )
return pipeline_inputs
diff --git a/pipelex/client/pipeline_response_factory.py b/pipelex/client/pipeline_response_factory.py
index fc0e32b9e..7215184cf 100644
--- a/pipelex/client/pipeline_response_factory.py
+++ b/pipelex/client/pipeline_response_factory.py
@@ -26,8 +26,6 @@ class PipelineResponseFactory:
# Convert each Stuff → DictStuff by dumping only the content
for stuff_name, stuff in working_memory.root.items():
dict_stuff = DictStuff(
- stuff_code=stuff.stuff_code,
- stuff_name=stuff.stuff_name,
concept=stuff.concept.concept_string,
content=stuff.content.model_dump(serialize_as_any=True),
)
diff --git a/pipelex/client/protocol.py b/pipelex/client/protocol.py
index 88fe1233b..59784c953 100644
--- a/pipelex/client/protocol.py
+++ b/pipelex/client/protocol.py
@@ -26,15 +26,13 @@ from pipelex.types import StrEnum
# - 2.4: {"concept": str, "content": Sequence[StuffContent]}
# - 2.5: {"concept": str, "content": dict[str, Any]}
# - 2.6: {"concept": str, "content": Sequence[dict[str, Any]]}
-# - 2.7: DictStuff {"stuff_code": str, "stuff_name": str | None, "concept": str, "content": Any}
-ReducedDictStuff = dict[str, Any] # Only contains {"concept": str, "content": Any}
+# - 2.7: DictStuff {"concept": str, "content": Any}
StuffContentOrData = (
str # Case 1.1
| Sequence[str] # Case 1.2
| StuffContent # Case 1.3 (also covers Case 1.5 as ListContent is a StuffContent)
| Sequence[StuffContent] # Case 1.4 (covariant - accepts list[TextContent], etc.)
- | ReducedDictStuff # Case 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
- | DictStuff # Case 2.7
+ | dict[str, Any] # Case 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7 (both plain dicts and DictStuff format)
)
PipelineInputs = dict[str, StuffContentOrData] # Can include both dict and StuffContent
diff --git a/pipelex/core/stuffs/stuff.py b/pipelex/core/stuffs/stuff.py
index 03dfa2622..9cadb8b5a 100644
--- a/pipelex/core/stuffs/stuff.py
+++ b/pipelex/core/stuffs/stuff.py
@@ -201,8 +201,5 @@ class DictStuff(CustomBaseModel):
"""
model_config = ConfigDict(extra="forbid", strict=True)
-
- stuff_code: str
- stuff_name: str | None = None
concept: str
content: dict[str, Any]
diff --git a/pipelex/core/stuffs/stuff_factory.py b/pipelex/core/stuffs/stuff_factory.py
index 472c0e5f7..0834619f4 100644
--- a/pipelex/core/stuffs/stuff_factory.py
+++ b/pipelex/core/stuffs/stuff_factory.py
@@ -338,21 +338,8 @@ class StuffFactory:
)
raise StuffFactoryError(msg)
- dict_stuff_code = stuff_content_or_data["stuff_code"]
- dict_stuff_name_in_dict = stuff_content_or_data.get("stuff_name")
- concept_string = stuff_content_or_data["concept"]
- content = stuff_content_or_data["content"]
-
- # Validate: if both dict_stuff_name and name argument are provided, they must match
- if dict_stuff_name_in_dict is not None and name is not None and dict_stuff_name_in_dict != name:
- msg = (
- f"Trying to create a Stuff from a DictStuff but the stuff_name in the dict ('{dict_stuff_name_in_dict}') "
- f"does not match the name argument ('{name}'). They must be equal if both are provided."
- )
- raise StuffFactoryError(msg)
-
- # Use dict's stuff_name if present, otherwise fallback to name argument
- dict_stuff_name = dict_stuff_name_in_dict if dict_stuff_name_in_dict is not None else name
+ concept_string = stuff_content_or_data.concept
+ content = stuff_content_or_data.content
# Get the concept from the library
try:
@@ -373,8 +360,7 @@ class StuffFactory:
raise StuffFactoryError(msg)
return cls.make_stuff(
- name=dict_stuff_name,
- code=dict_stuff_code,
+ name=name,
concept=concept,
content=the_class.model_validate(obj=content),
)
@@ -385,8 +371,7 @@ class StuffFactory:
value=content,
)
return cls.make_stuff(
- name=dict_stuff_name,
- code=dict_stuff_code,
+ name=name,
concept=concept,
content=stuff_content,
)