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,105 @@
1
+ """
2
+ Defines the HealthStatus class representing the result of a health check.
3
+ """
4
+
5
+ import json
6
+
7
+ from datetime import datetime
8
+ from typing import Optional
9
+
10
+ from ccai.agentkit.errors import SemanticError
11
+
12
+
13
+ VALID_STATUSES = {"healthy", "degraded", "unhealthy"}
14
+
15
+
16
+ class HealthStatus:
17
+ """
18
+ Immutable object representing the result of a health check.
19
+
20
+ :param check_name: The name of the health check.
21
+ :param status: The status string (healthy, degraded, unhealthy).
22
+ :param detail: Optional detail message.
23
+ :param response_time: Response time in seconds.
24
+ :param timestamp: The datetime of the check. Defaults to UTC now.
25
+ """
26
+
27
+ def __init__(self, check_name: str, status: str,
28
+ detail: Optional[str] = None,
29
+ response_time: float = 0.0,
30
+ timestamp: Optional[datetime] = None) -> None:
31
+ if status not in VALID_STATUSES:
32
+ errmsg = "Invalid health status '{}'. Valid values are: {}.".format(
33
+ status, ", ".join(sorted(VALID_STATUSES))
34
+ )
35
+ raise SemanticError(errmsg)
36
+
37
+ self._check_name = check_name
38
+ self._status = status
39
+ self._detail = detail
40
+ self._response_time = response_time
41
+ self._timestamp = timestamp if timestamp is not None else datetime.utcnow()
42
+ return
43
+
44
+ @property
45
+ def check_name(self) -> str:
46
+ return self._check_name
47
+
48
+ @property
49
+ def status(self) -> str:
50
+ return self._status
51
+
52
+ @property
53
+ def detail(self) -> Optional[str]:
54
+ return self._detail
55
+
56
+ @property
57
+ def response_time(self) -> float:
58
+ return self._response_time
59
+
60
+ @property
61
+ def timestamp(self) -> datetime:
62
+ return self._timestamp
63
+
64
+ @property
65
+ def is_healthy(self) -> bool:
66
+ return self._status == "healthy"
67
+
68
+ def as_dict(self) -> dict:
69
+ result = {
70
+ "check_name": self._check_name,
71
+ "status": self._status,
72
+ "detail": self._detail,
73
+ "response_time": self._response_time,
74
+ "timestamp": self._timestamp.isoformat()
75
+ }
76
+ return result
77
+
78
+ def to_json(self) -> str:
79
+ data = self.as_dict()
80
+ return json.dumps(data)
81
+
82
+ @classmethod
83
+ def from_dict(cls, data: dict) -> "HealthStatus":
84
+ return cls(
85
+ check_name=data["check_name"],
86
+ status=data["status"],
87
+ detail=data.get("detail"),
88
+ response_time=data.get("response_time", 0.0),
89
+ timestamp=datetime.fromisoformat(data["timestamp"]) if "timestamp" in data else None
90
+ )
91
+
92
+ @classmethod
93
+ def from_json(cls, json_str: str) -> "HealthStatus":
94
+ data = json.loads(json_str)
95
+ return cls.from_dict(data)
96
+
97
+ def __repr__(self) -> str:
98
+ return "HealthStatus(check_name={!r}, status={!r})".format(
99
+ self._check_name, self._status
100
+ )
101
+
102
+ def __str__(self) -> str:
103
+ return "HealthStatus check='{}', status={}, response_time={:.3f}s".format(
104
+ self._check_name, self._status, self._response_time
105
+ )
@@ -0,0 +1,214 @@
1
+ """
2
+ Defines the HotReloadMonitor class that watches configuration sources
3
+ for changes and triggers reload in the codecraftai-agent-kit framework.
4
+
5
+ The HotReloadMonitor runs on a configurable polling interval defined
6
+ by a HotReloadPolicy and notifies the ConfigurationManager of detected
7
+ changes. It uses a daemon thread for background monitoring and stores
8
+ file modification timestamps to detect changes.
9
+ """
10
+
11
+ import logging
12
+ import os
13
+ import threading
14
+
15
+ from ccai.agentkit.configurationerrors import ConfigurationValidationError
16
+
17
+
18
+ class HotReloadMonitor:
19
+ """
20
+ Watches configuration sources for changes and triggers reload.
21
+ Runs on a configurable polling interval and notifies the
22
+ ConfigurationManager of detected changes.
23
+
24
+ :param configuration_manager: The ConfigurationManager instance to
25
+ notify when changes are detected.
26
+ :param policy: The HotReloadPolicy defining monitoring behavior.
27
+ """
28
+
29
+ def __init__(self, configuration_manager, policy) -> None:
30
+ self._configuration_manager = configuration_manager
31
+ self._policy = policy
32
+ self._is_active = False
33
+ self._change_count = 0
34
+ self._logger = logging.getLogger("ccai.agentkit.configuration")
35
+ self._monitor_thread = None
36
+ self._stop_event = threading.Event()
37
+ self._file_timestamps = {}
38
+ return
39
+
40
+ @property
41
+ def is_active(self) -> bool:
42
+ """
43
+ Whether the monitor is currently active and polling for changes.
44
+
45
+ :returns: True if monitoring is active, False otherwise.
46
+ """
47
+ return self._is_active
48
+
49
+ @property
50
+ def change_count(self) -> int:
51
+ """
52
+ The number of configuration changes detected since the monitor
53
+ was started.
54
+
55
+ :returns: The count of detected changes.
56
+ """
57
+ return self._change_count
58
+
59
+ def start(self) -> None:
60
+ """
61
+ Begins monitoring configured file paths and environment variables
62
+ at the polling interval defined in the HotReloadPolicy.
63
+
64
+ Sets is_active to True and starts a daemon background thread
65
+ that polls file modification timestamps. When a file change is
66
+ detected, calls configuration_manager.reload() and increments
67
+ change_count. On reload failure (ConfigurationValidationError),
68
+ logs WARNING and retains previous config.
69
+ """
70
+ if self._is_active is True:
71
+ return
72
+
73
+ self._is_active = True
74
+ self._stop_event.clear()
75
+ self._file_timestamps = self._capture_file_timestamps()
76
+
77
+ self._logger.info(
78
+ "Starting hot-reload monitor with polling interval %.1f seconds",
79
+ self._policy.polling_interval
80
+ )
81
+
82
+ self._monitor_thread = threading.Thread(
83
+ target=self._monitor_loop,
84
+ name="hotreload-monitor",
85
+ daemon=True
86
+ )
87
+ self._monitor_thread.start()
88
+ return
89
+
90
+ def stop(self) -> None:
91
+ """
92
+ Stops monitoring and releases resources. Sets is_active to False
93
+ and stops the background thread.
94
+ """
95
+ if self._is_active is False:
96
+ return
97
+
98
+ self._is_active = False
99
+ self._stop_event.set()
100
+
101
+ if self._monitor_thread is not None:
102
+ self._monitor_thread.join(timeout=self._policy.polling_interval * 2)
103
+ self._monitor_thread = None
104
+
105
+ self._logger.info("Stopped hot-reload monitor")
106
+ return
107
+
108
+ def _monitor_loop(self) -> None:
109
+ """
110
+ Background thread loop that polls for file changes at the
111
+ configured polling interval. Exits when the stop event is set.
112
+ """
113
+ while self._stop_event.is_set() is False:
114
+ stopped = self._stop_event.wait(timeout=self._policy.polling_interval)
115
+
116
+ if stopped is True:
117
+ break
118
+
119
+ self._check_for_changes()
120
+
121
+ return
122
+
123
+ def _check_for_changes(self) -> None:
124
+ """
125
+ Checks all monitored files for modification timestamp changes.
126
+ When a change is detected, triggers a reload on the
127
+ ConfigurationManager and increments the change count.
128
+ """
129
+ current_timestamps = self._capture_file_timestamps()
130
+ change_detected = False
131
+
132
+ for file_path, current_mtime in current_timestamps.items():
133
+ previous_mtime = self._file_timestamps.get(file_path)
134
+
135
+ if previous_mtime is None:
136
+ change_detected = True
137
+ elif current_mtime != previous_mtime:
138
+ change_detected = True
139
+
140
+ for file_path in self._file_timestamps:
141
+ if file_path not in current_timestamps:
142
+ change_detected = True
143
+
144
+ if change_detected is True:
145
+ self._file_timestamps = current_timestamps
146
+ self._trigger_reload()
147
+
148
+ return
149
+
150
+ def _trigger_reload(self) -> None:
151
+ """
152
+ Triggers a configuration reload on the ConfigurationManager.
153
+ On success, increments the change count. On
154
+ ConfigurationValidationError, logs a WARNING and retains the
155
+ previous configuration.
156
+ """
157
+ try:
158
+ self._configuration_manager.reload()
159
+ self._change_count = self._change_count + 1
160
+ except ConfigurationValidationError as validation_err:
161
+ self._logger.warning(
162
+ "Hot-reload failed due to configuration validation error: %s",
163
+ str(validation_err)
164
+ )
165
+ except Exception as exc:
166
+ self._logger.warning(
167
+ "Hot-reload failed due to unexpected error: %s",
168
+ str(exc)
169
+ )
170
+
171
+ return
172
+
173
+ def _capture_file_timestamps(self) -> dict:
174
+ """
175
+ Captures the current modification timestamps for all monitored
176
+ files defined in the policy.
177
+
178
+ :returns: A dictionary mapping file path strings to their
179
+ modification timestamps as floats.
180
+ """
181
+ timestamps = {}
182
+ monitored_files = self._policy.monitored_files
183
+
184
+ for file_path in monitored_files:
185
+ if os.path.isfile(file_path) is True:
186
+ mtime = os.path.getmtime(file_path)
187
+ timestamps[file_path] = mtime
188
+
189
+ return timestamps
190
+
191
+ def __repr__(self) -> str:
192
+ """
193
+ Returns a detailed string representation including class name,
194
+ monitoring status, and polling interval.
195
+
196
+ :returns: A repr string for debugging.
197
+ """
198
+ repr_str = "HotReloadMonitor(is_active={}, polling_interval={})".format(
199
+ self._is_active, self._policy.polling_interval
200
+ )
201
+ return repr_str
202
+
203
+ def __str__(self) -> str:
204
+ """
205
+ Returns a human-readable summary including the monitoring status,
206
+ polling interval, and count of monitored files.
207
+
208
+ :returns: A human-readable string.
209
+ """
210
+ monitored_count = len(self._policy.monitored_files)
211
+ str_val = "HotReloadMonitor (is_active={}, polling_interval={}, monitored_files={})".format(
212
+ self._is_active, self._policy.polling_interval, monitored_count
213
+ )
214
+ return str_val
@@ -0,0 +1,160 @@
1
+ """
2
+ Defines the HotReloadPolicy class representing declarative hot-reload
3
+ behavior settings for the codecraftai-agent-kit framework.
4
+
5
+ A HotReloadPolicy contains a polling interval, a list of monitored file
6
+ paths, an environment monitoring enabled flag, and an automatic reload
7
+ enabled flag. The HotReloadMonitor uses a HotReloadPolicy to determine
8
+ how and when to check for configuration changes.
9
+ """
10
+
11
+ import json
12
+
13
+
14
+ class HotReloadPolicy:
15
+ """
16
+ Configuration object defining hot-reload behavior including polling
17
+ interval, monitored file paths, and automatic reload settings.
18
+
19
+ :param polling_interval: The polling interval in seconds as a float.
20
+ :param monitored_files: A list of file path strings to monitor for changes.
21
+ :param environment_monitoring_enabled: Whether environment variable monitoring is enabled.
22
+ :param automatic_reload_enabled: Whether automatic reload is enabled when changes are detected.
23
+ """
24
+
25
+ def __init__(self, polling_interval: float = 5.0, monitored_files: list = None,
26
+ environment_monitoring_enabled: bool = False,
27
+ automatic_reload_enabled: bool = True) -> None:
28
+ self._polling_interval = polling_interval
29
+
30
+ if monitored_files is not None:
31
+ self._monitored_files = list(monitored_files)
32
+ else:
33
+ self._monitored_files = []
34
+
35
+ self._environment_monitoring_enabled = environment_monitoring_enabled
36
+ self._automatic_reload_enabled = automatic_reload_enabled
37
+ return
38
+
39
+ @property
40
+ def polling_interval(self) -> float:
41
+ """
42
+ The polling interval in seconds.
43
+
44
+ :returns: The polling interval as a float.
45
+ """
46
+ return self._polling_interval
47
+
48
+ @property
49
+ def monitored_files(self) -> list:
50
+ """
51
+ A defensive copy of the list of monitored file paths.
52
+
53
+ :returns: A list copy of the monitored file path strings.
54
+ """
55
+ monitored_copy = list(self._monitored_files)
56
+ return monitored_copy
57
+
58
+ @property
59
+ def environment_monitoring_enabled(self) -> bool:
60
+ """
61
+ Whether environment variable monitoring is enabled.
62
+
63
+ :returns: True if environment monitoring is enabled, False otherwise.
64
+ """
65
+ return self._environment_monitoring_enabled
66
+
67
+ @property
68
+ def automatic_reload_enabled(self) -> bool:
69
+ """
70
+ Whether automatic reload is enabled when changes are detected.
71
+
72
+ :returns: True if automatic reload is enabled, False otherwise.
73
+ """
74
+ return self._automatic_reload_enabled
75
+
76
+ def as_dict(self) -> dict:
77
+ """
78
+ Returns a dictionary representation of the policy fields.
79
+
80
+ :returns: A dictionary with polling_interval, monitored_files,
81
+ environment_monitoring_enabled, and automatic_reload_enabled.
82
+ """
83
+ result = {
84
+ "polling_interval": self._polling_interval,
85
+ "monitored_files": list(self._monitored_files),
86
+ "environment_monitoring_enabled": self._environment_monitoring_enabled,
87
+ "automatic_reload_enabled": self._automatic_reload_enabled
88
+ }
89
+ return result
90
+
91
+ def to_json(self) -> str:
92
+ """
93
+ Returns a JSON string representation of the policy fields.
94
+
95
+ :returns: A JSON string containing all policy fields.
96
+ """
97
+ data = self.as_dict()
98
+ json_str = json.dumps(data)
99
+ return json_str
100
+
101
+ @classmethod
102
+ def from_dict(cls, data: dict) -> "HotReloadPolicy":
103
+ """
104
+ Constructs a HotReloadPolicy from a dictionary.
105
+
106
+ :param data: A dictionary containing polling_interval, monitored_files,
107
+ environment_monitoring_enabled, and automatic_reload_enabled.
108
+
109
+ :returns: A HotReloadPolicy instance reconstructed from the dictionary.
110
+ """
111
+ polling_interval = data.get("polling_interval", 5.0)
112
+ monitored_files = data.get("monitored_files", None)
113
+ environment_monitoring_enabled = data.get("environment_monitoring_enabled", False)
114
+ automatic_reload_enabled = data.get("automatic_reload_enabled", True)
115
+
116
+ policy = cls(
117
+ polling_interval=polling_interval,
118
+ monitored_files=monitored_files,
119
+ environment_monitoring_enabled=environment_monitoring_enabled,
120
+ automatic_reload_enabled=automatic_reload_enabled
121
+ )
122
+ return policy
123
+
124
+ @classmethod
125
+ def from_json(cls, json_str: str) -> "HotReloadPolicy":
126
+ """
127
+ Deserializes a JSON string into a HotReloadPolicy instance.
128
+
129
+ :param json_str: A JSON string containing policy fields.
130
+
131
+ :returns: A HotReloadPolicy instance reconstructed from the JSON data.
132
+ """
133
+ data = json.loads(json_str)
134
+ policy = cls.from_dict(data)
135
+ return policy
136
+
137
+ def __repr__(self) -> str:
138
+ """
139
+ Returns a detailed string representation including class name,
140
+ polling interval, and automatic reload enabled status.
141
+
142
+ :returns: A repr string for debugging.
143
+ """
144
+ repr_str = "HotReloadPolicy(polling_interval={}, automatic_reload_enabled={})".format(
145
+ self._polling_interval, self._automatic_reload_enabled
146
+ )
147
+ return repr_str
148
+
149
+ def __str__(self) -> str:
150
+ """
151
+ Returns a human-readable summary including the polling interval,
152
+ monitored file count, and automatic reload enabled status.
153
+
154
+ :returns: A human-readable string.
155
+ """
156
+ monitored_count = len(self._monitored_files)
157
+ str_val = "HotReloadPolicy (polling_interval={}, monitored_files={}, automatic_reload_enabled={})".format(
158
+ self._polling_interval, monitored_count, self._automatic_reload_enabled
159
+ )
160
+ return str_val
@@ -0,0 +1,61 @@
1
+ """
2
+ Defines the InMemoryDeadLetterStore for in-process dead letter storage.
3
+ """
4
+
5
+ from typing import Optional
6
+
7
+ from ccai.agentkit.deadletterentry import DeadLetterEntry
8
+ from ccai.agentkit.deadletterquery import DeadLetterQuery
9
+ from ccai.agentkit.deadletterquery import DeadLetterQueryResult
10
+ from ccai.agentkit.deadletterstore import DeadLetterStore
11
+
12
+
13
+ class InMemoryDeadLetterStore(DeadLetterStore):
14
+ """
15
+ In-process dictionary-based dead letter store.
16
+ """
17
+
18
+ def __init__(self) -> None:
19
+ super().__init__("in_memory")
20
+ self._entries = {}
21
+ return
22
+
23
+ def store(self, entry: DeadLetterEntry) -> None:
24
+ self._entries[entry.identifier] = entry
25
+ return
26
+
27
+ def retrieve(self, identifier: str) -> Optional[DeadLetterEntry]:
28
+ return self._entries.get(identifier)
29
+
30
+ def search(self, query: DeadLetterQuery) -> DeadLetterQueryResult:
31
+ matches = list(self._entries.values())
32
+
33
+ if query.operation_type is not None:
34
+ matches = [e for e in matches if e.operation_type == query.operation_type]
35
+ if query.source_component is not None:
36
+ matches = [e for e in matches if e.source_component == query.source_component]
37
+ if query.agent_identifier is not None:
38
+ matches = [e for e in matches if e.agent_identifier == query.agent_identifier]
39
+ if query.start_time is not None:
40
+ matches = [e for e in matches if e.timestamp >= query.start_time]
41
+ if query.end_time is not None:
42
+ matches = [e for e in matches if e.timestamp <= query.end_time]
43
+
44
+ total_count = len(matches)
45
+
46
+ if query.max_results is not None:
47
+ matches = matches[:query.max_results]
48
+
49
+ result = DeadLetterQueryResult(entries=matches, total_count=total_count)
50
+ return result
51
+
52
+ def delete(self, identifier: str) -> None:
53
+ self._entries.pop(identifier, None)
54
+ return
55
+
56
+ def purge(self) -> None:
57
+ self._entries.clear()
58
+ return
59
+
60
+ def count(self) -> int:
61
+ return len(self._entries)