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,155 @@
1
+ """
2
+ Defines the MetricsSnapshot class representing an immutable
3
+ point-in-time snapshot of all metric values.
4
+
5
+ MetricsSnapshot objects contain a snapshot timestamp and a
6
+ dictionary of metric names to their current aggregated values
7
+ and labels. All fields are exposed as read-only properties to
8
+ preserve immutability after construction.
9
+ """
10
+
11
+ import json
12
+
13
+ from datetime import datetime
14
+ from typing import Optional
15
+
16
+
17
+ class MetricsSnapshot:
18
+ """
19
+ An immutable object representing a point-in-time snapshot of
20
+ all metric values.
21
+
22
+ Contains a snapshot timestamp and a dictionary of metric names
23
+ to their current aggregated values and labels.
24
+
25
+ :param timestamp: The timestamp when the snapshot was taken.
26
+ :param metrics: A dictionary mapping metric names to their
27
+ current values and labels.
28
+ """
29
+
30
+ def __init__(self, timestamp: datetime, metrics: dict) -> None:
31
+
32
+ self._timestamp = timestamp
33
+ self._metrics = dict(metrics)
34
+
35
+ return
36
+
37
+ @property
38
+ def timestamp(self) -> datetime:
39
+ """
40
+ The timestamp when the snapshot was taken.
41
+
42
+ :returns: The datetime timestamp.
43
+ """
44
+ return self._timestamp
45
+
46
+ @property
47
+ def metrics(self) -> dict:
48
+ """
49
+ A copy of the metrics dictionary mapping metric names to
50
+ their current values and labels. Returns a copy to preserve
51
+ immutability.
52
+
53
+ :returns: A dictionary copy of the metrics data.
54
+ """
55
+ result = dict(self._metrics)
56
+ return result
57
+
58
+ def get_metric(self, name: str) -> Optional[dict]:
59
+ """
60
+ Returns the current value and labels for the specified metric
61
+ name, or None when the metric has no recorded values.
62
+
63
+ :param name: The metric name to look up.
64
+
65
+ :returns: A dictionary containing the metric value and labels,
66
+ or None if the metric is not found.
67
+ """
68
+ result = self._metrics.get(name, None)
69
+ return result
70
+
71
+ def as_dict(self) -> dict:
72
+ """
73
+ Returns a dictionary representation of the snapshot fields.
74
+
75
+ The timestamp is serialized as an ISO format string for
76
+ consistent representation.
77
+
78
+ :returns: A dictionary containing all snapshot fields.
79
+ """
80
+ result = {
81
+ "timestamp": self._timestamp.isoformat(),
82
+ "metrics": dict(self._metrics)
83
+ }
84
+ return result
85
+
86
+ def to_json(self) -> str:
87
+ """
88
+ Returns a JSON string representation of the snapshot fields.
89
+
90
+ :returns: A JSON string containing all snapshot fields.
91
+ """
92
+ data = self.as_dict()
93
+ json_str = json.dumps(data)
94
+ return json_str
95
+
96
+ @classmethod
97
+ def from_dict(cls, data: dict) -> "MetricsSnapshot":
98
+ """
99
+ Constructs a MetricsSnapshot from a dictionary.
100
+
101
+ The timestamp field is expected to be an ISO format string
102
+ and is parsed back into a datetime object.
103
+
104
+ :param data: A dictionary containing snapshot fields.
105
+
106
+ :returns: A MetricsSnapshot instance reconstructed from
107
+ the dictionary.
108
+ """
109
+ timestamp = datetime.fromisoformat(data["timestamp"])
110
+ metrics = data.get("metrics", {})
111
+
112
+ snapshot = cls(
113
+ timestamp=timestamp,
114
+ metrics=metrics
115
+ )
116
+ return snapshot
117
+
118
+ @classmethod
119
+ def from_json(cls, json_str: str) -> "MetricsSnapshot":
120
+ """
121
+ Deserializes a JSON string into a MetricsSnapshot instance.
122
+
123
+ :param json_str: A JSON string containing snapshot fields.
124
+
125
+ :returns: A MetricsSnapshot instance reconstructed from
126
+ the JSON data.
127
+ """
128
+ data = json.loads(json_str)
129
+ snapshot = cls.from_dict(data)
130
+ return snapshot
131
+
132
+ def __repr__(self) -> str:
133
+ """
134
+ Returns a detailed string representation including class name,
135
+ snapshot timestamp, and the count of metrics.
136
+
137
+ :returns: A repr string for debugging.
138
+ """
139
+ repr_str = "MetricsSnapshot(timestamp={!r}, metric_count={})".format(
140
+ self._timestamp.isoformat(), len(self._metrics)
141
+ )
142
+ return repr_str
143
+
144
+ def __str__(self) -> str:
145
+ """
146
+ Returns a human-readable summary including the snapshot
147
+ timestamp and the list of metric names.
148
+
149
+ :returns: A human-readable string.
150
+ """
151
+ metric_names = list(self._metrics.keys())
152
+ str_val = "MetricsSnapshot: timestamp={}, metrics={}".format(
153
+ self._timestamp.isoformat(), metric_names
154
+ )
155
+ return str_val
@@ -0,0 +1,51 @@
1
+ """
2
+ Defines the MetricType enumeration for classifying metrics as
3
+ COUNTER, GAUGE, or HISTOGRAM.
4
+
5
+ MetricType provides a from_string class method for converting
6
+ string values to enum members, raising SemanticError for invalid
7
+ values.
8
+ """
9
+
10
+ import enum
11
+
12
+ from ccai.agentkit.errors import SemanticError
13
+
14
+
15
+ class MetricType(enum.Enum):
16
+ """
17
+ Enumeration defining the type of a metric.
18
+
19
+ COUNTER represents a monotonically increasing value.
20
+ GAUGE represents a value that can increase or decrease.
21
+ HISTOGRAM represents a distribution of values.
22
+ """
23
+
24
+ COUNTER = "COUNTER"
25
+ GAUGE = "GAUGE"
26
+ HISTOGRAM = "HISTOGRAM"
27
+
28
+ @classmethod
29
+ def from_string(cls, value: str) -> "MetricType":
30
+ """
31
+ Converts a string value to the corresponding MetricType member.
32
+
33
+ The comparison is case-sensitive against the enum value strings.
34
+
35
+ :param value: A string representing the metric type.
36
+
37
+ :returns: The corresponding MetricType member.
38
+
39
+ :raises SemanticError: If the value does not match any valid
40
+ metric type.
41
+ """
42
+ for member in cls:
43
+ if member.value == value:
44
+ return member
45
+
46
+ valid_values = [m.value for m in cls]
47
+ raise SemanticError(
48
+ "Invalid metric type value: {!r}. Valid values are: {}".format(
49
+ value, valid_values
50
+ )
51
+ )
@@ -0,0 +1,97 @@
1
+ """
2
+ Defines the MsgpackMessageSerializer class for serializing Python
3
+ objects to MessagePack-encoded bytes and deserializing MessagePack-
4
+ encoded bytes to Python objects.
5
+
6
+ Uses the msgpack library for encoding and decoding. The msgpack
7
+ package (msgpack-python) must be installed for this serializer to
8
+ function. If msgpack is not available, importing this module will
9
+ succeed but instantiation will raise an ImportError.
10
+
11
+ .. module:: ccai.agentkit.msgpackmessageserializer
12
+ :platform: Darwin, Linux, Unix, Windows
13
+ :synopsis: MessagePack serialization implementation for message payloads.
14
+
15
+ Requirements: 9.6, 9.10
16
+ """
17
+
18
+ from ccai.agentkit.messageserializer import MessageSerializer
19
+ from ccai.agentkit.messagingerrors import MessageSerializationError
20
+
21
+ try:
22
+ import msgpack
23
+ _MSGPACK_AVAILABLE = True
24
+ except ImportError:
25
+ _MSGPACK_AVAILABLE = False
26
+
27
+
28
+ class MsgpackMessageSerializer(MessageSerializer):
29
+ """
30
+ Serializes Python objects to MessagePack-encoded bytes and
31
+ deserializes MessagePack-encoded bytes to Python objects.
32
+
33
+ Requires the msgpack package to be installed. Raises
34
+ ImportError at construction time if msgpack is not available.
35
+ """
36
+
37
+ def __init__(self) -> None:
38
+ if _MSGPACK_AVAILABLE is not True:
39
+ raise ImportError(
40
+ "The 'msgpack' package is required for MsgpackMessageSerializer. "
41
+ "Install it with: pip install msgpack"
42
+ )
43
+
44
+ super().__init__(format_name="msgpack", content_type="application/x-msgpack")
45
+ return
46
+
47
+ def serialize(self, obj: object) -> bytes:
48
+ """
49
+ Serializes a Python object to MessagePack-encoded bytes.
50
+
51
+ :param obj: The Python object to serialize. Must be
52
+ MessagePack-serializable.
53
+
54
+ :returns: The MessagePack-encoded bytes.
55
+ :raises MessageSerializationError: If the object cannot be
56
+ serialized to MessagePack format.
57
+ """
58
+ try:
59
+ rtnval = msgpack.packb(obj, use_bin_type=True)
60
+ except (TypeError, ValueError, OverflowError) as ex:
61
+ object_type = type(obj).__name__
62
+ detail = "Object of type '{}' is not MessagePack serializable: {}".format(
63
+ object_type, ex
64
+ )
65
+ raise MessageSerializationError(
66
+ format_name="msgpack",
67
+ direction="serialize",
68
+ detail=detail
69
+ ) from ex
70
+
71
+ return rtnval
72
+
73
+ def deserialize(self, data: bytes) -> object:
74
+ """
75
+ Deserializes MessagePack-encoded bytes to a Python object.
76
+
77
+ :param data: The MessagePack-encoded bytes to deserialize.
78
+
79
+ :returns: The deserialized Python object.
80
+ :raises MessageSerializationError: If the bytes are not
81
+ valid MessagePack. The error detail includes the bytes
82
+ length.
83
+ """
84
+ try:
85
+ rtnval = msgpack.unpackb(data, raw=False)
86
+ except (msgpack.UnpackException, ValueError, TypeError) as ex:
87
+ bytes_length = len(data)
88
+ detail = "Invalid MessagePack input ({} bytes): {}".format(
89
+ bytes_length, ex
90
+ )
91
+ raise MessageSerializationError(
92
+ format_name="msgpack",
93
+ direction="deserialize",
94
+ detail=detail
95
+ ) from ex
96
+
97
+ return rtnval