coreason-manifest 0.6.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.
@@ -0,0 +1,255 @@
1
+ # Copyright (c) 2025 CoReason, Inc.
2
+ #
3
+ # This software is proprietary and dual-licensed.
4
+ # Licensed under the Prosperity Public License 3.0 (the "License").
5
+ # A copy of the license is available at https://prosperitylicense.com/versions/3.0.0
6
+ # For details, see the LICENSE file.
7
+ # Commercial use beyond a 30-day trial requires a separate license.
8
+ #
9
+ # Source Code: https://github.com/CoReason-AI/coreason_maco
10
+
11
+ from enum import Enum
12
+ from typing import Annotated, Any, Dict, List, Literal, Optional, Union
13
+
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').")
31
+
32
+
33
+ class CouncilConfig(BaseModel):
34
+ """Configuration for 'Architectural Triangulation'.
35
+
36
+ Attributes:
37
+ strategy: The strategy for the council (e.g., 'consensus').
38
+ voters: List of agents or models that vote.
39
+ """
40
+
41
+ model_config = ConfigDict(extra="forbid")
42
+
43
+ strategy: str = Field(default="consensus", description="The strategy for the council, e.g., 'consensus'.")
44
+ voters: List[str] = Field(..., description="List of agents or models that vote.")
45
+
46
+
47
+ class VisualMetadata(BaseModel):
48
+ """Data explicitly for the UI.
49
+
50
+ Attributes:
51
+ label: The label to display for the node.
52
+ x_y_coordinates: The X and Y coordinates for the node on the canvas.
53
+ icon: The icon to represent the node.
54
+ animation_style: The animation style for the node.
55
+ """
56
+
57
+ model_config = ConfigDict(extra="forbid")
58
+
59
+ label: Optional[str] = Field(None, description="The label to display for the node.")
60
+ x_y_coordinates: Optional[List[float]] = Field(
61
+ None, description="The X and Y coordinates for the node on the canvas."
62
+ )
63
+ icon: Optional[str] = Field(None, description="The icon to represent the node.")
64
+ animation_style: Optional[str] = Field(None, description="The animation style for the node.")
65
+
66
+
67
+ class BaseNode(BaseModel):
68
+ """Base model for all node types.
69
+
70
+ Attributes:
71
+ id: Unique identifier for the node.
72
+ council_config: Optional configuration for architectural triangulation.
73
+ visual: Visual metadata for the UI.
74
+ """
75
+
76
+ model_config = ConfigDict(extra="forbid")
77
+
78
+ id: str = Field(..., description="Unique identifier for the node.")
79
+ council_config: Optional[CouncilConfig] = Field(
80
+ None, description="Optional configuration for architectural triangulation."
81
+ )
82
+ visual: Optional[VisualMetadata] = Field(None, description="Visual metadata for the UI.")
83
+
84
+
85
+ class AgentNode(BaseNode):
86
+ """A node that calls a specific atomic agent.
87
+
88
+ Attributes:
89
+ type: The type of the node (must be 'agent').
90
+ agent_name: The name of the atomic agent to call.
91
+ """
92
+
93
+ type: Literal["agent"] = Field("agent", description="Discriminator for AgentNode.")
94
+ agent_name: str = Field(..., description="The name of the atomic agent to call.")
95
+
96
+
97
+ class HumanNode(BaseNode):
98
+ """A node that pauses execution for user input/approval.
99
+
100
+ Attributes:
101
+ type: The type of the node (must be 'human').
102
+ timeout_seconds: Optional timeout in seconds for the user interaction.
103
+ """
104
+
105
+ type: Literal["human"] = Field("human", description="Discriminator for HumanNode.")
106
+ timeout_seconds: Optional[int] = Field(None, description="Optional timeout in seconds for the user interaction.")
107
+
108
+
109
+ class LogicNode(BaseNode):
110
+ """A node that executes pure Python logic.
111
+
112
+ Attributes:
113
+ type: The type of the node (must be 'logic').
114
+ code: The Python logic code to execute.
115
+ """
116
+
117
+ type: Literal["logic"] = Field("logic", description="Discriminator for LogicNode.")
118
+ code: str = Field(..., description="The Python logic code to execute.")
119
+
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
+
174
+ # Discriminated Union for polymorphism
175
+ Node = Annotated[
176
+ Union[AgentNode, HumanNode, LogicNode, RecipeNode, MapNode],
177
+ Field(discriminator="type", description="Polymorphic node definition."),
178
+ ]
179
+
180
+
181
+ class Edge(BaseModel):
182
+ """Represents a connection between two nodes.
183
+
184
+ Attributes:
185
+ source_node_id: The ID of the source node.
186
+ target_node_id: The ID of the target node.
187
+ condition: Optional Python expression for conditional branching.
188
+ """
189
+
190
+ model_config = ConfigDict(extra="forbid")
191
+
192
+ source_node_id: str = Field(..., description="The ID of the source node.")
193
+ target_node_id: str = Field(..., description="The ID of the target node.")
194
+ condition: Optional[str] = Field(None, description="Optional Python expression for conditional branching.")
195
+
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
+
239
+ class GraphTopology(BaseModel):
240
+ """The topology definition of the recipe.
241
+
242
+ Attributes:
243
+ nodes: List of nodes in the graph.
244
+ edges: List of edges connecting the nodes.
245
+ state_schema: Optional schema definition for the graph state.
246
+ """
247
+
248
+ model_config = ConfigDict(extra="forbid")
249
+
250
+ nodes: List[Node] = Field(..., description="List of nodes in the graph.")
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.")
253
+
254
+
255
+ Topology = GraphTopology
@@ -8,135 +8,46 @@
8
8
  #
