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,360 @@
1
+ """
2
+ Defines the PluginManager class that coordinates plugin discovery,
3
+ loading, validation, and lifecycle management for an Agent in the
4
+ codecraftai-agent-kit framework.
5
+
6
+ The PluginManager manages plugins through their lifecycle states
7
+ (DISCOVERED -> LOADING -> LOADED -> ACTIVE) and handles failures
8
+ (-> FAILED). It delegates discovery and loading to codecraftai-extension
9
+ and adds agent-specific lifecycle integration.
10
+ """
11
+
12
+ import logging
13
+
14
+ from ccai.agentkit.configurationerrors import PluginLoadError
15
+ from ccai.agentkit.pluginconfiguration import PluginConfiguration
16
+ from ccai.agentkit.plugindescriptor import PluginDescriptor
17
+ from ccai.agentkit.pluginlifecyclehook import PluginLifecycleHook
18
+ from ccai.agentkit.pluginstatus import PluginStatus
19
+
20
+
21
+ class PluginManager:
22
+ """
23
+ Coordinates plugin discovery, loading, validation, and lifecycle
24
+ management for an Agent. Delegates discovery and loading to
25
+ codecraftai-extension and adds agent-specific lifecycle integration.
26
+
27
+ :param agent_identifier: The identifier of the agent this manager belongs to.
28
+ :param plugin_configuration: An optional PluginConfiguration instance.
29
+ """
30
+
31
+ def __init__(self, agent_identifier: str,
32
+ plugin_configuration: PluginConfiguration = None) -> None:
33
+ self._agent_identifier = agent_identifier
34
+ self._plugin_configuration = plugin_configuration
35
+ self._plugins = {}
36
+ self._logger = logging.getLogger("ccai.agentkit.plugins")
37
+ return
38
+
39
+ @property
40
+ def agent_identifier(self) -> str:
41
+ """
42
+ The identifier of the agent this manager belongs to.
43
+
44
+ :returns: The agent identifier string.
45
+ """
46
+ return self._agent_identifier
47
+
48
+ @property
49
+ def loaded_count(self) -> int:
50
+ """
51
+ The count of plugins with status LOADED or ACTIVE.
52
+
53
+ :returns: The number of loaded or active plugins.
54
+ """
55
+ count = 0
56
+ for entry in self._plugins.values():
57
+ descriptor = entry["descriptor"]
58
+ status = descriptor.status
59
+ if status is PluginStatus.LOADED or status is PluginStatus.ACTIVE:
60
+ count = count + 1
61
+ return count
62
+
63
+ @property
64
+ def active_count(self) -> int:
65
+ """
66
+ The count of plugins with status ACTIVE.
67
+
68
+ :returns: The number of active plugins.
69
+ """
70
+ count = 0
71
+ for entry in self._plugins.values():
72
+ descriptor = entry["descriptor"]
73
+ if descriptor.status is PluginStatus.ACTIVE:
74
+ count = count + 1
75
+ return count
76
+
77
+ def discover(self) -> list:
78
+ """
79
+ Scans configured search paths and the codecraftai-extension registry
80
+ for available plugins. For now, returns an empty list as the
81
+ codecraftai-extension integration is not yet available.
82
+
83
+ :returns: A list of PluginDescriptor objects.
84
+ """
85
+ discovered = []
86
+ return discovered
87
+
88
+ def load_plugin(self, descriptor: PluginDescriptor,
89
+ hook: PluginLifecycleHook = None) -> None:
90
+ """
91
+ Loads a plugin given its descriptor and optional lifecycle hook.
92
+ Transitions status to LOADING, invokes on_load hook if provided,
93
+ then transitions to LOADED. On failure, transitions to FAILED
94
+ and raises PluginLoadError.
95
+
96
+ :param descriptor: The PluginDescriptor for the plugin.
97
+ :param hook: An optional PluginLifecycleHook implementation.
98
+
99
+ :raises: PluginLoadError
100
+ """
101
+ plugin_name = descriptor.name
102
+
103
+ loading_descriptor = PluginDescriptor(
104
+ name=descriptor.name,
105
+ version=descriptor.version,
106
+ description=descriptor.description,
107
+ author=descriptor.author,
108
+ extension_points=descriptor.extension_points,
109
+ dependencies=descriptor.dependencies,
110
+ status=PluginStatus.LOADING
111
+ )
112
+
113
+ self._plugins[plugin_name] = {
114
+ "descriptor": loading_descriptor,
115
+ "hook": hook
116
+ }
117
+
118
+ if hook is not None:
119
+ try:
120
+ hook.on_load()
121
+ except Exception as err:
122
+ self._logger.warning(
123
+ "Plugin '%s' on_load hook raised an exception for agent '%s': %s",
124
+ plugin_name, self._agent_identifier, str(err)
125
+ )
126
+
127
+ loaded_descriptor = PluginDescriptor(
128
+ name=descriptor.name,
129
+ version=descriptor.version,
130
+ description=descriptor.description,
131
+ author=descriptor.author,
132
+ extension_points=descriptor.extension_points,
133
+ dependencies=descriptor.dependencies,
134
+ status=PluginStatus.LOADED
135
+ )
136
+
137
+ self._plugins[plugin_name] = {
138
+ "descriptor": loaded_descriptor,
139
+ "hook": hook
140
+ }
141
+
142
+ self._logger.info(
143
+ "Plugin '%s' loaded for agent '%s'",
144
+ plugin_name, self._agent_identifier
145
+ )
146
+ return
147
+
148
+ def activate_plugin(self, plugin_name: str) -> None:
149
+ """
150
+ Activates a loaded plugin. Validates dependencies are satisfied,
151
+ invokes on_activate hook, and transitions status to ACTIVE.
152
+ On failure, transitions to FAILED and raises PluginLoadError.
153
+
154
+ :param plugin_name: Name of the plugin to activate.
155
+
156
+ :raises: PluginLoadError
157
+ """
158
+ if plugin_name not in self._plugins:
159
+ errmsg = "Plugin '{}' is not loaded.".format(plugin_name)
160
+ raise PluginLoadError(plugin_name=plugin_name, message=errmsg)
161
+
162
+ entry = self._plugins[plugin_name]
163
+ descriptor = entry["descriptor"]
164
+ hook = entry["hook"]
165
+
166
+ dependencies = descriptor.dependencies
167
+ for dependency in dependencies:
168
+ is_satisfied = False
169
+
170
+ for other_name, other_entry in self._plugins.items():
171
+ other_descriptor = other_entry["descriptor"]
172
+ other_status = other_descriptor.status
173
+
174
+ if other_status is PluginStatus.LOADED or other_status is PluginStatus.ACTIVE:
175
+ if dependency.is_satisfied_by(other_descriptor.name, other_descriptor.version) is True:
176
+ is_satisfied = True
177
+ break
178
+
179
+ if is_satisfied is not True:
180
+ failed_descriptor = PluginDescriptor(
181
+ name=descriptor.name,
182
+ version=descriptor.version,
183
+ description=descriptor.description,
184
+ author=descriptor.author,
185
+ extension_points=descriptor.extension_points,
186
+ dependencies=descriptor.dependencies,
187
+ status=PluginStatus.FAILED
188
+ )
189
+
190
+ self._plugins[plugin_name] = {
191
+ "descriptor": failed_descriptor,
192
+ "hook": hook
193
+ }
194
+
195
+ errmsg = "Unsatisfied dependency '{}' for plugin '{}'.".format(
196
+ dependency.name, plugin_name
197
+ )
198
+ self._logger.warning(
199
+ "Plugin '%s' failed to activate for agent '%s': %s",
200
+ plugin_name, self._agent_identifier, errmsg
201
+ )
202
+ raise PluginLoadError(plugin_name=plugin_name, message=errmsg)
203
+
204
+ if hook is not None:
205
+ try:
206
+ hook.on_activate()
207
+ except Exception as err:
208
+ self._logger.warning(
209
+ "Plugin '%s' on_activate hook raised an exception for agent '%s': %s",
210
+ plugin_name, self._agent_identifier, str(err)
211
+ )
212
+
213
+ active_descriptor = PluginDescriptor(
214
+ name=descriptor.name,
215
+ version=descriptor.version,
216
+ description=descriptor.description,
217
+ author=descriptor.author,
218
+ extension_points=descriptor.extension_points,
219
+ dependencies=descriptor.dependencies,
220
+ status=PluginStatus.ACTIVE
221
+ )
222
+
223
+ self._plugins[plugin_name] = {
224
+ "descriptor": active_descriptor,
225
+ "hook": hook
226
+ }
227
+
228
+ self._logger.info(
229
+ "Plugin '%s' activated for agent '%s'",
230
+ plugin_name, self._agent_identifier
231
+ )
232
+ return
233
+
234
+ def deactivate_plugin(self, plugin_name: str) -> None:
235
+ """
236
+ Deactivates an active plugin. Invokes on_deactivate hook
237
+ and transitions status to LOADED.
238
+
239
+ :param plugin_name: Name of the plugin to deactivate.
240
+ """
241
+ if plugin_name not in self._plugins:
242
+ return
243
+
244
+ entry = self._plugins[plugin_name]
245
+ descriptor = entry["descriptor"]
246
+ hook = entry["hook"]
247
+
248
+ if hook is not None:
249
+ try:
250
+ hook.on_deactivate()
251
+ except Exception as err:
252
+ self._logger.warning(
253
+ "Plugin '%s' on_deactivate hook raised an exception for agent '%s': %s",
254
+ plugin_name, self._agent_identifier, str(err)
255
+ )
256
+
257
+ loaded_descriptor = PluginDescriptor(
258
+ name=descriptor.name,
259
+ version=descriptor.version,
260
+ description=descriptor.description,
261
+ author=descriptor.author,
262
+ extension_points=descriptor.extension_points,
263
+ dependencies=descriptor.dependencies,
264
+ status=PluginStatus.LOADED
265
+ )
266
+
267
+ self._plugins[plugin_name] = {
268
+ "descriptor": loaded_descriptor,
269
+ "hook": hook
270
+ }
271
+
272
+ self._logger.info(
273
+ "Plugin '%s' deactivated for agent '%s'",
274
+ plugin_name, self._agent_identifier
275
+ )
276
+ return
277
+
278
+ def unload_plugin(self, plugin_name: str) -> None:
279
+ """
280
+ Unloads a plugin: deactivates if active, invokes on_unload hook,
281
+ and removes from the manager.
282
+
283
+ :param plugin_name: Name of the plugin to unload.
284
+ """
285
+ if plugin_name not in self._plugins:
286
+ return
287
+
288
+ entry = self._plugins[plugin_name]
289
+ descriptor = entry["descriptor"]
290
+ hook = entry["hook"]
291
+
292
+ if descriptor.status is PluginStatus.ACTIVE:
293
+ self.deactivate_plugin(plugin_name)
294
+
295
+ if hook is not None:
296
+ try:
297
+ hook.on_unload()
298
+ except Exception as err:
299
+ self._logger.warning(
300
+ "Plugin '%s' on_unload hook raised an exception for agent '%s': %s",
301
+ plugin_name, self._agent_identifier, str(err)
302
+ )
303
+
304
+ del self._plugins[plugin_name]
305
+
306
+ self._logger.info(
307
+ "Plugin '%s' unloaded for agent '%s'",
308
+ plugin_name, self._agent_identifier
309
+ )
310
+ return
311
+
312
+ def get_plugin(self, plugin_name: str) -> PluginDescriptor:
313
+ """
314
+ Returns the PluginDescriptor for a loaded plugin, or None.
315
+
316
+ :param plugin_name: Name of the plugin to look up.
317
+
318
+ :returns: The PluginDescriptor or None.
319
+ """
320
+ if plugin_name not in self._plugins:
321
+ return None
322
+
323
+ entry = self._plugins[plugin_name]
324
+ descriptor = entry["descriptor"]
325
+ return descriptor
326
+
327
+ def list_all(self) -> list:
328
+ """
329
+ Returns a list of all PluginDescriptor objects managed by this manager.
330
+
331
+ :returns: A list of PluginDescriptor objects.
332
+ """
333
+ descriptors = []
334
+ for entry in self._plugins.values():
335
+ descriptors.append(entry["descriptor"])
336
+ return descriptors
337
+
338
+ def __repr__(self) -> str:
339
+ """
340
+ Returns a detailed string representation including class name,
341
+ agent identifier, loaded count, and active count.
342
+
343
+ :returns: A repr string for debugging.
344
+ """
345
+ repr_str = "PluginManager(agent_identifier={!r}, loaded_count={}, active_count={})".format(
346
+ self._agent_identifier, self.loaded_count, self.active_count
347
+ )
348
+ return repr_str
349
+
350
+ def __str__(self) -> str:
351
+ """
352
+ Returns a human-readable summary including the agent identifier,
353
+ loaded count, and active count.
354
+
355
+ :returns: A human-readable string.
356
+ """
357
+ str_val = "PluginManager for agent '{}' (loaded={}, active={})".format(
358
+ self._agent_identifier, self.loaded_count, self.active_count
359
+ )
360
+ return str_val
@@ -0,0 +1,47 @@
1
+ """
2
+ Defines the PluginStatus enum representing the lifecycle status
3
+ of a plugin in the codecraftai-agent-kit framework.
4
+ """
5
+
6
+ import enum
7
+
8
+ from ccai.agentkit.errors import SemanticError
9
+
10
+
11
+ class PluginStatus(enum.Enum):
12
+ """
13
+ Enumeration defining the lifecycle status of a plugin.
14
+
15
+ Plugins transition through these states during their lifecycle:
16
+ DISCOVERED, LOADING, LOADED, ACTIVE, FAILED, and DISABLED.
17
+ """
18
+
19
+ DISCOVERED = "DISCOVERED"
20
+ LOADING = "LOADING"
21
+ LOADED = "LOADED"
22
+ ACTIVE = "ACTIVE"
23
+ FAILED = "FAILED"
24
+ DISABLED = "DISABLED"
25
+
26
+ @classmethod
27
+ def from_string(cls, value: str) -> "PluginStatus":
28
+ """
29
+ Returns the PluginStatus member matching the given string.
30
+
31
+ :param value: The string value to match.
32
+
33
+ :returns: The matching PluginStatus member.
34
+
35
+ :raises SemanticError: If the value does not match any member.
36
+ """
37
+ upper_value = value.upper()
38
+
39
+ for member in cls:
40
+ if member.value == upper_value:
41
+ return member
42
+
43
+ valid_values = ", ".join(sorted(member.value for member in cls))
44
+ errmsg = "Invalid PluginStatus value '{}'. Valid values: {}".format(
45
+ value, valid_values
46
+ )
47
+ raise SemanticError(errmsg)
@@ -0,0 +1,116 @@
1
+ """
2
+ Defines the PooledAgent abstract base class for agents that run
3
+ on a shared thread pool executor in the codecraftai-agent-kit framework.
4
+
5
+ PooledAgent extends Agent and provides class-level pool management.
6
+ Lifecycle methods are submitted to the shared pool for execution.
7
+ Subclasses implement the abstract lifecycle methods.
8
+ """
9
+
10
+ import threading
11
+
12
+ from concurrent.futures import Future
13
+ from concurrent.futures import ThreadPoolExecutor
14
+ from typing import Optional
15
+
16
+ from ccai.agentkit.agent import Agent
17
+ from ccai.agentkit.agentconfiguration import AgentConfiguration
18
+ from ccai.agentkit.concurrencymodel import ConcurrencyModel
19
+
20
+
21
+ class PooledAgent(Agent):
22
+ """
23
+ Abstract base class for agents that run on a shared thread pool executor.
24
+
25
+ Provides class-level pool management via get_pool() and shutdown_pool().
26
+ Lifecycle methods can be submitted to the pool using submit_lifecycle().
27
+ Subclasses must implement the abstract lifecycle methods: initialize,
28
+ start, pause, resume, stop, and reset.
29
+
30
+ :param configuration: The AgentConfiguration for this agent.
31
+ :param max_workers: Optional maximum number of workers for the pool.
32
+ Only used if the class-level pool has not been created yet.
33
+ """
34
+
35
+ _pool: Optional[ThreadPoolExecutor] = None
36
+ _pool_lock: threading.Lock = threading.Lock()
37
+ _pool_max_workers: Optional[int] = None
38
+
39
+ def __init__(self, configuration: AgentConfiguration,
40
+ max_workers: Optional[int] = None) -> None:
41
+ super().__init__(configuration)
42
+ self._concurrency_model: ConcurrencyModel = ConcurrencyModel.THREAD_POOL
43
+
44
+ if max_workers is not None:
45
+ PooledAgent._pool_max_workers = max_workers
46
+
47
+ return
48
+
49
+ @property
50
+ def concurrency_model(self) -> ConcurrencyModel:
51
+ """
52
+ The concurrency model used by this agent.
53
+
54
+ :returns: ConcurrencyModel.THREAD_POOL
55
+ """
56
+ return self._concurrency_model
57
+
58
+ @classmethod
59
+ def get_pool(cls, max_workers: Optional[int] = None) -> ThreadPoolExecutor:
60
+ """
61
+ Returns the shared thread pool executor, creating it if necessary.
62
+
63
+ :param max_workers: Optional maximum number of workers. Only used
64
+ when creating the pool for the first time.
65
+
66
+ :returns: The shared ThreadPoolExecutor instance.
67
+ """
68
+ with cls._pool_lock:
69
+ if cls._pool is None:
70
+ workers = max_workers
71
+ if workers is None:
72
+ workers = cls._pool_max_workers
73
+ cls._pool = ThreadPoolExecutor(max_workers=workers)
74
+
75
+ return cls._pool
76
+
77
+ @classmethod
78
+ def shutdown_pool(cls, wait: bool = True) -> None:
79
+ """
80
+ Shuts down the shared thread pool executor.
81
+
82
+ :param wait: Whether to wait for pending futures to complete.
83
+ """
84
+ with cls._pool_lock:
85
+ if cls._pool is not None:
86
+ cls._pool.shutdown(wait=wait)
87
+ cls._pool = None
88
+
89
+ return
90
+
91
+ @classmethod
92
+ def _reset_pool(cls) -> None:
93
+ """
94
+ Resets the pool reference without shutting down.
95
+
96
+ This method is intended for testing purposes only.
97
+ """
98
+ with cls._pool_lock:
99
+ cls._pool = None
100
+ cls._pool_max_workers = None
101
+
102
+ return
103
+
104
+ def submit_lifecycle(self, method_name: str) -> Future:
105
+ """
106
+ Submits a lifecycle method to the shared thread pool for execution.
107
+
108
+ :param method_name: The name of the lifecycle method to invoke
109
+ (e.g., 'initialize', 'start', 'stop').
110
+
111
+ :returns: A Future representing the pending execution.
112
+ """
113
+ pool = self.get_pool()
114
+ method = getattr(self, method_name)
115
+ future = pool.submit(method)
116
+ return future