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,95 @@
1
+ """
2
+ Exception hierarchy for the codecraftai-agent-kit framework.
3
+
4
+ Provides AgentKitError as the base exception, with ConfigurationError,
5
+ SemanticError, and LifecycleError as specialized subclasses.
6
+ """
7
+
8
+ from typing import Optional
9
+
10
+
11
+ class AgentKitError(Exception):
12
+ """
13
+ Base exception for all codecraftai-agent-kit framework errors.
14
+
15
+ :param message: A descriptive error message.
16
+ :param cause: An optional exception that caused this error.
17
+ """
18
+
19
+ def __init__(self, message: str, cause: Optional[Exception] = None) -> None:
20
+ self._message = message
21
+ self._cause = cause
22
+
23
+ if cause is not None:
24
+ super().__init__(message)
25
+ self.__cause__ = cause
26
+ else:
27
+ super().__init__(message)
28
+
29
+ return
30
+
31
+ @property
32
+ def message(self) -> str:
33
+ """
34
+ The descriptive error message.
35
+
36
+ :returns: The error message string.
37
+ """
38
+ return self._message
39
+
40
+ @property
41
+ def cause(self) -> Optional[Exception]:
42
+ """
43
+ The optional cause exception.
44
+
45
+ :returns: The cause exception or None.
46
+ """
47
+ return self._cause
48
+
49
+ def __repr__(self) -> str:
50
+ """
51
+ Returns a detailed string representation including class name and message.
52
+
53
+ :returns: A repr string for debugging.
54
+ """
55
+ repr_str = "{}(message={!r})".format(self.__class__.__name__, self._message)
56
+ return repr_str
57
+
58
+
59
+ class ConfigurationError(AgentKitError):
60
+ """
61
+ Raised for configuration-related problems in the agent framework.
62
+
63
+ :param message: A descriptive error message.
64
+ :param cause: An optional exception that caused this error.
65
+ """
66
+
67
+ def __init__(self, message: str, cause: Optional[Exception] = None) -> None:
68
+ super().__init__(message, cause=cause)
69
+ return
70
+
71
+
72
+ class SemanticError(AgentKitError):
73
+ """
74
+ Raised for API misuse in the agent framework.
75
+
76
+ :param message: A descriptive error message.
77
+ :param cause: An optional exception that caused this error.
78
+ """
79
+
80
+ def __init__(self, message: str, cause: Optional[Exception] = None) -> None:
81
+ super().__init__(message, cause=cause)
82
+ return
83
+
84
+
85
+ class LifecycleError(AgentKitError):
86
+ """
87
+ Raised for errors that occur during lifecycle transitions.
88
+
89
+ :param message: A descriptive error message.
90
+ :param cause: An optional exception that caused this error.
91
+ """
92
+
93
+ def __init__(self, message: str, cause: Optional[Exception] = None) -> None:
94
+ super().__init__(message, cause=cause)
95
+ return
@@ -0,0 +1,213 @@
1
+ """
2
+ Defines the ExecutionRecord class representing an immutable recorded
3
+ event during agent execution.
4
+
5
+ An ExecutionRecord contains a sequence number, a timestamp, an event
6
+ type string, the agent identifier, a correlation identifier, and a
7
+ payload dictionary with event-specific data. All fields are exposed
8
+ as read-only properties to preserve immutability after construction.
9
+ """
10
+
11
+ import json
12
+
13
+ from datetime import datetime
14
+
15
+
16
+ class ExecutionRecord:
17
+ """
18
+ An immutable object representing a recorded event during agent
19
+ execution.
20
+
21
+ Contains a sequence number identifying the order of the event,
22
+ a timestamp, an event type string, the agent identifier, a
23
+ correlation identifier, and a payload dictionary. All fields
24
+ are read-only after construction.
25
+
26
+ :param sequence_number: The monotonically increasing sequence
27
+ number for this record.
28
+ :param timestamp: The timestamp when the event was recorded.
29
+ :param event_type: The event type string identifying the kind
30
+ of event recorded.
31
+ :param agent_id: The agent identifier string for the agent that
32
+ produced this record.
33
+ :param correlation_id: The correlation identifier string linking
34
+ this record to a logical operation.
35
+ :param payload: Optional dictionary of event-specific data.
36
+ """
37
+
38
+ def __init__(self, sequence_number: int, timestamp: datetime,
39
+ event_type: str, agent_id: str, correlation_id: str,
40
+ payload: dict = None) -> None:
41
+
42
+ self._sequence_number = sequence_number
43
+ self._timestamp = timestamp
44
+ self._event_type = event_type
45
+ self._agent_id = agent_id
46
+ self._correlation_id = correlation_id
47
+
48
+ if payload is not None:
49
+ self._payload = dict(payload)
50
+ else:
51
+ self._payload = {}
52
+
53
+ return
54
+
55
+ @property
56
+ def sequence_number(self) -> int:
57
+ """
58
+ The monotonically increasing sequence number for this record.
59
+
60
+ :returns: The sequence number integer.
61
+ """
62
+ return self._sequence_number
63
+
64
+ @property
65
+ def timestamp(self) -> datetime:
66
+ """
67
+ The timestamp when the event was recorded.
68
+
69
+ :returns: The datetime timestamp.
70
+ """
71
+ return self._timestamp
72
+
73
+ @property
74
+ def event_type(self) -> str:
75
+ """
76
+ The event type string identifying the kind of event recorded.
77
+
78
+ :returns: The event type string.
79
+ """
80
+ return self._event_type
81
+
82
+ @property
83
+ def agent_id(self) -> str:
84
+ """
85
+ The agent identifier string for the agent that produced
86
+ this record.
87
+
88
+ :returns: The agent identifier string.
89
+ """
90
+ return self._agent_id
91
+
92
+ @property
93
+ def correlation_id(self) -> str:
94
+ """
95
+ The correlation identifier string linking this record to
96
+ a logical operation.
97
+
98
+ :returns: The correlation identifier string.
99
+ """
100
+ return self._correlation_id
101
+
102
+ @property
103
+ def payload(self) -> dict:
104
+ """
105
+ A copy of the payload dictionary of event-specific data.
106
+ Returns a copy to preserve immutability.
107
+
108
+ :returns: A dictionary copy of the payload fields.
109
+ """
110
+ result = dict(self._payload)
111
+ return result
112
+
113
+ def as_dict(self) -> dict:
114
+ """
115
+ Returns a dictionary representation of the execution record
116
+ fields.
117
+
118
+ The timestamp is serialized as an ISO format string for
119
+ consistent representation.
120
+
121
+ :returns: A dictionary containing all execution record fields.
122
+ """
123
+ result = {
124
+ "sequence_number": self._sequence_number,
125
+ "timestamp": self._timestamp.isoformat(),
126
+ "event_type": self._event_type,
127
+ "agent_id": self._agent_id,
128
+ "correlation_id": self._correlation_id,
129
+ "payload": dict(self._payload)
130
+ }
131
+ return result
132
+
133
+ def to_json(self) -> str:
134
+ """
135
+ Returns a JSON string representation of the execution record
136
+ fields.
137
+
138
+ :returns: A JSON string containing all execution record fields.
139
+ """
140
+ data = self.as_dict()
141
+ json_str = json.dumps(data)
142
+ return json_str
143
+
144
+ @classmethod
145
+ def from_dict(cls, data: dict) -> "ExecutionRecord":
146
+ """
147
+ Constructs an ExecutionRecord from a dictionary.
148
+
149
+ The timestamp field is expected to be an ISO format string
150
+ and is parsed back into a datetime object.
151
+
152
+ :param data: A dictionary containing execution record fields.
153
+
154
+ :returns: An ExecutionRecord instance reconstructed from
155
+ the dictionary.
156
+ """
157
+ sequence_number = data["sequence_number"]
158
+ timestamp = datetime.fromisoformat(data["timestamp"])
159
+ event_type = data["event_type"]
160
+ agent_id = data["agent_id"]
161
+ correlation_id = data["correlation_id"]
162
+ payload = data.get("payload", None)
163
+
164
+ record = cls(
165
+ sequence_number=sequence_number,
166
+ timestamp=timestamp,
167
+ event_type=event_type,
168
+ agent_id=agent_id,
169
+ correlation_id=correlation_id,
170
+ payload=payload
171
+ )
172
+ return record
173
+
174
+ @classmethod
175
+ def from_json(cls, json_str: str) -> "ExecutionRecord":
176
+ """
177
+ Deserializes a JSON string into an ExecutionRecord instance.
178
+
179
+ :param json_str: A JSON string containing execution record
180
+ fields.
181
+
182
+ :returns: An ExecutionRecord instance reconstructed from
183
+ the JSON data.
184
+ """
185
+ data = json.loads(json_str)
186
+ record = cls.from_dict(data)
187
+ return record
188
+
189
+ def __repr__(self) -> str:
190
+ """
191
+ Returns a detailed string representation including class name,
192
+ sequence number, event type, and agent identifier.
193
+
194
+ :returns: A repr string for debugging.
195
+ """
196
+ repr_str = "ExecutionRecord(sequence_number={!r}, event_type={!r}, agent_id={!r})".format(
197
+ self._sequence_number, self._event_type, self._agent_id
198
+ )
199
+ return repr_str
200
+
201
+ def __str__(self) -> str:
202
+ """
203
+ Returns a human-readable summary including the sequence number,
204
+ timestamp, event type, agent identifier, and correlation
205
+ identifier.
206
+
207
+ :returns: A human-readable string.
208
+ """
209
+ str_val = "ExecutionRecord: sequence_number={}, timestamp={}, event_type={}, agent_id={}, correlation_id={}".format(
210
+ self._sequence_number, self._timestamp.isoformat(),
211
+ self._event_type, self._agent_id, self._correlation_id
212
+ )
213
+ return str_val
@@ -0,0 +1,180 @@
1
+ """
2
+ Defines the ExecutionRecorder class that captures ExecutionRecord
3
+ objects during agent execution.
4
+
5
+ The ExecutionRecorder maintains an ordered list of records with
6
+ monotonically increasing sequence numbers starting from 1. It
7
+ supports start, stop, record, get_recording, and clear operations.
8
+ When not recording, the record method silently discards events.
9
+ """
10
+
11
+ from datetime import datetime
12
+
13
+ from ccai.agentkit.executionrecord import ExecutionRecord
14
+ from ccai.agentkit.executionrecording import ExecutionRecording
15
+
16
+
17
+ class ExecutionRecorder:
18
+ """
19
+ A component that captures ExecutionRecord objects during agent
20
+ execution, storing them in an ordered sequence for later replay
21
+ and inspection.
22
+
23
+ The recorder must be started before it will capture events.
24
+ When not recording, calls to record are silently discarded.
25
+ Sequence numbers are monotonically increasing starting from 1.
26
+
27
+ :param agent_id: The agent identifier string for the agent
28
+ whose execution is being recorded.
29
+ """
30
+
31
+ def __init__(self, agent_id: str) -> None:
32
+
33
+ self._agent_id = agent_id
34
+ self._records = []
35
+ self._sequence_counter = 0
36
+ self._is_recording = False
37
+ self._start_time = None
38
+ self._stop_time = None
39
+
40
+ return
41
+
42
+ @property
43
+ def count(self) -> int:
44
+ """
45
+ The number of records currently captured.
46
+
47
+ :returns: The record count integer.
48
+ """
49
+ return len(self._records)
50
+
51
+ @property
52
+ def is_recording(self) -> bool:
53
+ """
54
+ Whether the recorder is currently capturing events.
55
+
56
+ :returns: True if recording is active, False otherwise.
57
+ """
58
+ return self._is_recording
59
+
60
+ def start(self) -> None:
61
+ """
62
+ Starts recording execution events. Sets the start timestamp
63
+ to the current UTC time and enables event capture.
64
+
65
+ :returns: None.
66
+ """
67
+ self._is_recording = True
68
+ self._start_time = datetime.utcnow()
69
+ self._stop_time = None
70
+ return
71
+
72
+ def stop(self) -> None:
73
+ """
74
+ Stops recording execution events. Sets the stop timestamp
75
+ to the current UTC time and disables event capture.
76
+
77
+ :returns: None.
78
+ """
79
+ self._is_recording = False
80
+ self._stop_time = datetime.utcnow()
81
+ return
82
+
83
+ def record(self, event_type: str, correlation_id: str,
84
+ payload: dict = None) -> None:
85
+ """
86
+ Records an execution event if the recorder is currently
87
+ active. When not recording, the event is silently discarded.
88
+
89
+ Each recorded event receives a monotonically increasing
90
+ sequence number starting from 1.
91
+
92
+ :param event_type: The event type string identifying the
93
+ kind of event.
94
+ :param correlation_id: The correlation identifier string
95
+ linking this event to a logical operation.
96
+ :param payload: Optional dictionary of event-specific data.
97
+
98
+ :returns: None.
99
+ """
100
+ if not self._is_recording:
101
+ return
102
+
103
+ self._sequence_counter += 1
104
+
105
+ record = ExecutionRecord(
106
+ sequence_number=self._sequence_counter,
107
+ timestamp=datetime.utcnow(),
108
+ event_type=event_type,
109
+ agent_id=self._agent_id,
110
+ correlation_id=correlation_id,
111
+ payload=payload
112
+ )
113
+
114
+ self._records.append(record)
115
+
116
+ return
117
+
118
+ def get_recording(self) -> ExecutionRecording:
119
+ """
120
+ Returns an ExecutionRecording containing all captured records.
121
+
122
+ The start_time is the time when start was called. The
123
+ end_time is the time when stop was called, or the current
124
+ UTC time if still recording.
125
+
126
+ :returns: An ExecutionRecording instance with the captured
127
+ records.
128
+ """
129
+ start_time = self._start_time
130
+ if start_time is None:
131
+ start_time = datetime.utcnow()
132
+
133
+ end_time = self._stop_time
134
+ if end_time is None:
135
+ end_time = datetime.utcnow()
136
+
137
+ recording = ExecutionRecording(
138
+ agent_id=self._agent_id,
139
+ start_time=start_time,
140
+ end_time=end_time,
141
+ records=list(self._records)
142
+ )
143
+ return recording
144
+
145
+ def clear(self) -> None:
146
+ """
147
+ Clears all captured records and resets the sequence counter
148
+ to zero.
149
+
150
+ :returns: None.
151
+ """
152
+ self._records = []
153
+ self._sequence_counter = 0
154
+ return
155
+
156
+ def __repr__(self) -> str:
157
+ """
158
+ Returns a detailed string representation including class name,
159
+ agent identifier, record count, and recording state.
160
+
161
+ :returns: A repr string for debugging.
162
+ """
163
+ record_count = len(self._records)
164
+ repr_str = "ExecutionRecorder(agent_id={!r}, count={}, is_recording={})".format(
165
+ self._agent_id, record_count, self._is_recording
166
+ )
167
+ return repr_str
168
+
169
+ def __str__(self) -> str:
170
+ """
171
+ Returns a human-readable summary including the agent identifier,
172
+ record count, and recording state.
173
+
174
+ :returns: A human-readable string.
175
+ """
176
+ record_count = len(self._records)
177
+ str_val = "ExecutionRecorder: agent_id={}, count={}, is_recording={}".format(
178
+ self._agent_id, record_count, self._is_recording
179
+ )
180
+ return str_val