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,150 @@
1
+ """
2
+ Defines the Breakpoint class representing an immutable condition at
3
+ which a DebugSession pauses execution.
4
+
5
+ A Breakpoint contains a breakpoint type string validated against a
6
+ set of valid types, an optional target name string, and an optional
7
+ condition expression string. The matches method determines whether
8
+ a given event type and target name satisfy the breakpoint criteria.
9
+ """
10
+
11
+ import os
12
+
13
+ from typing import Optional
14
+
15
+ from ccai.agentkit.errors import SemanticError
16
+
17
+
18
+ class Breakpoint:
19
+ """
20
+ An immutable object representing a condition at which the
21
+ DebugSession pauses execution.
22
+
23
+ The breakpoint_type must be one of the VALID_TYPES. When a
24
+ target_name is provided, the breakpoint only matches events
25
+ with both a matching type and matching target name. When no
26
+ target_name is provided, the breakpoint matches any event
27
+ with a matching type.
28
+
29
+ :param breakpoint_type: The type of breakpoint, must be one
30
+ of VALID_TYPES.
31
+ :param target_name: An optional target name to match against.
32
+ :param condition: An optional condition expression string.
33
+ """
34
+
35
+ VALID_TYPES = (
36
+ "lifecycle",
37
+ "tool",
38
+ "llm",
39
+ "workflow_step",
40
+ "message",
41
+ "memory",
42
+ "custom",
43
+ )
44
+
45
+ def __init__(self, breakpoint_type: str, target_name: str = None,
46
+ condition: str = None) -> None:
47
+
48
+ if breakpoint_type not in self.VALID_TYPES:
49
+ error_lines = [
50
+ "Invalid breakpoint type: {!r}.".format(breakpoint_type),
51
+ "Valid breakpoint types are: {}.".format(
52
+ ", ".join(self.VALID_TYPES)
53
+ ),
54
+ ]
55
+ error_msg = os.linesep.join(error_lines)
56
+ raise SemanticError(error_msg)
57
+
58
+ self._breakpoint_type = breakpoint_type
59
+ self._target_name = target_name
60
+ self._condition = condition
61
+
62
+ return
63
+
64
+ @property
65
+ def breakpoint_type(self) -> str:
66
+ """
67
+ The type of breakpoint.
68
+
69
+ :returns: The breakpoint type string.
70
+ """
71
+ return self._breakpoint_type
72
+
73
+ @property
74
+ def target_name(self) -> Optional[str]:
75
+ """
76
+ The optional target name to match against.
77
+
78
+ :returns: The target name string or None.
79
+ """
80
+ return self._target_name
81
+
82
+ @property
83
+ def condition(self) -> Optional[str]:
84
+ """
85
+ The optional condition expression string.
86
+
87
+ :returns: The condition string or None.
88
+ """
89
+ return self._condition
90
+
91
+ def matches(self, event_type: str, target_name: str = None) -> bool:
92
+ """
93
+ Determines whether this breakpoint matches the given event
94
+ type and optional target name.
95
+
96
+ When the breakpoint has a target_name, both the breakpoint
97
+ type and target name must match. When the breakpoint has no
98
+ target_name, only the breakpoint type must match.
99
+
100
+ :param event_type: The event type string to match against.
101
+ :param target_name: An optional target name string to match
102
+ against.
103
+
104
+ :returns: True if the breakpoint matches, False otherwise.
105
+ """
106
+ if self._breakpoint_type != event_type:
107
+ return False
108
+
109
+ if self._target_name is not None:
110
+ if self._target_name != target_name:
111
+ return False
112
+
113
+ return True
114
+
115
+ def as_dict(self) -> dict:
116
+ """
117
+ Returns a dictionary representation of the breakpoint fields.
118
+
119
+ :returns: A dictionary containing all breakpoint fields.
120
+ """
121
+ result = {
122
+ "breakpoint_type": self._breakpoint_type,
123
+ "target_name": self._target_name,
124
+ "condition": self._condition,
125
+ }
126
+ return result
127
+
128
+ def __repr__(self) -> str:
129
+ """
130
+ Returns a detailed string representation including class name,
131
+ breakpoint type, and target name.
132
+
133
+ :returns: A repr string for debugging.
134
+ """
135
+ repr_str = "Breakpoint(breakpoint_type={!r}, target_name={!r})".format(
136
+ self._breakpoint_type, self._target_name
137
+ )
138
+ return repr_str
139
+
140
+ def __str__(self) -> str:
141
+ """
142
+ Returns a human-readable summary including the breakpoint
143
+ type, target name, and condition expression.
144
+
145
+ :returns: A human-readable string.
146
+ """
147
+ str_val = "Breakpoint: type={}, target_name={}, condition={}".format(
148
+ self._breakpoint_type, self._target_name, self._condition
149
+ )
150
+ return str_val
@@ -0,0 +1,114 @@
1
+ """
2
+ Provides the register_builtin_agent_metrics function that registers
3
+ the standard set of agent metrics in a MetricsRegistry.
4
+
5
+ The 13 built-in metrics cover agent lifecycle transitions, tool
6
+ execution duration and errors, LLM request duration, token usage,
7
+ and errors, memory operations, message counts, workflow step
8
+ duration and errors, and active trace spans.
9
+ """
10
+
11
+ from ccai.agentkit.metricdefinition import MetricDefinition
12
+ from ccai.agentkit.metricsregistry import MetricsRegistry
13
+ from ccai.agentkit.metrictype import MetricType
14
+
15
+
16
+ BUILTIN_METRICS = [
17
+ MetricDefinition(
18
+ name="agent.lifecycle.transitions",
19
+ description="Count of agent lifecycle state transitions",
20
+ unit="count",
21
+ metric_type=MetricType.COUNTER
22
+ ),
23
+ MetricDefinition(
24
+ name="agent.tool.execution.duration",
25
+ description="Duration of tool executions",
26
+ unit="seconds",
27
+ metric_type=MetricType.HISTOGRAM
28
+ ),
29
+ MetricDefinition(
30
+ name="agent.tool.execution.errors",
31
+ description="Count of tool execution errors",
32
+ unit="count",
33
+ metric_type=MetricType.COUNTER
34
+ ),
35
+ MetricDefinition(
36
+ name="agent.llm.request.duration",
37
+ description="Duration of LLM completion requests",
38
+ unit="seconds",
39
+ metric_type=MetricType.HISTOGRAM
40
+ ),
41
+ MetricDefinition(
42
+ name="agent.llm.token.usage.prompt",
43
+ description="Count of prompt tokens consumed",
44
+ unit="tokens",
45
+ metric_type=MetricType.COUNTER
46
+ ),
47
+ MetricDefinition(
48
+ name="agent.llm.token.usage.completion",
49
+ description="Count of completion tokens consumed",
50
+ unit="tokens",
51
+ metric_type=MetricType.COUNTER
52
+ ),
53
+ MetricDefinition(
54
+ name="agent.llm.request.errors",
55
+ description="Count of LLM request errors",
56
+ unit="count",
57
+ metric_type=MetricType.COUNTER
58
+ ),
59
+ MetricDefinition(
60
+ name="agent.memory.operations",
61
+ description="Count of memory store operations",
62
+ unit="count",
63
+ metric_type=MetricType.COUNTER
64
+ ),
65
+ MetricDefinition(
66
+ name="agent.message.sent",
67
+ description="Count of messages sent",
68
+ unit="count",
69
+ metric_type=MetricType.COUNTER
70
+ ),
71
+ MetricDefinition(
72
+ name="agent.message.received",
73
+ description="Count of messages received",
74
+ unit="count",
75
+ metric_type=MetricType.COUNTER
76
+ ),
77
+ MetricDefinition(
78
+ name="agent.workflow.step.duration",
79
+ description="Duration of workflow step executions",
80
+ unit="seconds",
81
+ metric_type=MetricType.HISTOGRAM
82
+ ),
83
+ MetricDefinition(
84
+ name="agent.workflow.step.errors",
85
+ description="Count of workflow step execution errors",
86
+ unit="count",
87
+ metric_type=MetricType.COUNTER
88
+ ),
89
+ MetricDefinition(
90
+ name="agent.active.spans",
91
+ description="Count of currently active trace spans",
92
+ unit="count",
93
+ metric_type=MetricType.GAUGE
94
+ ),
95
+ ]
96
+
97
+
98
+ def register_builtin_agent_metrics(registry: MetricsRegistry) -> None:
99
+ """
100
+ Registers the standard set of agent metrics in the provided
101
+ MetricsRegistry.
102
+
103
+ Called automatically when an Agent is initialized with
104
+ observability enabled. Registers 13 metric definitions covering
105
+ lifecycle transitions, tool execution, LLM requests, memory
106
+ operations, messaging, workflow steps, and active spans.
107
+
108
+ :param registry: The MetricsRegistry instance to register
109
+ the built-in metrics in.
110
+ """
111
+ for definition in BUILTIN_METRICS:
112
+ registry.register(definition)
113
+
114
+ return
@@ -0,0 +1,11 @@
1
+ """
2
+ Built-in tools for the codecraftai-agent-kit framework.
3
+
4
+ Provides ready-to-use Tool implementations for common operations
5
+ including file I/O, HTTP requests, and shell command execution.
6
+ """
7
+
8
+ from ccai.agentkit.builtins.filereadtool import FileReadTool
9
+ from ccai.agentkit.builtins.filewritetool import FileWriteTool
10
+ from ccai.agentkit.builtins.httprequesttool import HttpRequestTool
11
+ from ccai.agentkit.builtins.shellcommandtool import ShellCommandTool
@@ -0,0 +1,90 @@
1
+ """
2
+ Built-in tool for reading file contents.
3
+
4
+ Provides the FileReadTool class which reads the contents of a file
5
+ at a specified path and returns the content as a string.
6
+ """
7
+
8
+ import os
9
+
10
+ from ccai.agentkit.tool import Tool
11
+ from ccai.agentkit.toolerrors import ToolExecutionError
12
+
13
+
14
+ class FileReadTool(Tool):
15
+ """
16
+ Reads the contents of a file at the specified path.
17
+
18
+ Accepts a required file_path parameter and an optional encoding
19
+ parameter (defaulting to utf-8). Returns the file contents as
20
+ a string. Raises ToolExecutionError for file-not-found and
21
+ permission errors.
22
+ """
23
+
24
+ TOOL_NAME = "file_read"
25
+ TOOL_DESCRIPTION = "Reads the contents of a file at the specified path."
26
+ TOOL_VERSION = "1.0.0"
27
+
28
+ INPUT_SCHEMA = {
29
+ "parameters": [
30
+ {
31
+ "name": "file_path",
32
+ "type": "string",
33
+ "required": True,
34
+ "description": "Path to the file to read.",
35
+ },
36
+ {
37
+ "name": "encoding",
38
+ "type": "string",
39
+ "required": False,
40
+ "default": "utf-8",
41
+ "description": "File encoding.",
42
+ },
43
+ ]
44
+ }
45
+
46
+ OUTPUT_SCHEMA = {
47
+ "parameters": [
48
+ {
49
+ "name": "content",
50
+ "type": "string",
51
+ "required": True,
52
+ "description": "File contents.",
53
+ },
54
+ ]
55
+ }
56
+
57
+ def execute(self, inputs: dict, credentials: dict = None) -> dict:
58
+ """
59
+ Reads the contents of the file specified by the inputs.
60
+
61
+ :param inputs: Dictionary containing 'file_path' and optional 'encoding'.
62
+ :param credentials: Optional dictionary of resolved credentials (unused).
63
+
64
+ :returns: A dictionary with a 'content' key containing the file contents.
65
+
66
+ :raises: ToolExecutionError
67
+ """
68
+ file_path = inputs["file_path"]
69
+ encoding = inputs.get("encoding", "utf-8")
70
+
71
+ try:
72
+ with open(file_path, mode="r", encoding=encoding) as file_handle:
73
+ content = file_handle.read()
74
+ except FileNotFoundError as fnf_err:
75
+ err_msg_lines = [
76
+ "File not found: '{}'.".format(file_path),
77
+ ]
78
+ err_msg = os.linesep.join(err_msg_lines)
79
+ raise ToolExecutionError(tool_name=self.TOOL_NAME, cause=FileNotFoundError(err_msg)) from fnf_err
80
+ except PermissionError as perm_err:
81
+ err_msg_lines = [
82
+ "Permission denied reading file: '{}'.".format(file_path),
83
+ "DETAIL: {}".format(str(perm_err)),
84
+ ]
85
+ err_msg = os.linesep.join(err_msg_lines)
86
+ raise ToolExecutionError(tool_name=self.TOOL_NAME, cause=PermissionError(err_msg)) from perm_err
87
+
88
+ rtnval = {"content": content}
89
+
90
+ return rtnval
@@ -0,0 +1,93 @@
1
+ """
2
+ Built-in tool for writing content to a file.
3
+
4
+ Provides the FileWriteTool class which writes string content to a file
5
+ at a specified path and returns the number of bytes written.
6
+ """
7
+
8
+ import os
9
+
10
+ from ccai.agentkit.tool import Tool
11
+ from ccai.agentkit.toolerrors import ToolExecutionError
12
+
13
+
14
+ class FileWriteTool(Tool):
15
+ """
16
+ Writes content to a file at the specified path.
17
+
18
+ Accepts required file_path and content parameters, and an optional
19
+ encoding parameter (defaulting to utf-8). Returns the number of
20
+ bytes written. Raises ToolExecutionError for permission errors.
21
+ """
22
+
23
+ TOOL_NAME = "file_write"
24
+ TOOL_DESCRIPTION = "Writes content to a file at the specified path."
25
+ TOOL_VERSION = "1.0.0"
26
+
27
+ INPUT_SCHEMA = {
28
+ "parameters": [
29
+ {
30
+ "name": "file_path",
31
+ "type": "string",
32
+ "required": True,
33
+ "description": "Path to the file to write.",
34
+ },
35
+ {
36
+ "name": "content",
37
+ "type": "string",
38
+ "required": True,
39
+ "description": "Content to write.",
40
+ },
41
+ {
42
+ "name": "encoding",
43
+ "type": "string",
44
+ "required": False,
45
+ "default": "utf-8",
46
+ "description": "File encoding.",
47
+ },
48
+ ]
49
+ }
50
+
51
+ OUTPUT_SCHEMA = {
52
+ "parameters": [
53
+ {
54
+ "name": "bytes_written",
55
+ "type": "integer",
56
+ "required": True,
57
+ "description": "Number of bytes written.",
58
+ },
59
+ ]
60
+ }
61
+
62
+ def execute(self, inputs: dict, credentials: dict = None) -> dict:
63
+ """
64
+ Writes content to the file specified by the inputs.
65
+
66
+ :param inputs: Dictionary containing 'file_path', 'content', and optional 'encoding'.
67
+ :param credentials: Optional dictionary of resolved credentials (unused).
68
+
69
+ :returns: A dictionary with a 'bytes_written' key containing the byte count.
70
+
71
+ :raises: ToolExecutionError
72
+ """
73
+ file_path = inputs["file_path"]
74
+ content = inputs["content"]
75
+ encoding = inputs.get("encoding", "utf-8")
76
+
77
+ try:
78
+ content_bytes = content.encode(encoding)
79
+ with open(file_path, mode="wb") as file_handle:
80
+ file_handle.write(content_bytes)
81
+ except PermissionError as perm_err:
82
+ err_msg_lines = [
83
+ "Permission denied writing file: '{}'.".format(file_path),
84
+ "DETAIL: {}".format(str(perm_err)),
85
+ ]
86
+ err_msg = os.linesep.join(err_msg_lines)
87
+ raise ToolExecutionError(tool_name=self.TOOL_NAME, cause=PermissionError(err_msg)) from perm_err
88
+
89
+ bytes_written = len(content_bytes)
90
+
91
+ rtnval = {"bytes_written": bytes_written}
92
+
93
+ return rtnval
@@ -0,0 +1,169 @@
1
+ """
2
+ Built-in tool for making HTTP requests.
3
+
4
+ Provides the HttpRequestTool class which makes HTTP requests using
5
+ urllib and returns the response status code, headers, and body.
6
+ """
7
+
8
+ import os
9
+ import urllib.request
10
+ import urllib.error
11
+
12
+ from ccai.agentkit.tool import Tool
13
+ from ccai.agentkit.toolerrors import ToolExecutionError
14
+
15
+
16
+ class HttpRequestTool(Tool):
17
+ """
18
+ Makes an HTTP request to the specified URL.
19
+
20
+ Accepts required url and method parameters, and optional headers,
21
+ body, and timeout_seconds parameters. Returns the response status
22
+ code, headers, and body. Raises ToolExecutionError for timeout
23
+ and connection errors.
24
+ """
25
+
26
+ TOOL_NAME = "http_request"
27
+ TOOL_DESCRIPTION = "Makes an HTTP request to the specified URL."
28
+ TOOL_VERSION = "1.0.0"
29
+
30
+ INPUT_SCHEMA = {
31
+ "parameters": [
32
+ {
33
+ "name": "url",
34
+ "type": "string",
35
+ "required": True,
36
+ "description": "Request URL.",
37
+ },
38
+ {
39
+ "name": "method",
40
+ "type": "string",
41
+ "required": True,
42
+ "description": "HTTP method (GET, POST, PUT, DELETE, PATCH).",
43
+ },
44
+ {
45
+ "name": "headers",
46
+ "type": "dictionary",
47
+ "required": False,
48
+ "description": "Request headers.",
49
+ },
50
+ {
51
+ "name": "body",
52
+ "type": "string",
53
+ "required": False,
54
+ "description": "Request body.",
55
+ },
56
+ {
57
+ "name": "timeout_seconds",
58
+ "type": "float",
59
+ "required": False,
60
+ "default": 30.0,
61
+ "description": "Request timeout in seconds.",
62
+ },
63
+ ]
64
+ }
65
+
66
+ OUTPUT_SCHEMA = {
67
+ "parameters": [
68
+ {
69
+ "name": "status_code",
70
+ "type": "integer",
71
+ "required": True,
72
+ "description": "HTTP response status code.",
73
+ },
74
+ {
75
+ "name": "headers",
76
+ "type": "dictionary",
77
+ "required": True,
78
+ "description": "Response headers.",
79
+ },
80
+ {
81
+ "name": "body",
82
+ "type": "string",
83
+ "required": True,
84
+ "description": "Response body.",
85
+ },
86
+ ]
87
+ }
88
+
89
+ def execute(self, inputs: dict, credentials: dict = None) -> dict:
90
+ """
91
+ Makes an HTTP request using the provided inputs.
92
+
93
+ :param inputs: Dictionary containing 'url', 'method', and optional
94
+ 'headers', 'body', 'timeout_seconds'.
95
+ :param credentials: Optional dictionary of resolved credentials
96
+ for authentication headers.
97
+
98
+ :returns: A dictionary with 'status_code', 'headers', and 'body' keys.
99
+
100
+ :raises: ToolExecutionError
101
+ """
102
+ url = inputs["url"]
103
+ method = inputs["method"]
104
+ request_headers = inputs.get("headers", None)
105
+ body = inputs.get("body", None)
106
+ timeout_seconds = inputs.get("timeout_seconds", 30.0)
107
+
108
+ if request_headers is None:
109
+ request_headers = {}
110
+
111
+ if credentials is not None:
112
+ for cred_key, cred_value in credentials.items():
113
+ request_headers[cred_key] = cred_value
114
+
115
+ body_bytes = None
116
+ if body is not None:
117
+ body_bytes = body.encode("utf-8")
118
+
119
+ request = urllib.request.Request(
120
+ url=url,
121
+ data=body_bytes,
122
+ headers=request_headers,
123
+ method=method,
124
+ )
125
+
126
+ try:
127
+ response = urllib.request.urlopen(
128
+ url=request,
129
+ timeout=timeout_seconds,
130
+ )
131
+
132
+ status_code = response.status
133
+ response_headers = dict(response.getheaders())
134
+ response_body = response.read().decode("utf-8")
135
+
136
+ except urllib.error.HTTPError as http_err:
137
+ # HTTPError is a subclass of URLError and MUST be caught first; a
138
+ # 4xx/5xx is a real HTTP response whose status/headers/body we return
139
+ # rather than reclassifying it as a connection error below.
140
+ status_code = http_err.code
141
+ response_headers = dict(http_err.headers.items())
142
+ response_body = http_err.read().decode("utf-8")
143
+
144
+ except urllib.error.URLError as url_err:
145
+ if isinstance(url_err.reason, TimeoutError) or "timed out" in str(url_err):
146
+ err_msg_lines = [
147
+ "HTTP request timed out.",
148
+ "URL: {}".format(url),
149
+ "METHOD: {}".format(method),
150
+ "TIMEOUT: {} seconds".format(timeout_seconds),
151
+ ]
152
+ err_msg = os.linesep.join(err_msg_lines)
153
+ raise ToolExecutionError(tool_name=self.TOOL_NAME, cause=TimeoutError(err_msg)) from url_err
154
+
155
+ err_msg_lines = [
156
+ "HTTP request connection error.",
157
+ "URL: {}".format(url),
158
+ "DETAIL: {}".format(str(url_err)),
159
+ ]
160
+ err_msg = os.linesep.join(err_msg_lines)
161
+ raise ToolExecutionError(tool_name=self.TOOL_NAME, cause=ConnectionError(err_msg)) from url_err
162
+
163
+ rtnval = {
164
+ "status_code": status_code,
165
+ "headers": response_headers,
166
+ "body": response_body,
167
+ }
168
+
169
+ return rtnval