codecraftai-agent-kit 1.3.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.
Files changed (230) hide show
  1. ccai/agentkit/__init__.py +304 -0
  2. ccai/agentkit/addressresolver.py +177 -0
  3. ccai/agentkit/agent.py +2945 -0
  4. ccai/agentkit/agentaddress.py +187 -0
  5. ccai/agentkit/agentconfiguration.py +581 -0
  6. ccai/agentkit/agentidentity.py +152 -0
  7. ccai/agentkit/agentregistry.py +221 -0
  8. ccai/agentkit/agentstatemachine.py +134 -0
  9. ccai/agentkit/alternateproviderstrategy.py +36 -0
  10. ccai/agentkit/approvalgate.py +238 -0
  11. ccai/agentkit/approvalrequest.py +250 -0
  12. ccai/agentkit/asyncagent.py +187 -0
  13. ccai/agentkit/breakpoint.py +150 -0
  14. ccai/agentkit/builtinagentmetrics.py +114 -0
  15. ccai/agentkit/builtins/__init__.py +11 -0
  16. ccai/agentkit/builtins/filereadtool.py +90 -0
  17. ccai/agentkit/builtins/filewritetool.py +93 -0
  18. ccai/agentkit/builtins/httprequesttool.py +169 -0
  19. ccai/agentkit/builtins/shellcommandtool.py +190 -0
  20. ccai/agentkit/cachedresultstrategy.py +43 -0
  21. ccai/agentkit/checkpointmanager.py +219 -0
  22. ccai/agentkit/circuitbreaker.py +230 -0
  23. ccai/agentkit/circuitbreakerconfiguration.py +158 -0
  24. ccai/agentkit/circuitbreakerevent.py +158 -0
  25. ccai/agentkit/circuitbreakerhealthcheck.py +32 -0
  26. ccai/agentkit/circuitbreakerregistry.py +116 -0
  27. ccai/agentkit/circuitbreakerstate.py +44 -0
  28. ccai/agentkit/clearcacheaction.py +46 -0
  29. ccai/agentkit/concurrencybridge.py +143 -0
  30. ccai/agentkit/concurrencymodel.py +19 -0
  31. ccai/agentkit/conditionevaluator.py +594 -0
  32. ccai/agentkit/configurationchangeevent.py +179 -0
  33. ccai/agentkit/configurationerrors.py +152 -0
  34. ccai/agentkit/configurationlayer.py +160 -0
  35. ccai/agentkit/configurationlayersource.py +46 -0
  36. ccai/agentkit/configurationmanager.py +680 -0
  37. ccai/agentkit/configurationschema.py +224 -0
  38. ccai/agentkit/configurationschemafield.py +217 -0
  39. ccai/agentkit/configurationserializer.py +163 -0
  40. ccai/agentkit/configurationvalidationresult.py +118 -0
  41. ccai/agentkit/contextsummarizer.py +170 -0
  42. ccai/agentkit/contextwindow.py +264 -0
  43. ccai/agentkit/contextwindowstrategy.py +57 -0
  44. ccai/agentkit/correlationcontext.py +156 -0
  45. ccai/agentkit/costestimate.py +139 -0
  46. ccai/agentkit/costtracker.py +121 -0
  47. ccai/agentkit/deadletterentry.py +134 -0
  48. ccai/agentkit/deadletterquery.py +119 -0
  49. ccai/agentkit/deadletterqueue.py +123 -0
  50. ccai/agentkit/deadletterstore.py +86 -0
  51. ccai/agentkit/debuginspector.py +211 -0
  52. ccai/agentkit/debugsession.py +223 -0
  53. ccai/agentkit/defaultvaluestrategy.py +43 -0
  54. ccai/agentkit/degradationchangeevent.py +120 -0
  55. ccai/agentkit/degradationlevel.py +44 -0
  56. ccai/agentkit/degradationmanager.py +212 -0
  57. ccai/agentkit/degradationpolicy.py +130 -0
  58. ccai/agentkit/degradationstrategy.py +66 -0
  59. ccai/agentkit/embeddingprovider.py +106 -0
  60. ccai/agentkit/errors.py +95 -0
  61. ccai/agentkit/executionrecord.py +213 -0
  62. ccai/agentkit/executionrecorder.py +180 -0
  63. ccai/agentkit/executionrecording.py +230 -0
  64. ccai/agentkit/executionreplayer.py +187 -0
  65. ccai/agentkit/expirationpolicy.py +116 -0
  66. ccai/agentkit/fallbackchain.py +82 -0
  67. ccai/agentkit/featureflag.py +154 -0
  68. ccai/agentkit/featureflagevaluator.py +109 -0
  69. ccai/agentkit/featureflagregistry.py +258 -0
  70. ccai/agentkit/filedeadletterstore.py +112 -0
  71. ccai/agentkit/filememorystore.py +291 -0
  72. ccai/agentkit/healthcheck.py +46 -0
  73. ccai/agentkit/healthcheckregistry.py +51 -0
  74. ccai/agentkit/healthmonitor.py +258 -0
  75. ccai/agentkit/healthstatus.py +105 -0
  76. ccai/agentkit/hotreloadmonitor.py +214 -0
  77. ccai/agentkit/hotreloadpolicy.py +160 -0
  78. ccai/agentkit/inmemorydeadletterstore.py +61 -0
  79. ccai/agentkit/inmemorystore.py +173 -0
  80. ccai/agentkit/jsonmessageserializer.py +89 -0
  81. ccai/agentkit/jsonoutputparser.py +50 -0
  82. ccai/agentkit/lifecyclestate.py +22 -0
  83. ccai/agentkit/llmconversation.py +153 -0
  84. ccai/agentkit/llmerrors.py +193 -0
  85. ccai/agentkit/llmmessage.py +158 -0
  86. ccai/agentkit/llmprovider.py +158 -0
  87. ccai/agentkit/llmproviderregistry.py +200 -0
  88. ccai/agentkit/llmresponse.py +190 -0
  89. ccai/agentkit/llmstreamchunk.py +65 -0
  90. ccai/agentkit/llmstreamhandler.py +48 -0
  91. ccai/agentkit/llmtoolbridge.py +154 -0
  92. ccai/agentkit/logexporter.py +316 -0
  93. ccai/agentkit/logformatter.py +169 -0
  94. ccai/agentkit/memoryconfiguration.py +243 -0
  95. ccai/agentkit/memoryentry.py +254 -0
  96. ccai/agentkit/memoryerrors.py +135 -0
  97. ccai/agentkit/memoryindex.py +213 -0
  98. ccai/agentkit/memoryquery.py +248 -0
  99. ccai/agentkit/memoryqueryresult.py +86 -0
  100. ccai/agentkit/memoryscope.py +54 -0
  101. ccai/agentkit/memorystore.py +260 -0
  102. ccai/agentkit/memorystorehealthcheck.py +33 -0
  103. ccai/agentkit/memorystoreregistry.py +106 -0
  104. ccai/agentkit/message.py +310 -0
  105. ccai/agentkit/messageenvelope.py +144 -0
  106. ccai/agentkit/messagepattern.py +50 -0
  107. ccai/agentkit/messagerouter.py +290 -0
  108. ccai/agentkit/messageserializer.py +106 -0
  109. ccai/agentkit/messageserializerregistry.py +163 -0
  110. ccai/agentkit/messagingconfiguration.py +397 -0
  111. ccai/agentkit/messagingerrors.py +338 -0
  112. ccai/agentkit/metricdefinition.py +164 -0
  113. ccai/agentkit/metricmeasurement.py +178 -0
  114. ccai/agentkit/metricscollector.py +258 -0
  115. ccai/agentkit/metricsexporter.py +303 -0
  116. ccai/agentkit/metricsregistry.py +130 -0
  117. ccai/agentkit/metricssnapshot.py +155 -0
  118. ccai/agentkit/metrictype.py +51 -0
  119. ccai/agentkit/msgpackmessageserializer.py +97 -0
  120. ccai/agentkit/observabilityconfiguration.py +546 -0
  121. ccai/agentkit/observabilityerror.py +67 -0
  122. ccai/agentkit/observabilitypipeline.py +252 -0
  123. ccai/agentkit/outputparser.py +82 -0
  124. ccai/agentkit/outputschema.py +142 -0
  125. ccai/agentkit/parallelbranch.py +87 -0
  126. ccai/agentkit/platform/__init__.py +43 -0
  127. ccai/agentkit/platform/adapters/__init__.py +18 -0
  128. ccai/agentkit/platform/adapters/awsplatformadapter.py +1272 -0
  129. ccai/agentkit/platform/adapters/azureplatformadapter.py +1227 -0
  130. ccai/agentkit/platform/adapters/gcpplatformadapter.py +1257 -0
  131. ccai/agentkit/platform/adapters/localplatformadapter.py +956 -0
  132. ccai/agentkit/platform/adapters/platformadapter.py +139 -0
  133. ccai/agentkit/platform/deployment/__init__.py +15 -0
  134. ccai/agentkit/platform/deployment/deploymentdescriptor.py +234 -0
  135. ccai/agentkit/platform/deployment/deploymentdescriptorparser.py +178 -0
  136. ccai/agentkit/platform/deployment/deploymentdescriptorprinter.py +97 -0
  137. ccai/agentkit/platform/errors.py +224 -0
  138. ccai/agentkit/platform/platformconfiguration.py +412 -0
  139. ccai/agentkit/platform/platformdetector.py +125 -0
  140. ccai/agentkit/platform/platformruntime.py +331 -0
  141. ccai/agentkit/platform/platformserviceregistry.py +149 -0
  142. ccai/agentkit/platform/platformtype.py +60 -0
  143. ccai/agentkit/platform/services/__init__.py +19 -0
  144. ccai/agentkit/platform/services/computeservice.py +112 -0
  145. ccai/agentkit/platform/services/invocationresult.py +173 -0
  146. ccai/agentkit/platform/services/messagingservice.py +135 -0
  147. ccai/agentkit/platform/services/platformservice.py +111 -0
  148. ccai/agentkit/platform/services/queuemessage.py +193 -0
  149. ccai/agentkit/platform/services/storageobject.py +195 -0
  150. ccai/agentkit/platform/services/storageservice.py +159 -0
  151. ccai/agentkit/pluginconfiguration.py +241 -0
  152. ccai/agentkit/plugindependency.py +129 -0
  153. ccai/agentkit/plugindescriptor.py +225 -0
  154. ccai/agentkit/pluginlifecyclehook.py +41 -0
  155. ccai/agentkit/pluginmanager.py +360 -0
  156. ccai/agentkit/pluginstatus.py +47 -0
  157. ccai/agentkit/pooledagent.py +116 -0
  158. ccai/agentkit/prompttemplate.py +221 -0
  159. ccai/agentkit/prompttemplateregistry.py +145 -0
  160. ccai/agentkit/protobufmessageserializer.py +144 -0
  161. ccai/agentkit/pubsubbroker.py +311 -0
  162. ccai/agentkit/py.typed +0 -0
  163. ccai/agentkit/reconnecttransportaction.py +47 -0
  164. ccai/agentkit/regexoutputparser.py +68 -0
  165. ccai/agentkit/requestresponsehandler.py +274 -0
  166. ccai/agentkit/resetcircuitbreakeraction.py +48 -0
  167. ccai/agentkit/resilienceconfiguration.py +191 -0
  168. ccai/agentkit/resilienceerrors.py +103 -0
  169. ccai/agentkit/resiliencepipeline.py +201 -0
  170. ccai/agentkit/retryattempt.py +158 -0
  171. ccai/agentkit/retryexecutor.py +157 -0
  172. ccai/agentkit/retrypolicy.py +195 -0
  173. ccai/agentkit/retryresult.py +186 -0
  174. ccai/agentkit/selfhealingaction.py +42 -0
  175. ccai/agentkit/selfhealingpolicy.py +67 -0
  176. ccai/agentkit/selfhealingresult.py +130 -0
  177. ccai/agentkit/stepexecutionstatus.py +52 -0
  178. ccai/agentkit/stepresult.py +198 -0
  179. ccai/agentkit/steps/__init__.py +9 -0
  180. ccai/agentkit/steps/agentstep.py +247 -0
  181. ccai/agentkit/steps/approvalstep.py +276 -0
  182. ccai/agentkit/steps/llmstep.py +403 -0
  183. ccai/agentkit/steps/subworkflowstep.py +270 -0
  184. ccai/agentkit/steps/toolstep.py +265 -0
  185. ccai/agentkit/structuredlogentry.py +222 -0
  186. ccai/agentkit/structuredlogger.py +189 -0
  187. ccai/agentkit/subscription.py +141 -0
  188. ccai/agentkit/threadedagent.py +94 -0
  189. ccai/agentkit/tokenusage.py +136 -0
  190. ccai/agentkit/tool.py +203 -0
  191. ccai/agentkit/toolchain.py +268 -0
  192. ccai/agentkit/toolchainexecutor.py +134 -0
  193. ccai/agentkit/toolchainresult.py +166 -0
  194. ccai/agentkit/tooldescriptor.py +203 -0
  195. ccai/agentkit/toolerrors.py +160 -0
  196. ccai/agentkit/toolexecutor.py +168 -0
  197. ccai/agentkit/toolfactory.py +60 -0
  198. ccai/agentkit/toolregistry.py +184 -0
  199. ccai/agentkit/toolresult.py +142 -0
  200. ccai/agentkit/toolschema.py +197 -0
  201. ccai/agentkit/tracecontext.py +294 -0
  202. ccai/agentkit/traceevent.py +166 -0
  203. ccai/agentkit/traceexporter.py +305 -0
  204. ccai/agentkit/tracer.py +234 -0
  205. ccai/agentkit/tracespan.py +349 -0
  206. ccai/agentkit/transitionrecord.py +84 -0
  207. ccai/agentkit/transport.py +334 -0
  208. ccai/agentkit/transportconfiguration.py +436 -0
  209. ccai/agentkit/transporthealthcheck.py +36 -0
  210. ccai/agentkit/transportregistry.py +224 -0
  211. ccai/agentkit/transports/__init__.py +28 -0
  212. ccai/agentkit/transports/grpctransport.py +410 -0
  213. ccai/agentkit/transports/httptransport.py +423 -0
  214. ccai/agentkit/transports/messagequeuetransport.py +489 -0
  215. ccai/agentkit/transports/websockettransport.py +473 -0
  216. ccai/agentkit/workflowcheckpoint.py +208 -0
  217. ccai/agentkit/workflowconfiguration.py +295 -0
  218. ccai/agentkit/workflowcontext.py +249 -0
  219. ccai/agentkit/workflowdefinition.py +790 -0
  220. ccai/agentkit/workflowedge.py +128 -0
  221. ccai/agentkit/workflowerrors.py +295 -0
  222. ccai/agentkit/workflowexecutionstatus.py +48 -0
  223. ccai/agentkit/workflowexecutor.py +1121 -0
  224. ccai/agentkit/workflowregistry.py +185 -0
  225. ccai/agentkit/workflowresult.py +250 -0
  226. ccai/agentkit/workflowstep.py +195 -0
  227. codecraftai_agent_kit-1.3.0.dist-info/METADATA +99 -0
  228. codecraftai_agent_kit-1.3.0.dist-info/RECORD +230 -0
  229. codecraftai_agent_kit-1.3.0.dist-info/WHEEL +4 -0
  230. codecraftai_agent_kit-1.3.0.dist-info/licenses/LICENSE.md +204 -0