9
9
  # Source Code: https://github.com/CoReason-AI/coreason_maco
10
10
 
11
- from typing import Annotated, Any, Dict, List, Literal, Optional, Union
11
+ from typing import Any, Dict, Literal, Optional
12
12
 
13
13
  from pydantic import BaseModel, ConfigDict, Field
14
14
 
15
- from .models import VersionStr
15
+ from .definitions.agent import VersionStr
16
+ from .definitions.topology import GraphTopology
16
17
 
17
18
 
18
- class CouncilConfig(BaseModel):
19
- """Configuration for 'Architectural Triangulation'.
19
+ class RecipeInterface(BaseModel):
20
+ """Defines the input/output contract for a Recipe.
20
21
 
21
22
  Attributes:
22
- strategy: The strategy for the council (e.g., 'consensus').
23
- voters: List of agents or models that vote.
23
+ inputs: JSON Schema defining valid entry arguments.
24
+ outputs: JSON Schema defining the guaranteed structure of the final result.
24
25
  """
25
26
 
26
27
  model_config = ConfigDict(extra="forbid")
27
28
 
28
- strategy: str = Field(default="consensus", description="The strategy for the council, e.g., 'consensus'.")
29
- voters: List[str] = Field(..., description="List of agents or models that vote.")
30
-
31
-
32
- class VisualMetadata(BaseModel):
33
- """Data explicitly for the UI.
34
-
35
- Attributes:
36
- label: The label to display for the node.
37
- x_y_coordinates: The X and Y coordinates for the node on the canvas.
38
- icon: The icon to represent the node.
39
- animation_style: The animation style for the node.
40
- """
41
-
42
- model_config = ConfigDict(extra="forbid")
43
-
44
- label: Optional[str] = Field(None, description="The label to display for the node.")
45
- x_y_coordinates: Optional[List[float]] = Field(
46
- None, description="The X and Y coordinates for the node on the canvas."
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."
47
32
  )
48
- icon: Optional[str] = Field(None, description="The icon to represent the node.")
49
- animation_style: Optional[str] = Field(None, description="The animation style for the node.")
50
33
 
51
34
 
52
- class BaseNode(BaseModel):
53
- """Base model for all node types.
35
+ class StateDefinition(BaseModel):
36
+ """Defines the internal state (memory) of the Recipe.
54
37
 
55
38
  Attributes:
56
- id: Unique identifier for the node.
57
- council_config: Optional configuration for architectural triangulation.
58
- visual: Visual metadata for the UI.
39
+ schema: JSON Schema of the keys available in the shared memory.
40
+ persistence: Configuration for state durability.
59
41
  """
