coreason-manifest 0.7.0__py3-none-any.whl → 0.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,9 +8,26 @@
8
8
  #
9
9
  # Source Code: https://github.com/CoReason-AI/coreason_maco
10
10
 
11
- from typing import Annotated, List, Literal, Optional, Union
11
+ from enum import Enum
12
+ from typing import Annotated, Any, Dict, List, Literal, Optional, Union
12
13
 
13
- from pydantic import BaseModel, ConfigDict, Field
14
+ from pydantic import BaseModel, ConfigDict, Field, StringConstraints
15
+
16
+
17
+ class StateSchema(BaseModel):
18
+ """Defines the structure and persistence of the graph state.
19
+
20
+ Attributes:
21
+ data_schema: A JSON Schema or Pydantic definition describing the state structure.
22
+ persistence: Configuration for how state is checkpointed.
23
+ """
24
+
25
+ model_config = ConfigDict(extra="forbid")
26
+
27
+ data_schema: Dict[str, Any] = Field(
28
+ ..., description="A JSON Schema or Pydantic definition describing the state structure."
29
+ )
30
+ persistence: str = Field(..., description="Configuration for how state is checkpointed (e.g., 'memory', 'redis').")
14
31
 
15
32
 
16
33
  class CouncilConfig(BaseModel):
@@ -101,9 +118,63 @@ class LogicNode(BaseNode):
101
118
  code: str = Field(..., description="The Python logic code to execute.")
102
119
 
103
120
 
121
+ class DataMappingStrategy(str, Enum):
122
+ """Strategy for mapping data."""
123
+
124
+ DIRECT = "direct"
125
+ JSONPATH = "jsonpath"
126
+ LITERAL = "literal"
127
+
128
+
129
+ class DataMapping(BaseModel):
130
+ """Defines how to transform data between parent and child."""
131
+
132
+ model_config = ConfigDict(extra="forbid")
133
+
134
+ source: str = Field(..., description="The path/key source.")
135
+ strategy: DataMappingStrategy = Field(default=DataMappingStrategy.DIRECT, description="The mapping strategy.")
136
+
137
+
138
+ class RecipeNode(BaseNode):
139
+ """A node that executes another Recipe as a sub-graph.
140
+
141
+ Attributes:
142
+ type: The type of the node (must be 'recipe').
143
+ recipe_id: The ID of the recipe to execute.
144
+ input_mapping: How parent state maps to child inputs (parent_key -> child_key).
145
+ output_mapping: How child result maps back to parent state (child_key -> parent_key).
146
+ """
147
+
148
+ type: Literal["recipe"] = Field("recipe", description="Discriminator for RecipeNode.")
149
+ recipe_id: str = Field(..., description="The ID of the recipe to execute.")
150
+ input_mapping: Dict[str, Union[str, DataMapping]] = Field(
151
+ ..., description="Mapping of parent state keys to child input keys."
152
+ )
153
+ output_mapping: Dict[str, Union[str, DataMapping]] = Field(
154
+ ..., description="Mapping of child output keys to parent state keys."
155
+ )
156
+
157
+
158
+ class MapNode(BaseNode):
159
+ """A node that spawns multiple parallel executions of a sub-branch.
160
+
161
+ Attributes:
162
+ type: The type of the node (must be 'map').
163
+ items_path: Dot-notation path to the list in the state.
164
+ processor_node_id: The node (or subgraph) to run for each item.
165
+ concurrency_limit: Max parallel executions.
166
+ """
167
+
168
+ type: Literal["map"] = Field("map", description="Discriminator for MapNode.")
169
+ items_path: str = Field(..., description="Dot-notation path to the list in the state.")
170
+ processor_node_id: str = Field(..., description="The node (or subgraph) to run for each item.")
171
+ concurrency_limit: int = Field(..., description="Max parallel executions.")
172
+
173
+
104
174
  # Discriminated Union for polymorphism
105
175
  Node = Annotated[
106
- Union[AgentNode, HumanNode, LogicNode], Field(discriminator="type", description="Polymorphic node definition.")
176
+ Union[AgentNode, HumanNode, LogicNode, RecipeNode, MapNode],
177
+ Field(discriminator="type", description="Polymorphic node definition."),
107
178
  ]
108
179
 
109
180
 
@@ -123,18 +194,62 @@ class Edge(BaseModel):
123
194
  condition: Optional[str] = Field(None, description="Optional Python expression for conditional branching.")
124
195
 
125
196
 