@@ -0,0 +1,295 @@
1
+ """
2
+ Defines the WorkflowConfiguration class for declarative workflow
3
+ execution settings in the Workflow & Orchestration feature.
4
+
5
+ A WorkflowConfiguration contains the maximum parallel workers,
6
+ checkpoint interval, default approval timeout, and an optional
7
+ default retry policy. The class provides JSON and YAML
8
+ serialization and deserialization, including file-based loading
9
+ with optional AppContext path resolution.
10
+
11
+ Requirements: 17.1-17.16, 23.23, 23.24
12
+ """
13
+
14
+ import json
15
+ import os
16
+
17
+ import yaml
18
+
19
+ from ccai.agentkit.errors import ConfigurationError
20
+
21
+
22
+ class WorkflowConfiguration:
23
+ """
24
+ Configuration object defining default workflow execution
25
+ settings.
26
+
27
+ A WorkflowConfiguration captures the maximum number of
28
+ parallel workers, the checkpoint interval (number of steps
29
+ between automatic checkpoints), the default approval timeout
30
+ in seconds, and an optional default retry policy. All fields
31
+ are exposed as read-only properties.
32
+
33
+ Validation is performed at construction time:
34
+ - max_parallel_workers must be >= 1
35
+ - default_approval_timeout must be > 0
36
+
37
+ :param max_parallel_workers: The maximum number of
38
+ concurrently executing branches. Must be >= 1.
39
+ Defaults to 4.
40
+ :param checkpoint_interval: The number of steps between
41
+ automatic checkpoints. Defaults to 1.
42
+ :param default_approval_timeout: The default timeout in
43
+ seconds for approval requests. Must be > 0.
44
+ Defaults to 3600.0.
45
+ :param default_retry_policy: An optional default retry
46
+ policy for workflow steps. Defaults to None.
47
+
48
+ :raises ConfigurationError: If max_parallel_workers < 1
49
+ or default_approval_timeout <= 0.
50
+ """
51
+
52
+ def __init__(self, max_parallel_workers: int = 4,
53
+ checkpoint_interval: int = 1,
54
+ default_approval_timeout: float = 3600.0,
55
+ default_retry_policy=None) -> None:
56
+
57
+ if max_parallel_workers < 1:
58
+ errmsg = "The maximum parallel workers must be at least 1, got {}.".format(
59
+ max_parallel_workers
60
+ )
61
+ raise ConfigurationError(errmsg)
62
+
63
+ if default_approval_timeout <= 0:
64
+ errmsg = "The default approval timeout must be a positive value, got {}.".format(
65
+ default_approval_timeout
66
+ )
67
+ raise ConfigurationError(errmsg)
68
+
69
+ self._max_parallel_workers = max_parallel_workers
70
+ self._checkpoint_interval = checkpoint_interval
71
+ self._default_approval_timeout = default_approval_timeout
72
+ self._default_retry_policy = default_retry_policy
73
+ return
74
+
75
+ @property
76
+ def max_parallel_workers(self) -> int:
77
+ """
78
+ The maximum number of concurrently executing branches.
79
+
80
+ :returns: An integer >= 1.
81
+ """
82
+ return self._max_parallel_workers
83
+
84
+ @property
85
+ def checkpoint_interval(self) -> int:
86
+ """
87
+ The number of steps between automatic checkpoints.
88
+
89
+ :returns: An integer representing the checkpoint interval.
90
+ """
91
+ return self._checkpoint_interval
92
+
93
+ @property
94
+ def default_approval_timeout(self) -> float:
95
+ """
96
+ The default timeout in seconds for approval requests.
97
+
98
+ :returns: A positive float in seconds.
99
+ """
100
+ return self._default_approval_timeout
101
+
102
+ @property
103
+ def default_retry_policy(self):
104
+ """
105
+ The optional default retry policy for workflow steps.
106
+
107
+ :returns: A retry policy object or None.
108
+ """
109
+ return self._default_retry_policy
110
+
111
+ def as_dict(self) -> dict:
112
+ """
113
+ Returns a dictionary representation of the configuration.
114
+
115
+ The default_retry_policy is included only when it is
116
+ not None.
117
+
118
+ :returns: A dictionary containing all configuration
119
+ fields.
120
+ """
121
+ rtnval = {
122
+ "max_parallel_workers": self._max_parallel_workers,
123
+ "checkpoint_interval": self._checkpoint_interval,
124
+ "default_approval_timeout": self._default_approval_timeout,
125
+ }
126
+
127
+ if self._default_retry_policy is not None:
128
+ rtnval["default_retry_policy"] = self._default_retry_policy
129
+
130
+ return rtnval
131
+
132
+ def to_json(self) -> str:
133
+ """
134
+ Returns a JSON string representation of the
135
+ configuration.
136
+
137
+ :returns: A JSON string containing all configuration
138
+ fields.
139
+ """
140
+ data = self.as_dict()
141
+ rtnval = json.dumps(data)
142
+ return rtnval
143
+
144
+ def to_yaml(self) -> str:
145
+ """
146
+ Returns a YAML string representation of the
147
+ configuration.
148
+
149
+ :returns: A YAML string containing all configuration
150
+ fields.
151
+ """
152
+ data = self.as_dict()
153
+ rtnval = yaml.dump(data, default_flow_style=False)
154
+ return rtnval
155
+
156
+ @classmethod
157
+ def from_dict(cls, data: dict) -> "WorkflowConfiguration":
158
+ """
159
+ Constructs a WorkflowConfiguration from a dictionary.
160
+
161
+ :param data: A dictionary containing configuration
162
+ fields.
163
+
164
+ :returns: A WorkflowConfiguration instance.
165
+ """
166
+ max_parallel_workers = data.get("max_parallel_workers", 4)
167
+ checkpoint_interval = data.get("checkpoint_interval", 1)
168
+ default_approval_timeout = data.get("default_approval_timeout", 3600.0)
169
+ default_retry_policy = data.get("default_retry_policy", None)
170
+
171
+ rtnval = cls(
172
+ max_parallel_workers=max_parallel_workers,
173
+ checkpoint_interval=checkpoint_interval,
174
+ default_approval_timeout=default_approval_timeout,
175
+ default_retry_policy=default_retry_policy
176
+ )
177
+ return rtnval
178
+
179
+ @classmethod
180
+ def from_json(cls, json_str: str) -> "WorkflowConfiguration":
181
+ """
182
+ Deserializes a JSON string into a WorkflowConfiguration
183
+ instance.
184
+
185
+ :param json_str: A JSON string containing configuration
186
+ fields.
187
+
188
+ :returns: A WorkflowConfiguration instance.
189
+ """
190
+ data = json.loads(json_str)
191
+ rtnval = cls.from_dict(data)
192
+ return rtnval
193
+
194
+ @classmethod
195
+ def from_yaml(cls, yaml_str: str) -> "WorkflowConfiguration":
196
+ """
197
+ Deserializes a YAML string into a WorkflowConfiguration
198
+ instance.
199
+
200
+ :param yaml_str: A YAML string containing configuration
201
+ fields.
202
+
203
+ :returns: A WorkflowConfiguration instance.
204
+ """
205
+ data = yaml.safe_load(yaml_str)
206
+ rtnval = cls.from_dict(data)
207
+ return rtnval
208
+
209
+ @classmethod
210
+ def from_json_file(cls, file_path: str,
211
+ app_context=None) -> "WorkflowConfiguration":
212
+ """
213
+ Loads a WorkflowConfiguration from a JSON file.
214
+
215
+ When an app_context is provided, the file path is
216
+ resolved relative to the AppContext directory.
217
+
218
+ :param file_path: The path to the JSON configuration
219
+ file.
220
+ :param app_context: An optional AppContext for path
221
+ resolution.
222
+
223
+ :returns: A WorkflowConfiguration instance.
224
+ """
225
+ resolved_path = file_path
226
+
227
+ if app_context is not None:
228
+ base_dir = app_context.home_directory
229
+ resolved_path = os.path.join(base_dir, file_path)
230
+
231
+ with open(resolved_path, "r") as fh:
232
+ json_str = fh.read()
233
+
234
+ rtnval = cls.from_json(json_str)
235
+ return rtnval
236
+
237
+ @classmethod
238
+ def from_yaml_file(cls, file_path: str,
239
+ app_context=None) -> "WorkflowConfiguration":
240
+ """
241
+ Loads a WorkflowConfiguration from a YAML file.
242
+
243
+ When an app_context is provided, the file path is
244
+ resolved relative to the AppContext directory.
245
+
246
+ :param file_path: The path to the YAML configuration
247
+ file.
248
+ :param app_context: An optional AppContext for path
249
+ resolution.
250
+
251
+ :returns: A WorkflowConfiguration instance.
252
+ """
253
+ resolved_path = file_path
254
+
255
+ if app_context is not None:
256
+ base_dir = app_context.home_directory
257
+ resolved_path = os.path.join(base_dir, file_path)
258
+
259
+ with open(resolved_path, "r") as fh:
260
+ yaml_str = fh.read()
261
+
262
+ rtnval = cls.from_yaml(yaml_str)
263
+ return rtnval
264
+
265
+ def __repr__(self) -> str:
266
+ """
267
+ Returns a detailed string representation including the
268
+ class name, maximum parallel workers, and checkpoint
269
+ interval.
270
+
271
+ :returns: A repr string for debugging.
272
+ """
273
+ repr_str = "{}(max_parallel_workers={}, checkpoint_interval={})".format(
274
+ self.__class__.__name__, self._max_parallel_workers,
275
+ self._checkpoint_interval
276
+ )
277
+ return repr_str
278
+
279
+ def __str__(self) -> str:
280
+ """
281
+ Returns a human-readable summary including the maximum
282
+ parallel workers, checkpoint interval, and default
283
+ approval timeout.
284
+
285
+ :returns: A human-readable string describing the
286
+ configuration.
287
+ """
288
+ str_val = (
289
+ "WorkflowConfiguration: max_parallel_workers={}, "
290
+ "checkpoint_interval={}, default_approval_timeout={}s"
291
+ ).format(
292
+ self._max_parallel_workers, self._checkpoint_interval,
293
+ self._default_approval_timeout
294
+ )
295
+ return str_val
@@ -0,0 +1,249 @@
1
+ """
2
+ Defines the WorkflowContext class representing a mutable object
3
+ that carries shared state across workflow steps during execution
4
+ in the Workflow & Orchestration feature.
5
+
6
+ A WorkflowContext contains the workflow input dictionary,
7
+ accumulated step outputs keyed by step identifier, workflow-level
8
+ metadata, and a reference to the executing Agent. The class
9
+ provides JSON serialization and dictionary-based deserialization
10
+ for checkpoint persistence and state reconstruction.
11
+ """
12
+
13
+ import json
14
+
15
+ from typing import Optional
16
+
17
+
18
+ class WorkflowContext:
19
+ """
20
+ Mutable object carrying shared state across workflow steps
21
+ during execution.
22
+
23
+ A WorkflowContext holds the workflow input dictionary,
24
+ accumulated step outputs keyed by step identifier,
25
+ workflow-level metadata, and a reference to the executing
26
+ Agent. Steps read inputs and prior step outputs from the
27
+ context and write their own outputs back into it. The
28
+ context is scoped to a single workflow execution and is
29
+ not shared across executions.
30
+
31
+ :param inputs: A dictionary of workflow input values. When
32
+ None is provided, defaults to an empty dictionary.
33
+ :param agent: An optional reference to the executing Agent
34
+ instance. Defaults to None.
35
+ :param metadata: An optional dictionary of workflow-level
36
+ metadata. When None is provided, defaults to an empty
37
+ dictionary.
38
+ """
39
+
40
+ def __init__(self, inputs: dict, agent=None,
41
+ metadata: Optional[dict] = None) -> None:
42
+ self._inputs = dict(inputs) if inputs is not None else {}
43
+ self._agent = agent
44
+ self._metadata = dict(metadata) if metadata is not None else {}
45
+ self._step_outputs = {}
46
+ return
47
+
48
+ @property
49
+ def inputs(self) -> dict:
50
+ """
51
+ The workflow input dictionary.
52
+
53
+ :returns: A dictionary of workflow input values.
54
+ """
55
+ return self._inputs
56
+
57
+ @property
58
+ def agent(self):
59
+ """
60
+ The reference to the executing Agent instance.
61
+
62
+ :returns: The Agent instance or None when no agent
63
+ is associated with this context.
64
+ """
65
+ return self._agent
66
+
67
+ @property
68
+ def step_outputs(self) -> dict:
69
+ """
70
+ The dictionary of completed step outputs keyed by
71
+ step identifier.
72
+
73
+ :returns: A dictionary mapping step identifiers to
74
+ their output dictionaries.
75
+ """
76
+ return self._step_outputs
77
+
78
+ @property
79
+ def metadata(self) -> dict:
80
+ """
81
+ The workflow-level metadata dictionary.
82
+
83
+ :returns: A dictionary of metadata key-value pairs.
84
+ """
85
+ return self._metadata
86
+
87
+ def get_input(self, field_name: str, default=None):
88
+ """
89
+ Returns the value from the workflow input dictionary
90
+ for the given field name, or the default value when
91
+ the field is not present.
92
+
93
+ :param field_name: The name of the input field to
94
+ retrieve.
95
+ :param default: The value to return when the field
96
+ is not present. Defaults to None.
97
+
98
+ :returns: The input field value or the default value.
99
+ """
100
+ rtnval = self._inputs.get(field_name, default)
101
+ return rtnval
102
+
103
+ def get_step_output(self, step_id: str) -> Optional[dict]:
104
+ """
105
+ Returns the output dictionary for the completed step
106
+ with the given identifier, or None when the step has
107
+ not completed.
108
+
109
+ :param step_id: The unique identifier of the step
110
+ whose output to retrieve.
111
+
112
+ :returns: The step output dictionary or None when the
113
+ step has not completed.
114
+ """
115
+ rtnval = self._step_outputs.get(step_id, None)
116
+ return rtnval
117
+
118
+ def set_step_output(self, step_id: str, output: dict) -> None:
119
+ """
120
+ Stores the output dictionary for a completed step in
121
+ the context, keyed by the step identifier.
122
+
123
+ :param step_id: The unique identifier of the step.
124
+ :param output: The output dictionary produced by the
125
+ step execution.
126
+ """
127
+ self._step_outputs[step_id] = output
128
+ return
129
+
130
+ def get_metadata(self, key: str, default=None):
131
+ """
132
+ Returns the metadata value for the given key, or the
133
+ default value when the key is not present.
134
+
135
+ :param key: The metadata key string to retrieve.
136
+ :param default: The value to return when the key is
137
+ not present. Defaults to None.
138
+
139
+ :returns: The metadata value or the default value.
140
+ """
141
+ rtnval = self._metadata.get(key, default)
142
+ return rtnval
143
+
144
+ def set_metadata(self, key: str, value) -> None:
145
+ """
146
+ Stores a metadata value in the context under the given
147
+ key.
148
+
149
+ :param key: The metadata key string.
150
+ :param value: The metadata value to store.
151
+ """
152
+ self._metadata[key] = value
153
+ return
154
+
155
+ def as_dict(self) -> dict:
156
+ """
157
+ Returns a dictionary representation of the context state
158
+ including inputs, step_outputs, and metadata.
159
+
160
+ The agent reference is not included in the dictionary
161
+ representation because it is not serializable and must
162
+ be provided separately when reconstructing a context
163
+ from a dictionary.
164
+
165
+ :returns: A dictionary containing inputs, step_outputs,
166
+ and metadata.
167
+ """
168
+ rtnval = {
169
+ "inputs": self._inputs,
170
+ "step_outputs": self._step_outputs,
171
+ "metadata": self._metadata
172
+ }
173
+ return rtnval
174
+
175
+ def to_json(self) -> str:
176
+ """
177
+ Returns a JSON string representation of the context
178
+ state.
179
+
180
+ Serializes the as_dict output to a JSON string. The
181
+ agent reference is not included in the serialized
182
+ output.
183
+
184
+ :returns: A JSON string containing inputs, step_outputs,
185
+ and metadata.
186
+ """
187
+ data = self.as_dict()
188
+ rtnval = json.dumps(data)
189
+ return rtnval
190
+
191
+ @classmethod
192
+ def from_dict(cls, data: dict, agent=None) -> "WorkflowContext":
193
+ """
194
+ Constructs a WorkflowContext from a dictionary
195
+ representation.
196
+
197
+ Reconstructs the context from a dictionary containing
198
+ inputs, step_outputs, and metadata fields. The agent
199
+ reference is accepted as a separate parameter because
200
+ it is not included in the serialized representation.
201
+
202
+ :param data: A dictionary containing inputs, step_outputs,
203
+ and metadata fields.
204
+ :param agent: An optional reference to the executing Agent
205
+ instance. Defaults to None.
206
+
207
+ :returns: A WorkflowContext instance reconstructed from
208
+ the dictionary data.
209
+ """
210
+ inputs = data.get("inputs", {})
211
+ metadata = data.get("metadata", {})
212
+
213
+ context = cls(inputs=inputs, agent=agent, metadata=metadata)
214
+
215
+ step_outputs = data.get("step_outputs", {})
216
+ for step_id, output in step_outputs.items():
217
+ context.set_step_output(step_id, output)
218
+
219
+ return context
220
+
221
+ def __repr__(self) -> str:
222
+ """
223
+ Returns a detailed string representation including the
224
+ class name, the count of completed steps, and the count
225
+ of input fields.
226
+
227
+ :returns: A repr string for debugging.
228
+ """
229
+ completed_count = len(self._step_outputs)
230
+ input_count = len(self._inputs)
231
+ repr_str = "{}(completed_steps={}, input_fields={})".format(
232
+ self.__class__.__name__, completed_count, input_count
233
+ )
234
+ return repr_str
235
+
236
+ def __str__(self) -> str:
237
+ """
238
+ Returns a human-readable summary including the count of
239
+ completed steps and input field names.
240
+
241
+ :returns: A human-readable string describing the workflow
242
+ context.
243
+ """
244
+ completed_count = len(self._step_outputs)
245
+ input_names = list(self._inputs.keys())
246
+ str_val = "WorkflowContext: {} completed steps, inputs: {}".format(
247
+ completed_count, input_names
248
+ )
249
+ return str_val