60
42
 
61
43
  model_config = ConfigDict(extra="forbid")
62
44
 
63
- id: str = Field(..., description="Unique identifier for the node.")
64
- council_config: Optional[CouncilConfig] = Field(
65
- None, description="Optional configuration for architectural triangulation."
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."
66
50
  )
67
- visual: Optional[VisualMetadata] = Field(None, description="Visual metadata for the UI.")
68
-
69
-
70
- class AgentNode(BaseNode):
71
- """A node that calls a specific atomic agent.
72
-
73
- Attributes:
74
- type: The type of the node (must be 'agent').
75
- agent_name: The name of the atomic agent to call.
76
- """
77
-
78
- type: Literal["agent"] = Field("agent", description="Discriminator for AgentNode.")
79
- agent_name: str = Field(..., description="The name of the atomic agent to call.")
80
-
81
-
82
- class HumanNode(BaseNode):
83
- """A node that pauses execution for user input/approval.
84
-
85
- Attributes:
86
- type: The type of the node (must be 'human').
87
- timeout_seconds: Optional timeout in seconds for the user interaction.
88
- """
89
-
90
- type: Literal["human"] = Field("human", description="Discriminator for HumanNode.")
91
- timeout_seconds: Optional[int] = Field(None, description="Optional timeout in seconds for the user interaction.")
92
-
93
-
94
- class LogicNode(BaseNode):
95
- """A node that executes pure Python logic.
96
-
97
- Attributes:
98
- type: The type of the node (must be 'logic').
99
- code: The Python logic code to execute.
100
- """
101
-
102
- type: Literal["logic"] = Field("logic", description="Discriminator for LogicNode.")
103
- code: str = Field(..., description="The Python logic code to execute.")
104
-
105
-
106
- # Discriminated Union for polymorphism
107
- Node = Annotated[
108
- Union[AgentNode, HumanNode, LogicNode], Field(discriminator="type", description="Polymorphic node definition.")
109
- ]
110
-
111
-
112
- class Edge(BaseModel):
113
- """Represents a connection between two nodes.
114
-
115
- Attributes:
116
- source_node_id: The ID of the source node.
117
- target_node_id: The ID of the target node.
118
- condition: Optional Python expression for conditional branching.
119
- """
120
-
121
- model_config = ConfigDict(extra="forbid")
122
-
123
- source_node_id: str = Field(..., description="The ID of the source node.")
124
- target_node_id: str = Field(..., description="The ID of the target node.")
125
- condition: Optional[str] = Field(None, description="Optional Python expression for conditional branching.")
126
-
127
-
128
- class GraphTopology(BaseModel):
129
- """The topology definition of the recipe.
130
-
131
- Attributes:
132
- nodes: List of nodes in the graph.
133
- edges: List of edges connecting the nodes.
134
- """
135
-
136
- model_config = ConfigDict(extra="forbid")
137
-
138
- nodes: List[Node] = Field(..., description="List of nodes in the graph.")
139
- edges: List[Edge] = Field(..., description="List of edges connecting the nodes.")
140
51
 
141
52
 
142
53
  class RecipeManifest(BaseModel):
@@ -147,8 +58,10 @@ class RecipeManifest(BaseModel):
147
58
  version: Version of the recipe.
148
59
  name: Human-readable name of the recipe.
149
60
  description: Detailed description of the recipe.
150
- inputs: Schema defining global variables this recipe accepts.
151
- 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.
152
65
  """
153
66
 
154
67
  model_config = ConfigDict(extra="forbid")
@@ -157,5 +70,7 @@ class RecipeManifest(BaseModel):
157
70
  version: VersionStr = Field(..., description="Version of the recipe.")
158
71
  name: str = Field(..., description="Human-readable name of the recipe.")
159
72
  description: Optional[str] = Field(None, description="Detailed description of the recipe.")
160
- inputs: Dict[str, Any] = Field(..., description="Schema defining global variables this recipe accepts.")
161
- 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.")