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,230 @@
1
+ """
2
+ Defines the ExecutionRecording class representing an immutable
3
+ complete recording of agent execution.
4
+
5
+ An ExecutionRecording contains the agent identifier, a start
6
+ timestamp, an end timestamp, and an ordered list of ExecutionRecord
7
+ objects. It supports filtering by event type and serialization
8
+ to and from JSON and dictionary representations.
9
+ """
10
+
11
+ import json
12
+
13
+ from datetime import datetime
14
+
15
+ from ccai.agentkit.executionrecord import ExecutionRecord
16
+
17
+
18
+ class ExecutionRecording:
19
+ """
20
+ An immutable object representing a complete recording of agent
21
+ execution.
22
+
23
+ Contains the agent identifier, a start timestamp, an end
24
+ timestamp, and an ordered list of ExecutionRecord objects.
25
+ All fields are read-only after construction.
26
+
27
+ :param agent_id: The agent identifier string for the agent
28
+ whose execution was recorded.
29
+ :param start_time: The timestamp when recording started.
30
+ :param end_time: The timestamp when recording ended.
31
+ :param records: Optional list of ExecutionRecord objects in
32
+ sequence order.
33
+ """
34
+
35
+ def __init__(self, agent_id: str, start_time: datetime,
36
+ end_time: datetime, records: list = None) -> None:
37
+
38
+ self._agent_id = agent_id
39
+ self._start_time = start_time
40
+ self._end_time = end_time
41
+
42
+ if records is not None:
43
+ self._records = list(records)
44
+ else:
45
+ self._records = []
46
+
47
+ return
48
+
49
+ @property
50
+ def agent_id(self) -> str:
51
+ """
52
+ The agent identifier string for the agent whose execution
53
+ was recorded.
54
+
55
+ :returns: The agent identifier string.
56
+ """
57
+ return self._agent_id
58
+
59
+ @property
60
+ def start_time(self) -> datetime:
61
+ """
62
+ The timestamp when recording started.
63
+
64
+ :returns: The start datetime timestamp.
65
+ """
66
+ return self._start_time
67
+
68
+ @property
69
+ def end_time(self) -> datetime:
70
+ """
71
+ The timestamp when recording ended.
72
+
73
+ :returns: The end datetime timestamp.
74
+ """
75
+ return self._end_time
76
+
77
+ @property
78
+ def records(self) -> list:
79
+ """
80
+ A copy of the ordered list of ExecutionRecord objects.
81
+ Returns a copy to preserve immutability.
82
+
83
+ :returns: A list copy of the ExecutionRecord objects.
84
+ """
85
+ result = list(self._records)
86
+ return result
87
+
88
+ @property
89
+ def duration(self) -> float:
90
+ """
91
+ The elapsed time in seconds between the start and end
92
+ timestamps.
93
+
94
+ :returns: The duration as a float in seconds.
95
+ """
96
+ delta = self._end_time - self._start_time
97
+ elapsed = delta.total_seconds()
98
+ return elapsed
99
+
100
+ def filter_by_event_type(self, event_type: str) -> "ExecutionRecording":
101
+ """
102
+ Returns a new ExecutionRecording containing only the records
103
+ that match the specified event type. The agent_id, start_time,
104
+ and end_time are preserved from the original recording.
105
+
106
+ :param event_type: The event type string to filter by.
107
+
108
+ :returns: A new ExecutionRecording with matching records.
109
+ """
110
+ matching_records = []
111
+
112
+ for record in self._records:
113
+ if record.event_type == event_type:
114
+ matching_records.append(record)
115
+
116
+ filtered = ExecutionRecording(
117
+ agent_id=self._agent_id,
118
+ start_time=self._start_time,
119
+ end_time=self._end_time,
120
+ records=matching_records
121
+ )
122
+ return filtered
123
+
124
+ def as_dict(self) -> dict:
125
+ """
126
+ Returns a dictionary representation of the execution recording
127
+ fields.
128
+
129
+ The timestamps are serialized as ISO format strings. Each
130
+ ExecutionRecord is serialized via its own as_dict method.
131
+
132
+ :returns: A dictionary containing all execution recording fields.
133
+ """
134
+ record_dicts = []
135
+ for record in self._records:
136
+ record_dicts.append(record.as_dict())
137
+
138
+ result = {
139
+ "agent_id": self._agent_id,
140
+ "start_time": self._start_time.isoformat(),
141
+ "end_time": self._end_time.isoformat(),
142
+ "records": record_dicts
143
+ }
144
+ return result
145
+
146
+ def to_json(self) -> str:
147
+ """
148
+ Returns a JSON string representation of the execution recording
149
+ fields.
150
+
151
+ :returns: A JSON string containing all execution recording fields.
152
+ """
153
+ data = self.as_dict()
154
+ json_str = json.dumps(data)
155
+ return json_str
156
+
157
+ @classmethod
158
+ def from_dict(cls, data: dict) -> "ExecutionRecording":
159
+ """
160
+ Constructs an ExecutionRecording from a dictionary.
161
+
162
+ The timestamp fields are expected to be ISO format strings
163
+ and are parsed back into datetime objects. Each record
164
+ dictionary is deserialized via ExecutionRecord.from_dict.
165
+
166
+ :param data: A dictionary containing execution recording fields.
167
+
168
+ :returns: An ExecutionRecording instance reconstructed from
169
+ the dictionary.
170
+ """
171
+ agent_id = data["agent_id"]
172
+ start_time = datetime.fromisoformat(data["start_time"])
173
+ end_time = datetime.fromisoformat(data["end_time"])
174
+
175
+ records = []
176
+ raw_records = data.get("records", [])
177
+ for record_data in raw_records:
178
+ record = ExecutionRecord.from_dict(record_data)
179
+ records.append(record)
180
+
181
+ recording = cls(
182
+ agent_id=agent_id,
183
+ start_time=start_time,
184
+ end_time=end_time,
185
+ records=records
186
+ )
187
+ return recording
188
+
189
+ @classmethod
190
+ def from_json(cls, json_str: str) -> "ExecutionRecording":
191
+ """
192
+ Deserializes a JSON string into an ExecutionRecording instance.
193
+
194
+ :param json_str: A JSON string containing execution recording
195
+ fields.
196
+
197
+ :returns: An ExecutionRecording instance reconstructed from
198
+ the JSON data.
199
+ """
200
+ data = json.loads(json_str)
201
+ recording = cls.from_dict(data)
202
+ return recording
203
+
204
+ def __repr__(self) -> str:
205
+ """
206
+ Returns a detailed string representation including class name,
207
+ agent identifier, and record count.
208
+
209
+ :returns: A repr string for debugging.
210
+ """
211
+ record_count = len(self._records)
212
+ repr_str = "ExecutionRecording(agent_id={!r}, record_count={})".format(
213
+ self._agent_id, record_count
214
+ )
215
+ return repr_str
216
+
217
+ def __str__(self) -> str:
218
+ """
219
+ Returns a human-readable summary including the agent identifier,
220
+ start time, end time, duration, and record count.
221
+
222
+ :returns: A human-readable string.
223
+ """
224
+ record_count = len(self._records)
225
+ elapsed = self.duration
226
+ str_val = "ExecutionRecording: agent_id={}, start_time={}, end_time={}, duration={:.3f}s, records={}".format(
227
+ self._agent_id, self._start_time.isoformat(),
228
+ self._end_time.isoformat(), elapsed, record_count
229
+ )
230
+ return str_val
@@ -0,0 +1,187 @@
1
+ """
2
+ Defines the ExecutionReplayer class that reads an ExecutionRecording
3
+ and allows step-by-step inspection of the recorded events.
4
+
5
+ The ExecutionReplayer supports forward traversal via next, backward
6
+ traversal via previous, reset to the beginning, seek to a specific
7
+ sequence number, and filtering by event type. It raises SemanticError
8
+ when seeking to an invalid sequence number.
9
+ """
10
+
11
+ import os
12
+
13
+ from typing import Optional
14
+
15
+ from ccai.agentkit.errors import SemanticError
16
+ from ccai.agentkit.executionrecord import ExecutionRecord
17
+ from ccai.agentkit.executionrecording import ExecutionRecording
18
+
19
+
20
+ class ExecutionReplayer:
21
+ """
22
+ A component that reads an ExecutionRecording and allows
23
+ step-by-step inspection of the recorded events.
24
+
25
+ Supports forward and backward traversal, reset, seek by
26
+ sequence number, and filtering by event type. The position
27
+ starts at -1 (before the first record).
28
+
29
+ :param recording: The ExecutionRecording to replay.
30
+ """
31
+
32
+ def __init__(self, recording: ExecutionRecording) -> None:
33
+
34
+ self._recording = recording
35
+ self._position = -1
36
+
37
+ return
38
+
39
+ @property
40
+ def current(self) -> Optional[ExecutionRecord]:
41
+ """
42
+ The ExecutionRecord at the current position, or None if
43
+ the position is before the first record or after the last.
44
+
45
+ :returns: The current ExecutionRecord or None.
46
+ """
47
+ records = self._recording.records
48
+
49
+ if self._position < 0:
50
+ return None
51
+
52
+ if self._position >= len(records):
53
+ return None
54
+
55
+ record = records[self._position]
56
+ return record
57
+
58
+ @property
59
+ def position(self) -> int:
60
+ """
61
+ The current position index in the recording. Starts at -1
62
+ before any traversal.
63
+
64
+ :returns: The current position integer.
65
+ """
66
+ return self._position
67
+
68
+ @property
69
+ def total_count(self) -> int:
70
+ """
71
+ The total number of records in the recording.
72
+
73
+ :returns: The total record count integer.
74
+ """
75
+ records = self._recording.records
76
+ count = len(records)
77
+ return count
78
+
79
+ def next(self) -> Optional[ExecutionRecord]:
80
+ """
81
+ Advances the position by one and returns the ExecutionRecord
82
+ at the new position. Returns None if there are no more
83
+ records to traverse.
84
+
85
+ :returns: The next ExecutionRecord or None.
86
+ """
87
+ records = self._recording.records
88
+ next_position = self._position + 1
89
+
90
+ if next_position >= len(records):
91
+ return None
92
+
93
+ self._position = next_position
94
+ record = records[self._position]
95
+ return record
96
+
97
+ def previous(self) -> Optional[ExecutionRecord]:
98
+ """
99
+ Moves the position back by one and returns the ExecutionRecord
100
+ at the new position. Returns None if already at or before
101
+ the first record.
102
+
103
+ :returns: The previous ExecutionRecord or None.
104
+ """
105
+ prev_position = self._position - 1
106
+
107
+ if prev_position < 0:
108
+ return None
109
+
110
+ self._position = prev_position
111
+ records = self._recording.records
112
+ record = records[self._position]
113
+ return record
114
+
115
+ def reset(self) -> None:
116
+ """
117
+ Resets the position to -1, before the first record.
118
+
119
+ :returns: None.
120
+ """
121
+ self._position = -1
122
+ return
123
+
124
+ def seek(self, sequence_number: int) -> ExecutionRecord:
125
+ """
126
+ Moves the position to the record with the specified sequence
127
+ number and returns it. Raises SemanticError if no record
128
+ with the given sequence number exists.
129
+
130
+ :param sequence_number: The sequence number to seek to.
131
+
132
+ :returns: The ExecutionRecord at the specified sequence number.
133
+
134
+ :raises SemanticError: If no record with the given sequence
135
+ number exists in the recording.
136
+ """
137
+ records = self._recording.records
138
+
139
+ for index, record in enumerate(records):
140
+ if record.sequence_number == sequence_number:
141
+ self._position = index
142
+ return record
143
+
144
+ error_lines = []
145
+ error_lines.append("Cannot seek to sequence number {}.".format(sequence_number))
146
+ error_lines.append("No record with that sequence number exists in the recording.")
147
+ error_message = os.linesep.join(error_lines)
148
+ raise SemanticError(error_message)
149
+
150
+ def filter(self, event_type: str) -> "ExecutionReplayer":
151
+ """
152
+ Returns a new ExecutionReplayer with a filtered recording
153
+ containing only records that match the specified event type.
154
+
155
+ :param event_type: The event type string to filter by.
156
+
157
+ :returns: A new ExecutionReplayer with the filtered recording.
158
+ """
159
+ filtered_recording = self._recording.filter_by_event_type(event_type)
160
+ replayer = ExecutionReplayer(filtered_recording)
161
+ return replayer
162
+
163
+ def __repr__(self) -> str:
164
+ """
165
+ Returns a detailed string representation including class name,
166
+ position, and total record count.
167
+
168
+ :returns: A repr string for debugging.
169
+ """
170
+ total = self.total_count
171
+ repr_str = "ExecutionReplayer(position={}, total_count={})".format(
172
+ self._position, total
173
+ )
174
+ return repr_str
175
+
176
+ def __str__(self) -> str:
177
+ """
178
+ Returns a human-readable summary including the position
179
+ and total record count.
180
+
181
+ :returns: A human-readable string.
182
+ """
183
+ total = self.total_count
184
+ str_val = "ExecutionReplayer: position={}, total_count={}".format(
185
+ self._position, total
186
+ )
187
+ return str_val
@@ -0,0 +1,116 @@
1
+ """
2
+ Configuration object defining how expired MemoryEntry objects are handled.
3
+
4
+ Contains the default time-to-live duration and the cleanup interval.
5
+ """
6
+
7
+ import json
8
+ from typing import Optional
9
+
10
+
11
+ class ExpirationPolicy:
12
+ """
13
+ Configuration object defining how expired MemoryEntry objects are handled.
14
+ Contains the default time-to-live duration and the cleanup interval.
15
+ """
16
+
17
+ def __init__(self, default_ttl: float = None, cleanup_interval: float = 300.0) -> None:
18
+ """
19
+ Constructs an ExpirationPolicy.
20
+
21
+ :param default_ttl: Optional default time-to-live in seconds.
22
+ :param cleanup_interval: Cleanup interval in seconds. Defaults to 300.
23
+ """
24
+ self._default_ttl = default_ttl
25
+ self._cleanup_interval = cleanup_interval
26
+ return
27
+
28
+ @property
29
+ def default_ttl(self) -> Optional[float]:
30
+ """
31
+ The default time-to-live in seconds, or None if not set.
32
+
33
+ :returns: A float or None.
34
+ """
35
+ return self._default_ttl
36
+
37
+ @property
38
+ def cleanup_interval(self) -> float:
39
+ """
40
+ The cleanup interval in seconds.
41
+
42
+ :returns: A float.
43
+ """
44
+ return self._cleanup_interval
45
+
46
+ def as_dict(self) -> dict:
47
+ """
48
+ Returns a dictionary representation of the policy fields.
49
+
50
+ :returns: A dictionary with default_ttl and cleanup_interval.
51
+ """
52
+ rtnval = {
53
+ "default_ttl": self._default_ttl,
54
+ "cleanup_interval": self._cleanup_interval,
55
+ }
56
+ return rtnval
57
+
58
+ def to_json(self) -> str:
59
+ """
60
+ Returns a JSON string representation of the policy fields.
61
+
62
+ :returns: A JSON string.
63
+ """
64
+ rtnval = json.dumps(self.as_dict())
65
+ return rtnval
66
+
67
+ @classmethod
68
+ def from_dict(cls, data: dict) -> "ExpirationPolicy":
69
+ """
70
+ Constructs an ExpirationPolicy from a dictionary.
71
+
72
+ :param data: A dictionary with policy fields.
73
+
74
+ :returns: An ExpirationPolicy instance.
75
+ """
76
+ rtnval = cls(
77
+ default_ttl=data.get("default_ttl"),
78
+ cleanup_interval=data.get("cleanup_interval", 300.0),
79
+ )
80
+ return rtnval
81
+
82
+ @classmethod
83
+ def from_json(cls, json_str: str) -> "ExpirationPolicy":
84
+ """
85
+ Deserializes a JSON string into an ExpirationPolicy instance.
86
+
87
+ :param json_str: A JSON string.
88
+
89
+ :returns: An ExpirationPolicy instance.
90
+ """
91
+ data = json.loads(json_str)
92
+ rtnval = cls.from_dict(data)
93
+ return rtnval
94
+
95
+ def __repr__(self) -> str:
96
+ rtnval = "{}(default_ttl={}, cleanup_interval={})".format(
97
+ self.__class__.__name__, self._default_ttl, self._cleanup_interval
98
+ )
99
+ return rtnval
100
+
101
+ def __str__(self) -> str:
102
+ ttl_str = "{}s".format(self._default_ttl) if self._default_ttl is not None else "none"
103
+ rtnval = "ExpirationPolicy: ttl={}, cleanup_interval={}s".format(
104
+ ttl_str, self._cleanup_interval
105
+ )
106
+ return rtnval
107
+
108
+ def __eq__(self, other) -> bool:
109
+ if not isinstance(other, ExpirationPolicy):
110
+ rtnval = False
111
+ return rtnval
112
+ rtnval = (
113
+ self._default_ttl == other._default_ttl
114
+ and self._cleanup_interval == other._cleanup_interval
115
+ )
116
+ return rtnval
@@ -0,0 +1,82 @@
1
+ """
2
+ Defines the FallbackChain class for configuring fallback provider
3
+ sequences in the codecraftai-agent-kit framework.
4
+
5
+ FallbackChain maintains an ordered list of LLMProvider name-model pairs
6
+ that defines the fallback sequence when a provider fails. The chain is
7
+ traversed in order until a provider succeeds or all providers have been
8
+ exhausted.
9
+ """
10
+
11
+
12
+ class FallbackChain:
13
+ """
14
+ An ordered list of LLMProvider name-model pairs defining
15
+ the fallback sequence when a provider fails.
16
+
17
+ :param providers: An ordered list of (provider_name, model_name) tuples.
18
+ """
19
+
20
+ def __init__(self, providers: list) -> None:
21
+ self._providers = list(providers)
22
+ return
23
+
24
+ @property
25
+ def providers(self) -> list:
26
+ """
27
+ Returns the ordered list of provider name-model pairs.
28
+
29
+ :returns: A copy of the list of (provider_name, model_name) tuples.
30
+ """
31
+ rtnval = list(self._providers)
32
+ return rtnval
33
+
34
+ def next_provider(self, current_provider_name: str,
35
+ current_model_name: str) -> tuple:
36
+ """
37
+ Returns the next provider in the fallback sequence after the
38
+ specified current provider.
39
+
40
+ :param current_provider_name: The current provider name.
41
+ :param current_model_name: The current model name.
42
+
43
+ :returns: A (provider_name, model_name) tuple, or None if end of chain.
44
+ """
45
+ current = (current_provider_name, current_model_name)
46
+
47
+ for i in range(len(self._providers)):
48
+ provider_entry = self._providers[i]
49
+ is_match = provider_entry == current
50
+
51
+ if is_match is True:
52
+ next_index = i + 1
53
+ has_next = next_index < len(self._providers)
54
+
55
+ if has_next is True:
56
+ rtnval = self._providers[next_index]
57
+ return rtnval
58
+
59
+ return None
60
+
61
+ return None
62
+
63
+ def __repr__(self) -> str:
64
+ """
65
+ Returns a detailed string representation including the class name
66
+ and the count of providers in the chain.
67
+
68
+ :returns: A repr string for debugging.
69
+ """
70
+ rtnval = "{}(count={})".format(self.__class__.__name__, len(self._providers))
71
+ return rtnval
72
+
73
+ def __str__(self) -> str:
74
+ """
75
+ Returns a human-readable summary listing the provider name-model
76
+ pairs in the fallback chain.
77
+
78
+ :returns: A human-readable string.
79
+ """
80
+ pairs = ["{}/{}".format(p[0], p[1]) for p in self._providers]
81
+ rtnval = "FallbackChain: [{}]".format(", ".join(pairs))
82
+ return rtnval