197
+ RouterRef = Annotated[
198
+ str,
199
+ StringConstraints(
200
+ pattern=r"^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z_][a-zA-Z0-9_]*)*$",
201
+ strip_whitespace=True,
202
+ ),
203
+ ]
204
+
205
+
206
+ class RouterExpression(BaseModel):
207
+ """A structured expression for routing logic (e.g., CEL or JSONLogic)."""
208
+
209
+ model_config = ConfigDict(extra="forbid")
210
+
211
+ operator: str = Field(..., description="The operator (e.g., 'eq', 'gt').")
212
+ args: List[Any] = Field(..., description="Arguments for the expression.")
213
+
214
+
215
+ RouterDefinition = Annotated[
216
+ Union[RouterRef, RouterExpression],
217
+ Field(description="A reference to a python function or a logic expression."),
218
+ ]
219
+
220
+
221
+ class ConditionalEdge(BaseModel):
222
+ """Represents a dynamic routing connection from one node to multiple potential targets.
223
+
224
+ Attributes:
225
+ source_node_id: The ID of the source node.
226
+ router_logic: A reference to a python function or a logic expression that returns the next node ID.
227
+ mapping: A dictionary mapping the router's output (e.g., "approve", "reject") to target Node IDs.
228
+ """
229
+
230
+ model_config = ConfigDict(extra="forbid")
231
+
232
+ source_node_id: str = Field(..., description="The ID of the source node.")
233
+ router_logic: RouterDefinition = Field(
234
+ ..., description="A reference to a python function or logic expression that determines the path."
235
+ )
236
+ mapping: Dict[str, str] = Field(..., description="Map of router output values to target node IDs.")
237
+
238
+
126
239
  class GraphTopology(BaseModel):
127
240
  """The topology definition of the recipe.
128
241
 
129
242
  Attributes:
130
243
  nodes: List of nodes in the graph.
131
244
  edges: List of edges connecting the nodes.
245
+ state_schema: Optional schema definition for the graph state.
132
246
  """
133
247
 
134
248
  model_config = ConfigDict(extra="forbid")
135
249
 
136
250
  nodes: List[Node] = Field(..., description="List of nodes in the graph.")
137
- edges: List[Edge] = Field(..., description="List of edges connecting the nodes.")
251
+ edges: List[Union[Edge, ConditionalEdge]] = Field(..., description="List of edges connecting the nodes.")
252
+ state_schema: Optional[StateSchema] = Field(None, description="Schema definition for the graph state.")
138
253
 
139
254
 
140
255
  Topology = GraphTopology
@@ -8,7 +8,7 @@
8
8
  #
9
9
  # Source Code: https://github.com/CoReason-AI/coreason_maco
10
10
 
11
- from typing import Any, Dict, Optional
11
+ from typing import Any, Dict, Literal, Optional
12
12
 
13
13
  from pydantic import BaseModel, ConfigDict, Field
14
14
 
@@ -16,6 +16,40 @@ from .definitions.agent import VersionStr
16
16
  from .definitions.topology import GraphTopology
17
17
 
18
18
 
19
+ class RecipeInterface(BaseModel):
20
+ """Defines the input/output contract for a Recipe.
21
+
22
+ Attributes:
23
+ inputs: JSON Schema defining valid entry arguments.
24
+ outputs: JSON Schema defining the guaranteed structure of the final result.
25
+ """
26
+
27
+ model_config = ConfigDict(extra="forbid")
28
+
29
+ inputs: Dict[str, Any] = Field(..., description="JSON Schema defining valid entry arguments.")
30
+ outputs: Dict[str, Any] = Field(
31
+ ..., description="JSON Schema defining the guaranteed structure of the final result."
32
+ )
33
+
34
+
35
+ class StateDefinition(BaseModel):
36
+ """Defines the internal state (memory) of the Recipe.
37
+
38
+ Attributes:
39
+ schema: JSON Schema of the keys available in the shared memory.
40
+ persistence: Configuration for state durability.
41
+ """
42
+
43
+ model_config = ConfigDict(extra="forbid")
44
+
45
+ schema_: Dict[str, Any] = Field(
46
+ ..., alias="schema", description="JSON Schema of the keys available in the shared memory."
47
+ )
48
+ persistence: Literal["ephemeral", "persistent"] = Field(
49
+ default="ephemeral", description="Configuration for state durability."
50
+ )
51
+
52
+
19
53
  class RecipeManifest(BaseModel):
20
54
  """The executable specification for the MACO engine.
21
55
 
@@ -24,8 +58,10 @@ class RecipeManifest(BaseModel):
24
58
  version: Version of the recipe.
25
59
  name: Human-readable name of the recipe.
26
60
  description: Detailed description of the recipe.
27
- inputs: Schema defining global variables this recipe accepts.
28
- graph: The topology definition of the workflow.
61
+ interface: Defines the input/output contract for the Recipe.
62
+ state: Defines the internal state (memory) of the Recipe.
63
+ parameters: Dictionary of build-time constants.
64
+ topology: The topology definition of the workflow.
29
65
  """
30
66
 
31
67
  model_config = ConfigDict(extra="forbid")
@@ -34,5 +70,7 @@ class RecipeManifest(BaseModel):
34
70
  version: VersionStr = Field(..., description="Version of the recipe.")
35
71
  name: str = Field(..., description="Human-readable name of the recipe.")
36
72
  description: Optional[str] = Field(None, description="Detailed description of the recipe.")
37
- inputs: Dict[str, Any] = Field(..., description="Schema defining global variables this recipe accepts.")
38
- graph: GraphTopology = Field(..., description="The topology definition of the workflow.")
73
+ interface: RecipeInterface = Field(..., description="Defines the input/output contract for the Recipe.")
74
+ state: StateDefinition = Field(..., description="Defines the internal state (memory) of the Recipe.")
75
+ parameters: Dict[str, Any] = Field(..., description="Dictionary of build-time constants.")
76
+ topology: GraphTopology = Field(..., description="The topology definition of the workflow.")