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,252 @@
1
+ """
2
+ Defines the ObservabilityPipeline class that coordinates the
3
+ StructuredLogger, Tracer, MetricsCollector, MetricsRegistry, and
4
+ ExecutionRecorder for an Agent.
5
+
6
+ The pipeline constructs all subsystem components during initialization
7
+ based on the provided ObservabilityConfiguration. When tracing is
8
+ disabled, the Tracer operates with a sampling rate of 0.0 so that
9
+ spans are not exported. When metrics are disabled, the MetricsCollector
10
+ exists but measurements are not delivered to exporters. When recording
11
+ is disabled, the ExecutionRecorder exists but is never started, so
12
+ calls to record silently discard events.
13
+
14
+ The pipeline provides methods for registering log, trace, and metrics
15
+ exporters, and a shutdown method that flushes and shuts down all
16
+ registered exporters.
17
+ """
18
+
19
+ from ccai.agentkit.builtinagentmetrics import register_builtin_agent_metrics
20
+ from ccai.agentkit.correlationcontext import CorrelationContext
21
+ from ccai.agentkit.executionrecorder import ExecutionRecorder
22
+ from ccai.agentkit.logexporter import LogExporter
23
+ from ccai.agentkit.metricscollector import MetricsCollector
24
+ from ccai.agentkit.metricsexporter import MetricsExporter
25
+ from ccai.agentkit.metricsregistry import MetricsRegistry
26
+ from ccai.agentkit.observabilityconfiguration import ObservabilityConfiguration
27
+ from ccai.agentkit.structuredlogger import StructuredLogger
28
+ from ccai.agentkit.tracer import Tracer
29
+ from ccai.agentkit.traceexporter import TraceExporter
30
+
31
+
32
+ class ObservabilityPipeline:
33
+ """
34
+ A component that coordinates the StructuredLogger, Tracer,
35
+ MetricsCollector, MetricsRegistry, and ExecutionRecorder for
36
+ an Agent, routing observability data to configured exporters.
37
+
38
+ The pipeline constructs all subsystem components during
39
+ initialization. The StructuredLogger is always created. When
40
+ tracing is disabled, the Tracer is created with a sampling
41
+ rate of 0.0 so spans are not exported. When metrics are
42
+ disabled, the MetricsCollector exists but does not deliver
43
+ measurements to exporters. When recording is disabled, the
44
+ ExecutionRecorder exists but is never started, so calls to
45
+ record silently discard events.
46
+
47
+ When metrics are enabled, the built-in agent metrics are
48
+ automatically registered in the MetricsRegistry.
49
+
50
+ :param configuration: The ObservabilityConfiguration defining
51
+ the pipeline behavior.
52
+ :param agent_id: The agent identifier string for the agent
53
+ that owns this pipeline.
54
+ :param correlation_context: Optional CorrelationContext for
55
+ the pipeline. Auto-created if not provided.
56
+ """
57
+
58
+ def __init__(self, configuration: ObservabilityConfiguration, agent_id: str,
59
+ correlation_context: CorrelationContext = None) -> None:
60
+
61
+ self._configuration = configuration
62
+ self._agent_id = agent_id
63
+
64
+ if correlation_context is not None:
65
+ self._correlation_context = correlation_context
66
+ else:
67
+ self._correlation_context = CorrelationContext()
68
+
69
+ self._log_exporters = []
70
+ self._trace_exporters = []
71
+ self._metrics_exporters = []
72
+
73
+ # StructuredLogger is always created
74
+ self._logger = StructuredLogger(
75
+ agent_id=agent_id,
76
+ correlation_context=self._correlation_context
77
+ )
78
+
79
+ # Tracer: when tracing disabled, use sampling_rate=0.0 (no-op)
80
+ if configuration.tracing_enabled:
81
+ tracer_sampling_rate = configuration.sampling_rate
82
+ else:
83
+ tracer_sampling_rate = 0.0
84
+
85
+ self._tracer = Tracer(
86
+ agent_id=agent_id,
87
+ sampling_rate=tracer_sampling_rate
88
+ )
89
+
90
+ # MetricsRegistry and MetricsCollector
91
+ self._metrics_registry = MetricsRegistry()
92
+ self._metrics_collector = MetricsCollector(
93
+ registry=self._metrics_registry
94
+ )
95
+
96
+ # Register built-in agent metrics when metrics are enabled
97
+ if configuration.metrics_enabled:
98
+ register_builtin_agent_metrics(self._metrics_registry)
99
+
100
+ # ExecutionRecorder: when recording disabled, never start it
101
+ self._execution_recorder = ExecutionRecorder(
102
+ agent_id=agent_id
103
+ )
104
+
105
+ if configuration.recording_enabled:
106
+ self._execution_recorder.start()
107
+
108
+ return
109
+
110
+ @property
111
+ def logger(self) -> StructuredLogger:
112
+ """
113
+ The StructuredLogger instance owned by this pipeline.
114
+
115
+ :returns: The StructuredLogger instance.
116
+ """
117
+ return self._logger
118
+
119
+ @property
120
+ def tracer(self) -> Tracer:
121
+ """
122
+ The Tracer instance owned by this pipeline.
123
+
124
+ :returns: The Tracer instance.
125
+ """
126
+ return self._tracer
127
+
128
+ @property
129
+ def metrics_collector(self) -> MetricsCollector:
130
+ """
131
+ The MetricsCollector instance owned by this pipeline.
132
+
133
+ :returns: The MetricsCollector instance.
134
+ """
135
+ return self._metrics_collector
136
+
137
+ @property
138
+ def metrics_registry(self) -> MetricsRegistry:
139
+ """
140
+ The MetricsRegistry instance owned by this pipeline.
141
+
142
+ :returns: The MetricsRegistry instance.
143
+ """
144
+ return self._metrics_registry
145
+
146
+ @property
147
+ def execution_recorder(self) -> ExecutionRecorder:
148
+ """
149
+ The ExecutionRecorder instance owned by this pipeline.
150
+
151
+ :returns: The ExecutionRecorder instance.
152
+ """
153
+ return self._execution_recorder
154
+
155
+ def register_log_exporter(self, exporter: LogExporter) -> None:
156
+ """
157
+ Registers a LogExporter instance with the pipeline.
158
+
159
+ :param exporter: The LogExporter instance to register.
160
+ """
161
+ self._log_exporters.append(exporter)
162
+
163
+ return
164
+
165
+ def register_trace_exporter(self, exporter: TraceExporter) -> None:
166
+ """
167
+ Registers a TraceExporter instance with the pipeline and
168
+ adds it to the Tracer's exporter list.
169
+
170
+ :param exporter: The TraceExporter instance to register.
171
+ """
172
+ self._trace_exporters.append(exporter)
173
+ self._tracer.register_exporter(exporter)
174
+
175
+ return
176
+
177
+ def register_metrics_exporter(self, exporter: MetricsExporter) -> None:
178
+ """
179
+ Registers a MetricsExporter instance with the pipeline and
180
+ adds it to the MetricsCollector's exporter list.
181
+
182
+ :param exporter: The MetricsExporter instance to register.
183
+ """
184
+ self._metrics_exporters.append(exporter)
185
+ self._metrics_collector.register_exporter(exporter)
186
+
187
+ return
188
+
189
+ def shutdown(self) -> None:
190
+ """
191
+ Flushes and shuts down all registered exporters.
192
+
193
+ Iterates through all log, trace, and metrics exporters,
194
+ calling flush and then shutdown on each. If an exporter
195
+ raises an exception during flush or shutdown, an
196
+ ObservabilityError is raised with the exporter details.
197
+ """
198
+ for exporter in self._log_exporters:
199
+ exporter.flush()
200
+ exporter.shutdown()
201
+
202
+ for exporter in self._trace_exporters:
203
+ exporter.flush()
204
+ exporter.shutdown()
205
+
206
+ for exporter in self._metrics_exporters:
207
+ exporter.flush()
208
+ exporter.shutdown()
209
+
210
+ return
211
+
212
+ def __repr__(self) -> str:
213
+ """
214
+ Returns a detailed string representation including the
215
+ class name and the count of log, trace, and metrics
216
+ exporters.
217
+
218
+ :returns: A repr string for debugging.
219
+ """
220
+ repr_str = (
221
+ "ObservabilityPipeline("
222
+ "log_exporters={}, "
223
+ "trace_exporters={}, "
224
+ "metrics_exporters={})"
225
+ ).format(
226
+ len(self._log_exporters),
227
+ len(self._trace_exporters),
228
+ len(self._metrics_exporters)
229
+ )
230
+ return repr_str
231
+
232
+ def __str__(self) -> str:
233
+ """
234
+ Returns a human-readable summary including the log level,
235
+ tracing enabled status, metrics enabled status, and
236
+ recording enabled status.
237
+
238
+ :returns: A human-readable string.
239
+ """
240
+ str_val = (
241
+ "ObservabilityPipeline: "
242
+ "log_level={}, "
243
+ "tracing_enabled={}, "
244
+ "metrics_enabled={}, "
245
+ "recording_enabled={}"
246
+ ).format(
247
+ self._configuration.log_level,
248
+ self._configuration.tracing_enabled,
249
+ self._configuration.metrics_enabled,
250
+ self._configuration.recording_enabled
251
+ )
252
+ return str_val
@@ -0,0 +1,82 @@
1
+ """
2
+ Defines the OutputParser abstract base class for parsing raw LLM
3
+ response text into structured Python objects.
4
+
5
+ OutputParser provides a two-phase parsing pipeline: subclasses implement
6
+ the _parse_raw method for format-specific parsing, and the base class
7
+ optionally validates the parsed result against an OutputSchema.
8
+ """
9
+
10
+ import abc
11
+
12
+ from ccai.agentkit.llmerrors import LLMResponseParsingError
13
+ from ccai.agentkit.outputschema import OutputSchema
14
+
15
+
16
+ class OutputParser(abc.ABC):
17
+ """
18
+ Abstract base class for parsing raw LLM response text
19
+ into structured Python objects.
20
+
21
+ Subclasses must implement the _parse_raw method to handle
22
+ format-specific parsing. The base class provides optional
23
+ post-parse validation against an OutputSchema.
24
+
25
+ :param schema: Optional OutputSchema for post-parse validation.
26
+ """
27
+
28
+ def __init__(self, schema: OutputSchema = None) -> None:
29
+ self._schema = schema
30
+ return
31
+
32
+ @property
33
+ def schema(self) -> OutputSchema:
34
+ """
35
+ The optional OutputSchema used for post-parse validation.
36
+
37
+ :returns: The OutputSchema instance or None.
38
+ """
39
+ rtnval = self._schema
40
+ return rtnval
41
+
42
+ @abc.abstractmethod
43
+ def _parse_raw(self, raw_text: str) -> object:
44
+ """
45
+ Parses the raw text into a Python object.
46
+ Subclasses implement this method.
47
+
48
+ :param raw_text: The raw LLM response text.
49
+
50
+ :returns: A parsed Python object.
51
+ :raises: LLMResponseParsingError
52
+ """
53
+
54
+ def parse(self, raw_text: str) -> object:
55
+ """
56
+ Parses raw text and optionally validates against the schema.
57
+
58
+ Calls _parse_raw to perform format-specific parsing, then
59
+ validates the result against the OutputSchema if one was
60
+ provided at construction time.
61
+
62
+ :param raw_text: The raw LLM response text.
63
+
64
+ :returns: A parsed Python object.
65
+ :raises: LLMResponseParsingError if parsing or validation fails.
66
+ """
67
+ parsed = self._parse_raw(raw_text)
68
+
69
+ if self._schema is not None:
70
+ validation_errors = self._schema.validate(parsed)
71
+ if len(validation_errors) > 0:
72
+ errmsg = "Output validation failed for {}: {}".format(
73
+ self.__class__.__name__, "; ".join(validation_errors)
74
+ )
75
+ raise LLMResponseParsingError(
76
+ parser_name=self.__class__.__name__,
77
+ raw_text=raw_text,
78
+ message=errmsg
79
+ )
80
+
81
+ rtnval = parsed
82
+ return rtnval
@@ -0,0 +1,142 @@
1
+ """
2
+ Defines the OutputSchema class for declarative output validation.
3
+
4
+ OutputSchema provides a schema definition with typed fields that can
5
+ be used to validate parsed LLM output. Each field has a name, a type
6
+ constraint, and a required/optional flag. The schema supports
7
+ serialization to and from JSON and dictionary representations.
8
+ """
9
+
10
+ import json
11
+
12
+
13
+ class OutputSchema:
14
+ """
15
+ Declarative schema for validating parsed LLM output.
16
+
17
+ Supports field type constraints and required/optional marking.
18
+ Each field definition is a dictionary with 'name', 'type', and
19
+ optional 'required' keys. Supported types are: string, integer,
20
+ float, boolean, list, and dictionary.
21
+
22
+ :param fields: A list of field definition dictionaries.
23
+ """
24
+
25
+ SUPPORTED_TYPES = {"string", "integer", "float", "boolean", "list", "dictionary"}
26
+
27
+ TYPE_MAP = {
28
+ "string": str,
29
+ "integer": int,
30
+ "float": float,
31
+ "boolean": bool,
32
+ "list": list,
33
+ "dictionary": dict,
34
+ }
35
+
36
+ def __init__(self, fields: list = None) -> None:
37
+ self._fields = list(fields) if fields is not None else []
38
+ return
39
+
40
+ @property
41
+ def fields(self) -> list:
42
+ """
43
+ Returns a copy of the field definitions list.
44
+
45
+ :returns: A list of field definition dictionaries.
46
+ """
47
+ rtnval = list(self._fields)
48
+ return rtnval
49
+
50
+ def validate(self, parsed_output: object) -> list:
51
+ """
52
+ Validates a parsed output object against this schema.
53
+
54
+ Checks that the parsed output is a dictionary, that all required
55
+ fields are present, and that field values match their declared types.
56
+
57
+ :param parsed_output: The parsed output (typically a dict).
58
+
59
+ :returns: A list of validation error strings. Empty if valid.
60
+ """
61
+ errors = []
62
+
63
+ if not isinstance(parsed_output, dict):
64
+ errors.append("Expected a dictionary, got {}.".format(type(parsed_output).__name__))
65
+ return errors
66
+
67
+ for field_def in self._fields:
68
+ fname = field_def["name"]
69
+ ftype = field_def["type"]
70
+ required = field_def.get("required", True)
71
+
72
+ if fname not in parsed_output:
73
+ if required:
74
+ errors.append("Missing required field: {!r}.".format(fname))
75
+ continue
76
+
77
+ value = parsed_output[fname]
78
+ expected_python_type = self.TYPE_MAP.get(ftype)
79
+ if expected_python_type is not None and not isinstance(value, expected_python_type):
80
+ errors.append("Field {!r} expected type {}, got {}.".format(
81
+ fname, ftype, type(value).__name__
82
+ ))
83
+
84
+ rtnval = errors
85
+ return rtnval
86
+
87
+ def as_dict(self) -> dict:
88
+ """
89
+ Returns a dictionary representation of the schema definition.
90
+
91
+ :returns: A dictionary with a 'fields' key containing the field definitions.
92
+ """
93
+ rtnval = {"fields": list(self._fields)}
94
+ return rtnval
95
+
96
+ def to_json(self) -> str:
97
+ """
98
+ Returns a JSON string representation of the schema definition.
99
+
100
+ :returns: A JSON string.
101
+ """
102
+ rtnval = json.dumps(self.as_dict())
103
+ return rtnval
104
+
105
+ @classmethod
106
+ def from_dict(cls, data: dict) -> "OutputSchema":
107
+ """
108
+ Constructs an OutputSchema from a dictionary.
109
+
110
+ :param data: A dictionary with a 'fields' key.
111
+
112
+ :returns: An OutputSchema instance.
113
+ """
114
+ rtnval = cls(fields=data.get("fields", []))
115
+ return rtnval
116
+
117
+ @classmethod
118
+ def from_json(cls, json_str: str) -> "OutputSchema":
119
+ """
120
+ Deserializes a JSON string into an OutputSchema instance.
121
+
122
+ :param json_str: A JSON string.
123
+
124
+ :returns: An OutputSchema instance.
125
+ """
126
+ data = json.loads(json_str)
127
+ rtnval = cls.from_dict(data)
128
+ return rtnval
129
+
130
+ def __eq__(self, other) -> bool:
131
+ """
132
+ Checks equality based on the field definitions.
133
+
134
+ :param other: The object to compare against.
135
+
136
+ :returns: True if field definitions are equal, False otherwise.
137
+ """
138
+ if not isinstance(other, OutputSchema):
139
+ return False
140
+
141
+ rtnval = self._fields == other._fields
142
+ return rtnval
@@ -0,0 +1,87 @@
1
+ """
2
+ Defines the ParallelBranch class representing an immutable grouping
3
+ construct that identifies a set of WorkflowStep nodes that can execute
4
+ concurrently, bounded by a fork step and a join step within a
5
+ WorkflowDefinition.
6
+
7
+ A ParallelBranch declares the boundaries of parallel execution by
8
+ specifying the fork step identifier where concurrent execution begins
9
+ and the join step identifier where parallel branches converge.
10
+ """
11
+
12
+
13
+ class ParallelBranch:
14
+ """
15
+ Immutable grouping construct identifying a set of steps that can
16
+ execute concurrently, bounded by a fork step and a join step.
17
+
18
+ A ParallelBranch makes parallel execution boundaries visible in
19
+ the WorkflowDefinition rather than inferred, improving
20
+ debuggability. The fork step identifier marks where concurrent
21
+ execution begins and the join step identifier marks where all
22
+ parallel branches must converge before execution continues.
23
+
24
+ :param fork_step_id: The identifier of the step where parallel
25
+ execution begins.
26
+ :param join_step_id: The identifier of the step where parallel
27
+ branches converge.
28
+ """
29
+
30
+ def __init__(self, fork_step_id: str, join_step_id: str) -> None:
31
+ self._fork_step_id = fork_step_id
32
+ self._join_step_id = join_step_id
33
+ return
34
+
35
+ @property
36
+ def fork_step_id(self) -> str:
37
+ """
38
+ The identifier of the step where parallel execution begins.
39
+
40
+ :returns: The fork step identifier string.
41
+ """
42
+ return self._fork_step_id
43
+
44
+ @property
45
+ def join_step_id(self) -> str:
46
+ """
47
+ The identifier of the step where parallel branches converge.
48
+
49
+ :returns: The join step identifier string.
50
+ """
51
+ return self._join_step_id
52
+
53
+ def as_dict(self) -> dict:
54
+ """
55
+ Returns a dictionary representation of the parallel branch fields.
56
+
57
+ :returns: A dictionary containing fork_step_id and join_step_id.
58
+ """
59
+ rtnval = {
60
+ "fork_step_id": self._fork_step_id,
61
+ "join_step_id": self._join_step_id
62
+ }
63
+ return rtnval
64
+
65
+ def __repr__(self) -> str:
66
+ """
67
+ Returns a detailed string representation including the class name,
68
+ fork step identifier, and join step identifier.
69
+
70
+ :returns: A repr string for debugging.
71
+ """
72
+ repr_str = "{}(fork_step_id={!r}, join_step_id={!r})".format(
73
+ self.__class__.__name__, self._fork_step_id, self._join_step_id
74
+ )
75
+ return repr_str
76
+
77
+ def __str__(self) -> str:
78
+ """
79
+ Returns a human-readable summary including the fork and join
80
+ step identifiers.
81
+
82
+ :returns: A human-readable string describing the parallel branch.
83
+ """
84
+ str_val = "ParallelBranch: fork={} -> join={}".format(
85
+ self._fork_step_id, self._join_step_id
86
+ )
87
+ return str_val
@@ -0,0 +1,43 @@
1
+ """
2
+ ccai.agentkit.platform - Cross-platform runtime abstraction layer.
3
+
4
+ Provides platform type enumeration, platform detection, configuration,
5
+ abstract service base classes, data transfer objects, platform adapters,
6
+ deployment descriptors, service registry, platform runtime, and the
7
+ platform-specific exception hierarchy.
8
+
9
+ .. module:: ccai.agentkit.platform
10
+ :platform: Darwin, Linux, Unix, Windows
11
+ :synopsis: Cross-platform runtime for the codecraftai-agent-kit SDK.
12
+ """
13
+
14
+ from ccai.agentkit.platform.errors import ComputeError
15
+ from ccai.agentkit.platform.errors import DeploymentDescriptorError
16
+ from ccai.agentkit.platform.errors import MessagingError
17
+ from ccai.agentkit.platform.errors import PlatformDetectionError
18
+ from ccai.agentkit.platform.errors import PlatformError
19
+ from ccai.agentkit.platform.errors import StorageError
20
+
21
+ from ccai.agentkit.platform.platformtype import PlatformType
22
+ from ccai.agentkit.platform.platformdetector import PlatformDetector
23
+ from ccai.agentkit.platform.platformconfiguration import PlatformConfiguration
24
+ from ccai.agentkit.platform.platformserviceregistry import PlatformServiceRegistry
25
+ from ccai.agentkit.platform.platformruntime import PlatformRuntime
26
+
27
+ from ccai.agentkit.platform.services.platformservice import PlatformService
28
+ from ccai.agentkit.platform.services.computeservice import ComputeService
29
+ from ccai.agentkit.platform.services.storageservice import StorageService
30
+ from ccai.agentkit.platform.services.messagingservice import MessagingService
31
+ from ccai.agentkit.platform.services.storageobject import StorageObject
32
+ from ccai.agentkit.platform.services.queuemessage import QueueMessage
33
+ from ccai.agentkit.platform.services.invocationresult import InvocationResult
34
+
35
+ from ccai.agentkit.platform.adapters.platformadapter import PlatformAdapter
36
+ from ccai.agentkit.platform.adapters.awsplatformadapter import AwsPlatformAdapter
37
+ from ccai.agentkit.platform.adapters.azureplatformadapter import AzurePlatformAdapter
38
+ from ccai.agentkit.platform.adapters.gcpplatformadapter import GcpPlatformAdapter
39
+ from ccai.agentkit.platform.adapters.localplatformadapter import LocalPlatformAdapter
40
+
41
+ from ccai.agentkit.platform.deployment.deploymentdescriptor import DeploymentDescriptor
42
+ from ccai.agentkit.platform.deployment.deploymentdescriptorparser import DeploymentDescriptorParser
43
+ from ccai.agentkit.platform.deployment.deploymentdescriptorprinter import DeploymentDescriptorPrinter
@@ -0,0 +1,18 @@
1
+ """
2
+ ccai.agentkit.platform.adapters - Platform-specific adapter implementations.
3
+
4
+ Provides the PlatformAdapter abstract base class and concrete adapter
5
+ implementations for AWS, Azure, GCP, and local environments. Each
6
+ adapter bundles compute, storage, and messaging service implementations
7
+ for its target platform.
8
+
9
+ .. module:: ccai.agentkit.platform.adapters
10
+ :platform: Darwin, Linux, Unix, Windows
11
+ :synopsis: Platform adapter base class and concrete implementations.
12
+ """
13
+
14
+ from ccai.agentkit.platform.adapters.platformadapter import PlatformAdapter
15
+ from ccai.agentkit.platform.adapters.awsplatformadapter import AwsPlatformAdapter
16
+ from ccai.agentkit.platform.adapters.azureplatformadapter import AzurePlatformAdapter
17
+ from ccai.agentkit.platform.adapters.gcpplatformadapter import GcpPlatformAdapter
18
+ from ccai.agentkit.platform.adapters.localplatformadapter import LocalPlatformAdapter