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.
- ccai/agentkit/__init__.py +304 -0
- ccai/agentkit/addressresolver.py +177 -0
- ccai/agentkit/agent.py +2945 -0
- ccai/agentkit/agentaddress.py +187 -0
- ccai/agentkit/agentconfiguration.py +581 -0
- ccai/agentkit/agentidentity.py +152 -0
- ccai/agentkit/agentregistry.py +221 -0
- ccai/agentkit/agentstatemachine.py +134 -0
- ccai/agentkit/alternateproviderstrategy.py +36 -0
- ccai/agentkit/approvalgate.py +238 -0
- ccai/agentkit/approvalrequest.py +250 -0
- ccai/agentkit/asyncagent.py +187 -0
- ccai/agentkit/breakpoint.py +150 -0
- ccai/agentkit/builtinagentmetrics.py +114 -0
- ccai/agentkit/builtins/__init__.py +11 -0
- ccai/agentkit/builtins/filereadtool.py +90 -0
- ccai/agentkit/builtins/filewritetool.py +93 -0
- ccai/agentkit/builtins/httprequesttool.py +169 -0
- ccai/agentkit/builtins/shellcommandtool.py +190 -0
- ccai/agentkit/cachedresultstrategy.py +43 -0
- ccai/agentkit/checkpointmanager.py +219 -0
- ccai/agentkit/circuitbreaker.py +230 -0
- ccai/agentkit/circuitbreakerconfiguration.py +158 -0
- ccai/agentkit/circuitbreakerevent.py +158 -0
- ccai/agentkit/circuitbreakerhealthcheck.py +32 -0
- ccai/agentkit/circuitbreakerregistry.py +116 -0
- ccai/agentkit/circuitbreakerstate.py +44 -0
- ccai/agentkit/clearcacheaction.py +46 -0
- ccai/agentkit/concurrencybridge.py +143 -0
- ccai/agentkit/concurrencymodel.py +19 -0
- ccai/agentkit/conditionevaluator.py +594 -0
- ccai/agentkit/configurationchangeevent.py +179 -0
- ccai/agentkit/configurationerrors.py +152 -0
- ccai/agentkit/configurationlayer.py +160 -0
- ccai/agentkit/configurationlayersource.py +46 -0
- ccai/agentkit/configurationmanager.py +680 -0
- ccai/agentkit/configurationschema.py +224 -0
- ccai/agentkit/configurationschemafield.py +217 -0
- ccai/agentkit/configurationserializer.py +163 -0
- ccai/agentkit/configurationvalidationresult.py +118 -0
- ccai/agentkit/contextsummarizer.py +170 -0
- ccai/agentkit/contextwindow.py +264 -0
- ccai/agentkit/contextwindowstrategy.py +57 -0
- ccai/agentkit/correlationcontext.py +156 -0
- ccai/agentkit/costestimate.py +139 -0
- ccai/agentkit/costtracker.py +121 -0
- ccai/agentkit/deadletterentry.py +134 -0
- ccai/agentkit/deadletterquery.py +119 -0
- ccai/agentkit/deadletterqueue.py +123 -0
- ccai/agentkit/deadletterstore.py +86 -0
- ccai/agentkit/debuginspector.py +211 -0
- ccai/agentkit/debugsession.py +223 -0
- ccai/agentkit/defaultvaluestrategy.py +43 -0
- ccai/agentkit/degradationchangeevent.py +120 -0
- ccai/agentkit/degradationlevel.py +44 -0
- ccai/agentkit/degradationmanager.py +212 -0
- ccai/agentkit/degradationpolicy.py +130 -0
- ccai/agentkit/degradationstrategy.py +66 -0
- ccai/agentkit/embeddingprovider.py +106 -0
- ccai/agentkit/errors.py +95 -0
- ccai/agentkit/executionrecord.py +213 -0
- ccai/agentkit/executionrecorder.py +180 -0
- ccai/agentkit/executionrecording.py +230 -0
- ccai/agentkit/executionreplayer.py +187 -0
- ccai/agentkit/expirationpolicy.py +116 -0
- ccai/agentkit/fallbackchain.py +82 -0
- ccai/agentkit/featureflag.py +154 -0
- ccai/agentkit/featureflagevaluator.py +109 -0
- ccai/agentkit/featureflagregistry.py +258 -0
- ccai/agentkit/filedeadletterstore.py +112 -0
- ccai/agentkit/filememorystore.py +291 -0
- ccai/agentkit/healthcheck.py +46 -0
- ccai/agentkit/healthcheckregistry.py +51 -0
- ccai/agentkit/healthmonitor.py +258 -0
- ccai/agentkit/healthstatus.py +105 -0
- ccai/agentkit/hotreloadmonitor.py +214 -0
- ccai/agentkit/hotreloadpolicy.py +160 -0
- ccai/agentkit/inmemorydeadletterstore.py +61 -0
- ccai/agentkit/inmemorystore.py +173 -0
- ccai/agentkit/jsonmessageserializer.py +89 -0
- ccai/agentkit/jsonoutputparser.py +50 -0
- ccai/agentkit/lifecyclestate.py +22 -0
- ccai/agentkit/llmconversation.py +153 -0
- ccai/agentkit/llmerrors.py +193 -0
- ccai/agentkit/llmmessage.py +158 -0
- ccai/agentkit/llmprovider.py +158 -0
- ccai/agentkit/llmproviderregistry.py +200 -0
- ccai/agentkit/llmresponse.py +190 -0
- ccai/agentkit/llmstreamchunk.py +65 -0
- ccai/agentkit/llmstreamhandler.py +48 -0
- ccai/agentkit/llmtoolbridge.py +154 -0
- ccai/agentkit/logexporter.py +316 -0
- ccai/agentkit/logformatter.py +169 -0
- ccai/agentkit/memoryconfiguration.py +243 -0
- ccai/agentkit/memoryentry.py +254 -0
- ccai/agentkit/memoryerrors.py +135 -0
- ccai/agentkit/memoryindex.py +213 -0
- ccai/agentkit/memoryquery.py +248 -0
- ccai/agentkit/memoryqueryresult.py +86 -0
- ccai/agentkit/memoryscope.py +54 -0
- ccai/agentkit/memorystore.py +260 -0
- ccai/agentkit/memorystorehealthcheck.py +33 -0
- ccai/agentkit/memorystoreregistry.py +106 -0
- ccai/agentkit/message.py +310 -0
- ccai/agentkit/messageenvelope.py +144 -0
- ccai/agentkit/messagepattern.py +50 -0
- ccai/agentkit/messagerouter.py +290 -0
- ccai/agentkit/messageserializer.py +106 -0
- ccai/agentkit/messageserializerregistry.py +163 -0
- ccai/agentkit/messagingconfiguration.py +397 -0
- ccai/agentkit/messagingerrors.py +338 -0
- ccai/agentkit/metricdefinition.py +164 -0
- ccai/agentkit/metricmeasurement.py +178 -0
- ccai/agentkit/metricscollector.py +258 -0
- ccai/agentkit/metricsexporter.py +303 -0
- ccai/agentkit/metricsregistry.py +130 -0
- ccai/agentkit/metricssnapshot.py +155 -0
- ccai/agentkit/metrictype.py +51 -0
- ccai/agentkit/msgpackmessageserializer.py +97 -0
- ccai/agentkit/observabilityconfiguration.py +546 -0
- ccai/agentkit/observabilityerror.py +67 -0
- ccai/agentkit/observabilitypipeline.py +252 -0
- ccai/agentkit/outputparser.py +82 -0
- ccai/agentkit/outputschema.py +142 -0
- ccai/agentkit/parallelbranch.py +87 -0
- ccai/agentkit/platform/__init__.py +43 -0
- ccai/agentkit/platform/adapters/__init__.py +18 -0
- ccai/agentkit/platform/adapters/awsplatformadapter.py +1272 -0
- ccai/agentkit/platform/adapters/azureplatformadapter.py +1227 -0
- ccai/agentkit/platform/adapters/gcpplatformadapter.py +1257 -0
- ccai/agentkit/platform/adapters/localplatformadapter.py +956 -0
- ccai/agentkit/platform/adapters/platformadapter.py +139 -0
- ccai/agentkit/platform/deployment/__init__.py +15 -0
- ccai/agentkit/platform/deployment/deploymentdescriptor.py +234 -0
- ccai/agentkit/platform/deployment/deploymentdescriptorparser.py +178 -0
- ccai/agentkit/platform/deployment/deploymentdescriptorprinter.py +97 -0
- ccai/agentkit/platform/errors.py +224 -0
- ccai/agentkit/platform/platformconfiguration.py +412 -0
- ccai/agentkit/platform/platformdetector.py +125 -0
- ccai/agentkit/platform/platformruntime.py +331 -0
- ccai/agentkit/platform/platformserviceregistry.py +149 -0
- ccai/agentkit/platform/platformtype.py +60 -0
- ccai/agentkit/platform/services/__init__.py +19 -0
- ccai/agentkit/platform/services/computeservice.py +112 -0
- ccai/agentkit/platform/services/invocationresult.py +173 -0
- ccai/agentkit/platform/services/messagingservice.py +135 -0
- ccai/agentkit/platform/services/platformservice.py +111 -0
- ccai/agentkit/platform/services/queuemessage.py +193 -0
- ccai/agentkit/platform/services/storageobject.py +195 -0
- ccai/agentkit/platform/services/storageservice.py +159 -0
- ccai/agentkit/pluginconfiguration.py +241 -0
- ccai/agentkit/plugindependency.py +129 -0
- ccai/agentkit/plugindescriptor.py +225 -0
- ccai/agentkit/pluginlifecyclehook.py +41 -0
- ccai/agentkit/pluginmanager.py +360 -0
- ccai/agentkit/pluginstatus.py +47 -0
- ccai/agentkit/pooledagent.py +116 -0
- ccai/agentkit/prompttemplate.py +221 -0
- ccai/agentkit/prompttemplateregistry.py +145 -0
- ccai/agentkit/protobufmessageserializer.py +144 -0
- ccai/agentkit/pubsubbroker.py +311 -0
- ccai/agentkit/py.typed +0 -0
- ccai/agentkit/reconnecttransportaction.py +47 -0
- ccai/agentkit/regexoutputparser.py +68 -0
- ccai/agentkit/requestresponsehandler.py +274 -0
- ccai/agentkit/resetcircuitbreakeraction.py +48 -0
- ccai/agentkit/resilienceconfiguration.py +191 -0
- ccai/agentkit/resilienceerrors.py +103 -0
- ccai/agentkit/resiliencepipeline.py +201 -0
- ccai/agentkit/retryattempt.py +158 -0
- ccai/agentkit/retryexecutor.py +157 -0
- ccai/agentkit/retrypolicy.py +195 -0
- ccai/agentkit/retryresult.py +186 -0
- ccai/agentkit/selfhealingaction.py +42 -0
- ccai/agentkit/selfhealingpolicy.py +67 -0
- ccai/agentkit/selfhealingresult.py +130 -0
- ccai/agentkit/stepexecutionstatus.py +52 -0
- ccai/agentkit/stepresult.py +198 -0
- ccai/agentkit/steps/__init__.py +9 -0
- ccai/agentkit/steps/agentstep.py +247 -0
- ccai/agentkit/steps/approvalstep.py +276 -0
- ccai/agentkit/steps/llmstep.py +403 -0
- ccai/agentkit/steps/subworkflowstep.py +270 -0
- ccai/agentkit/steps/toolstep.py +265 -0
- ccai/agentkit/structuredlogentry.py +222 -0
- ccai/agentkit/structuredlogger.py +189 -0
- ccai/agentkit/subscription.py +141 -0
- ccai/agentkit/threadedagent.py +94 -0
- ccai/agentkit/tokenusage.py +136 -0
- ccai/agentkit/tool.py +203 -0
- ccai/agentkit/toolchain.py +268 -0
- ccai/agentkit/toolchainexecutor.py +134 -0
- ccai/agentkit/toolchainresult.py +166 -0
- ccai/agentkit/tooldescriptor.py +203 -0
- ccai/agentkit/toolerrors.py +160 -0
- ccai/agentkit/toolexecutor.py +168 -0
- ccai/agentkit/toolfactory.py +60 -0
- ccai/agentkit/toolregistry.py +184 -0
- ccai/agentkit/toolresult.py +142 -0
- ccai/agentkit/toolschema.py +197 -0
- ccai/agentkit/tracecontext.py +294 -0
- ccai/agentkit/traceevent.py +166 -0
- ccai/agentkit/traceexporter.py +305 -0
- ccai/agentkit/tracer.py +234 -0
- ccai/agentkit/tracespan.py +349 -0
- ccai/agentkit/transitionrecord.py +84 -0
- ccai/agentkit/transport.py +334 -0
- ccai/agentkit/transportconfiguration.py +436 -0
- ccai/agentkit/transporthealthcheck.py +36 -0
- ccai/agentkit/transportregistry.py +224 -0
- ccai/agentkit/transports/__init__.py +28 -0
- ccai/agentkit/transports/grpctransport.py +410 -0
- ccai/agentkit/transports/httptransport.py +423 -0
- ccai/agentkit/transports/messagequeuetransport.py +489 -0
- ccai/agentkit/transports/websockettransport.py +473 -0
- ccai/agentkit/workflowcheckpoint.py +208 -0
- ccai/agentkit/workflowconfiguration.py +295 -0
- ccai/agentkit/workflowcontext.py +249 -0
- ccai/agentkit/workflowdefinition.py +790 -0
- ccai/agentkit/workflowedge.py +128 -0
- ccai/agentkit/workflowerrors.py +295 -0
- ccai/agentkit/workflowexecutionstatus.py +48 -0
- ccai/agentkit/workflowexecutor.py +1121 -0
- ccai/agentkit/workflowregistry.py +185 -0
- ccai/agentkit/workflowresult.py +250 -0
- ccai/agentkit/workflowstep.py +195 -0
- codecraftai_agent_kit-1.3.0.dist-info/METADATA +99 -0
- codecraftai_agent_kit-1.3.0.dist-info/RECORD +230 -0
- codecraftai_agent_kit-1.3.0.dist-info/WHEEL +4 -0
- codecraftai_agent_kit-1.3.0.dist-info/licenses/LICENSE.md +204 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Exception classes for the Communication & Messaging feature.
|
|
3
|
+
|
|
4
|
+
Provides TransportError for transport operation failures,
|
|
5
|
+
NoMessageAvailableError for a receive that finds no waiting message,
|
|
6
|
+
MessageSerializationError for serialization and deserialization failures,
|
|
7
|
+
MessageRoutingError for routing and address resolution failures,
|
|
8
|
+
and MessageTimeoutError for request/response timeout conditions.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import Optional
|
|
12
|
+
|
|
13
|
+
from ccai.agentkit.errors import AgentKitError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TransportError(AgentKitError):
|
|
17
|
+
"""
|
|
18
|
+
Raised when a Transport operation fails due to a connection, send,
|
|
19
|
+
or receive error.
|
|
20
|
+
|
|
21
|
+
:param transport_name: The name of the transport where the error occurred.
|
|
22
|
+
:param operation: The operation that failed (e.g. 'connect', 'disconnect',
|
|
23
|
+
'send', 'receive').
|
|
24
|
+
:param cause: An optional exception that caused the failure.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, transport_name: str, operation: str, cause: Optional[Exception] = None) -> None:
|
|
28
|
+
self._transport_name = transport_name
|
|
29
|
+
self._operation = operation
|
|
30
|
+
self._cause_exception = cause
|
|
31
|
+
|
|
32
|
+
errmsg = self._format_message()
|
|
33
|
+
super().__init__(errmsg, cause=cause)
|
|
34
|
+
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def transport_name(self) -> str:
|
|
39
|
+
"""
|
|
40
|
+
The name of the transport where the error occurred.
|
|
41
|
+
|
|
42
|
+
:returns: The transport name string.
|
|
43
|
+
"""
|
|
44
|
+
return self._transport_name
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def operation(self) -> str:
|
|
48
|
+
"""
|
|
49
|
+
The operation that failed.
|
|
50
|
+
|
|
51
|
+
:returns: The operation string (e.g. 'connect', 'disconnect',
|
|
52
|
+
'send', 'receive').
|
|
53
|
+
"""
|
|
54
|
+
return self._operation
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def cause(self) -> Optional[Exception]:
|
|
58
|
+
"""
|
|
59
|
+
The optional exception that caused the failure.
|
|
60
|
+
|
|
61
|
+
:returns: The cause exception or None.
|
|
62
|
+
"""
|
|
63
|
+
return self._cause_exception
|
|
64
|
+
|
|
65
|
+
def _format_message(self) -> str:
|
|
66
|
+
"""
|
|
67
|
+
Builds a descriptive error message from the transport name,
|
|
68
|
+
operation, and optional cause.
|
|
69
|
+
|
|
70
|
+
:returns: A formatted error message string.
|
|
71
|
+
"""
|
|
72
|
+
errmsg = "Transport '{}' failed during {} operation".format(
|
|
73
|
+
self._transport_name, self._operation
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if self._cause_exception is not None:
|
|
77
|
+
errmsg = "{}: {}".format(errmsg, self._cause_exception)
|
|
78
|
+
|
|
79
|
+
return errmsg
|
|
80
|
+
|
|
81
|
+
def __repr__(self) -> str:
|
|
82
|
+
"""
|
|
83
|
+
Returns a detailed string representation including class name,
|
|
84
|
+
transport name, operation, and cause.
|
|
85
|
+
|
|
86
|
+
:returns: A repr string for debugging.
|
|
87
|
+
"""
|
|
88
|
+
repr_str = "{}(transport_name={!r}, operation={!r}, cause={!r})".format(
|
|
89
|
+
self.__class__.__name__, self._transport_name, self._operation,
|
|
90
|
+
self._cause_exception
|
|
91
|
+
)
|
|
92
|
+
return repr_str
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class NoMessageAvailableError(TransportError):
|
|
96
|
+
"""
|
|
97
|
+
Raised by the receive method of a pull-based Transport, such as the
|
|
98
|
+
MessageQueueTransport, when no message is waiting to be received.
|
|
99
|
+
|
|
100
|
+
It derives from TransportError so code that catches TransportError
|
|
101
|
+
around receive keeps working. The Agent receive path treats it as
|
|
102
|
+
"nothing received yet" instead of as a failure.
|
|
103
|
+
|
|
104
|
+
:param transport_name: The name of the transport that had no message.
|
|
105
|
+
:param operation: The operation that found no message, 'receive'.
|
|
106
|
+
:param cause: An optional exception describing the empty source.
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class MessageSerializationError(AgentKitError):
|
|
111
|
+
"""
|
|
112
|
+
Raised when a MessageSerializer fails to serialize or deserialize
|
|
113
|
+
a message payload.
|
|
114
|
+
|
|
115
|
+
:param format_name: The serializer format name (e.g. 'json', 'msgpack',
|
|
116
|
+
'protobuf').
|
|
117
|
+
:param direction: The serialization direction ('serialize' or 'deserialize').
|
|
118
|
+
:param detail: A descriptive string identifying the serialization problem.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
def __init__(self, format_name: str, direction: str, detail: str) -> None:
|
|
122
|
+
self._format_name = format_name
|
|
123
|
+
self._direction = direction
|
|
124
|
+
self._detail = detail
|
|
125
|
+
|
|
126
|
+
errmsg = self._format_message()
|
|
127
|
+
super().__init__(errmsg)
|
|
128
|
+
|
|
129
|
+
return
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def format_name(self) -> str:
|
|
133
|
+
"""
|
|
134
|
+
The serializer format name.
|
|
135
|
+
|
|
136
|
+
:returns: The format name string (e.g. 'json', 'msgpack', 'protobuf').
|
|
137
|
+
"""
|
|
138
|
+
return self._format_name
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def direction(self) -> str:
|
|
142
|
+
"""
|
|
143
|
+
The serialization direction that failed.
|
|
144
|
+
|
|
145
|
+
:returns: The direction string ('serialize' or 'deserialize').
|
|
146
|
+
"""
|
|
147
|
+
return self._direction
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def detail(self) -> str:
|
|
151
|
+
"""
|
|
152
|
+
A descriptive string identifying the serialization problem.
|
|
153
|
+
|
|
154
|
+
:returns: The detail string.
|
|
155
|
+
"""
|
|
156
|
+
return self._detail
|
|
157
|
+
|
|
158
|
+
def _format_message(self) -> str:
|
|
159
|
+
"""
|
|
160
|
+
Builds a descriptive error message from the format name,
|
|
161
|
+
direction, and detail.
|
|
162
|
+
|
|
163
|
+
:returns: A formatted error message string.
|
|
164
|
+
"""
|
|
165
|
+
errmsg = "Serialization error in '{}' during {}: {}".format(
|
|
166
|
+
self._format_name, self._direction, self._detail
|
|
167
|
+
)
|
|
168
|
+
return errmsg
|
|
169
|
+
|
|
170
|
+
def __repr__(self) -> str:
|
|
171
|
+
"""
|
|
172
|
+
Returns a detailed string representation including class name,
|
|
173
|
+
format name, direction, and detail.
|
|
174
|
+
|
|
175
|
+
:returns: A repr string for debugging.
|
|
176
|
+
"""
|
|
177
|
+
repr_str = "{}(format_name={!r}, direction={!r}, detail={!r})".format(
|
|
178
|
+
self.__class__.__name__, self._format_name, self._direction,
|
|
179
|
+
self._detail
|
|
180
|
+
)
|
|
181
|
+
return repr_str
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class MessageRoutingError(AgentKitError):
|
|
185
|
+
"""
|
|
186
|
+
Raised when the MessageRouter or AddressResolver cannot route or resolve
|
|
187
|
+
a message destination.
|
|
188
|
+
|
|
189
|
+
:param message_id: The message identifier, when available.
|
|
190
|
+
:param target: The target agent identifier or topic.
|
|
191
|
+
:param detail: A descriptive string identifying the routing problem.
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
def __init__(self, message_id: Optional[str] = None, target: Optional[str] = None,
|
|
195
|
+
detail: Optional[str] = None) -> None:
|
|
196
|
+
self._message_id = message_id
|
|
197
|
+
self._target = target
|
|
198
|
+
self._detail = detail
|
|
199
|
+
|
|
200
|
+
errmsg = self._format_message()
|
|
201
|
+
super().__init__(errmsg)
|
|
202
|
+
|
|
203
|
+
return
|
|
204
|
+
|
|
205
|
+
@property
|
|
206
|
+
def message_id(self) -> Optional[str]:
|
|
207
|
+
"""
|
|
208
|
+
The message identifier, when available.
|
|
209
|
+
|
|
210
|
+
:returns: The message identifier string or None.
|
|
211
|
+
"""
|
|
212
|
+
return self._message_id
|
|
213
|
+
|
|
214
|
+
@property
|
|
215
|
+
def target(self) -> Optional[str]:
|
|
216
|
+
"""
|
|
217
|
+
The target agent identifier or topic.
|
|
218
|
+
|
|
219
|
+
:returns: The target string or None.
|
|
220
|
+
"""
|
|
221
|
+
return self._target
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def detail(self) -> Optional[str]:
|
|
225
|
+
"""
|
|
226
|
+
A descriptive string identifying the routing problem.
|
|
227
|
+
|
|
228
|
+
:returns: The detail string or None.
|
|
229
|
+
"""
|
|
230
|
+
return self._detail
|
|
231
|
+
|
|
232
|
+
def _format_message(self) -> str:
|
|
233
|
+
"""
|
|
234
|
+
Builds a descriptive error message from the message identifier,
|
|
235
|
+
target, and detail.
|
|
236
|
+
|
|
237
|
+
:returns: A formatted error message string.
|
|
238
|
+
"""
|
|
239
|
+
parts = ["Message routing failed"]
|
|
240
|
+
|
|
241
|
+
if self._target is not None:
|
|
242
|
+
parts.append("for target '{}'".format(self._target))
|
|
243
|
+
|
|
244
|
+
if self._message_id is not None:
|
|
245
|
+
parts.append("(message_id='{}')".format(self._message_id))
|
|
246
|
+
|
|
247
|
+
if self._detail is not None:
|
|
248
|
+
parts.append(": {}".format(self._detail))
|
|
249
|
+
|
|
250
|
+
errmsg = " ".join(parts)
|
|
251
|
+
return errmsg
|
|
252
|
+
|
|
253
|
+
def __repr__(self) -> str:
|
|
254
|
+
"""
|
|
255
|
+
Returns a detailed string representation including class name,
|
|
256
|
+
message identifier, target, and detail.
|
|
257
|
+
|
|
258
|
+
:returns: A repr string for debugging.
|
|
259
|
+
"""
|
|
260
|
+
repr_str = "{}(message_id={!r}, target={!r}, detail={!r})".format(
|
|
261
|
+
self.__class__.__name__, self._message_id, self._target,
|
|
262
|
+
self._detail
|
|
263
|
+
)
|
|
264
|
+
return repr_str
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class MessageTimeoutError(AgentKitError):
|
|
268
|
+
"""
|
|
269
|
+
Raised when a request/response exchange exceeds the configured timeout
|
|
270
|
+
duration.
|
|
271
|
+
|
|
272
|
+
:param request_message_id: The request message identifier.
|
|
273
|
+
:param correlation_id: The correlation identifier for the request/response
|
|
274
|
+
exchange.
|
|
275
|
+
:param timeout: The timeout duration in seconds.
|
|
276
|
+
"""
|
|
277
|
+
|
|
278
|
+
def __init__(self, request_message_id: str, correlation_id: str, timeout: float) -> None:
|
|
279
|
+
self._request_message_id = request_message_id
|
|
280
|
+
self._correlation_id = correlation_id
|
|
281
|
+
self._timeout = timeout
|
|
282
|
+
|
|
283
|
+
errmsg = self._format_message()
|
|
284
|
+
super().__init__(errmsg)
|
|
285
|
+
|
|
286
|
+
return
|
|
287
|
+
|
|
288
|
+
@property
|
|
289
|
+
def request_message_id(self) -> str:
|
|
290
|
+
"""
|
|
291
|
+
The request message identifier.
|
|
292
|
+
|
|
293
|
+
:returns: The request message identifier string.
|
|
294
|
+
"""
|
|
295
|
+
return self._request_message_id
|
|
296
|
+
|
|
297
|
+
@property
|
|
298
|
+
def correlation_id(self) -> str:
|
|
299
|
+
"""
|
|
300
|
+
The correlation identifier for the request/response exchange.
|
|
301
|
+
|
|
302
|
+
:returns: The correlation identifier string.
|
|
303
|
+
"""
|
|
304
|
+
return self._correlation_id
|
|
305
|
+
|
|
306
|
+
@property
|
|
307
|
+
def timeout(self) -> float:
|
|
308
|
+
"""
|
|
309
|
+
The timeout duration in seconds.
|
|
310
|
+
|
|
311
|
+
:returns: The timeout value as a float.
|
|
312
|
+
"""
|
|
313
|
+
return self._timeout
|
|
314
|
+
|
|
315
|
+
def _format_message(self) -> str:
|
|
316
|
+
"""
|
|
317
|
+
Builds a descriptive error message from the request message identifier,
|
|
318
|
+
correlation identifier, and timeout duration.
|
|
319
|
+
|
|
320
|
+
:returns: A formatted error message string.
|
|
321
|
+
"""
|
|
322
|
+
errmsg = "Request '{}' with correlation '{}' timed out after {} seconds".format(
|
|
323
|
+
self._request_message_id, self._correlation_id, self._timeout
|
|
324
|
+
)
|
|
325
|
+
return errmsg
|
|
326
|
+
|
|
327
|
+
def __repr__(self) -> str:
|
|
328
|
+
"""
|
|
329
|
+
Returns a detailed string representation including class name,
|
|
330
|
+
request message identifier, correlation identifier, and timeout.
|
|
331
|
+
|
|
332
|
+
:returns: A repr string for debugging.
|
|
333
|
+
"""
|
|
334
|
+
repr_str = "{}(request_message_id={!r}, correlation_id={!r}, timeout={!r})".format(
|
|
335
|
+
self.__class__.__name__, self._request_message_id,
|
|
336
|
+
self._correlation_id, self._timeout
|
|
337
|
+
)
|
|
338
|
+
return repr_str
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the MetricDefinition class representing an immutable
|
|
3
|
+
description of a metric with a name, description, unit, and type.
|
|
4
|
+
|
|
5
|
+
MetricDefinition objects are registered in a MetricsRegistry and
|
|
6
|
+
used by the MetricsCollector to validate metric operations. All
|
|
7
|
+
fields are exposed as read-only properties to preserve immutability
|
|
8
|
+
after construction.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
|
|
13
|
+
from ccai.agentkit.metrictype import MetricType
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MetricDefinition:
|
|
17
|
+
"""
|
|
18
|
+
An immutable object describing a metric with a name, description,
|
|
19
|
+
unit, and type.
|
|
20
|
+
|
|
21
|
+
:param name: The metric name string.
|
|
22
|
+
:param description: A human-readable description of the metric.
|
|
23
|
+
:param unit: The unit of measurement string (e.g. "seconds",
|
|
24
|
+
"count", "tokens").
|
|
25
|
+
:param metric_type: The MetricType enum value classifying this
|
|
26
|
+
metric.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(self, name: str, description: str, unit: str,
|
|
30
|
+
metric_type: MetricType) -> None:
|
|
31
|
+
|
|
32
|
+
self._name = name
|
|
33
|
+
self._description = description
|
|
34
|
+
self._unit = unit
|
|
35
|
+
self._metric_type = metric_type
|
|
36
|
+
|
|
37
|
+
return
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def name(self) -> str:
|
|
41
|
+
"""
|
|
42
|
+
The metric name string.
|
|
43
|
+
|
|
44
|
+
:returns: The metric name.
|
|
45
|
+
"""
|
|
46
|
+
return self._name
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def description(self) -> str:
|
|
50
|
+
"""
|
|
51
|
+
A human-readable description of the metric.
|
|
52
|
+
|
|
53
|
+
:returns: The description string.
|
|
54
|
+
"""
|
|
55
|
+
return self._description
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def unit(self) -> str:
|
|
59
|
+
"""
|
|
60
|
+
The unit of measurement string.
|
|
61
|
+
|
|
62
|
+
:returns: The unit string.
|
|
63
|
+
"""
|
|
64
|
+
return self._unit
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def metric_type(self) -> MetricType:
|
|
68
|
+
"""
|
|
69
|
+
The MetricType enum value classifying this metric.
|
|
70
|
+
|
|
71
|
+
:returns: The MetricType value.
|
|
72
|
+
"""
|
|
73
|
+
return self._metric_type
|
|
74
|
+
|
|
75
|
+
def as_dict(self) -> dict:
|
|
76
|
+
"""
|
|
77
|
+
Returns a dictionary representation of the definition fields.
|
|
78
|
+
|
|
79
|
+
The metric_type is serialized as its string value for
|
|
80
|
+
consistent representation.
|
|
81
|
+
|
|
82
|
+
:returns: A dictionary containing all definition fields.
|
|
83
|
+
"""
|
|
84
|
+
result = {
|
|
85
|
+
"name": self._name,
|
|
86
|
+
"description": self._description,
|
|
87
|
+
"unit": self._unit,
|
|
88
|
+
"metric_type": self._metric_type.value
|
|
89
|
+
}
|
|
90
|
+
return result
|
|
91
|
+
|
|
92
|
+
def to_json(self) -> str:
|
|
93
|
+
"""
|
|
94
|
+
Returns a JSON string representation of the definition fields.
|
|
95
|
+
|
|
96
|
+
:returns: A JSON string containing all definition fields.
|
|
97
|
+
"""
|
|
98
|
+
data = self.as_dict()
|
|
99
|
+
json_str = json.dumps(data)
|
|
100
|
+
return json_str
|
|
101
|
+
|
|
102
|
+
@classmethod
|
|
103
|
+
def from_dict(cls, data: dict) -> "MetricDefinition":
|
|
104
|
+
"""
|
|
105
|
+
Constructs a MetricDefinition from a dictionary.
|
|
106
|
+
|
|
107
|
+
The metric_type field is expected to be a string value
|
|
108
|
+
and is converted to a MetricType enum member.
|
|
109
|
+
|
|
110
|
+
:param data: A dictionary containing definition fields.
|
|
111
|
+
|
|
112
|
+
:returns: A MetricDefinition instance reconstructed from
|
|
113
|
+
the dictionary.
|
|
114
|
+
"""
|
|
115
|
+
name = data["name"]
|
|
116
|
+
description = data["description"]
|
|
117
|
+
unit = data["unit"]
|
|
118
|
+
metric_type = MetricType.from_string(data["metric_type"])
|
|
119
|
+
|
|
120
|
+
definition = cls(
|
|
121
|
+
name=name,
|
|
122
|
+
description=description,
|
|
123
|
+
unit=unit,
|
|
124
|
+
metric_type=metric_type
|
|
125
|
+
)
|
|
126
|
+
return definition
|
|
127
|
+
|
|
128
|
+
@classmethod
|
|
129
|
+
def from_json(cls, json_str: str) -> "MetricDefinition":
|
|
130
|
+
"""
|
|
131
|
+
Deserializes a JSON string into a MetricDefinition instance.
|
|
132
|
+
|
|
133
|
+
:param json_str: A JSON string containing definition fields.
|
|
134
|
+
|
|
135
|
+
:returns: A MetricDefinition instance reconstructed from
|
|
136
|
+
the JSON data.
|
|
137
|
+
"""
|
|
138
|
+
data = json.loads(json_str)
|
|
139
|
+
definition = cls.from_dict(data)
|
|
140
|
+
return definition
|
|
141
|
+
|
|
142
|
+
def __repr__(self) -> str:
|
|
143
|
+
"""
|
|
144
|
+
Returns a detailed string representation including class name,
|
|
145
|
+
metric name, and metric type.
|
|
146
|
+
|
|
147
|
+
:returns: A repr string for debugging.
|
|
148
|
+
"""
|
|
149
|
+
repr_str = "MetricDefinition(name={!r}, metric_type={!r})".format(
|
|
150
|
+
self._name, self._metric_type.value
|
|
151
|
+
)
|
|
152
|
+
return repr_str
|
|
153
|
+
|
|
154
|
+
def __str__(self) -> str:
|
|
155
|
+
"""
|
|
156
|
+
Returns a human-readable summary including the metric name,
|
|
157
|
+
type, and unit.
|
|
158
|
+
|
|
159
|
+
:returns: A human-readable string.
|
|
160
|
+
"""
|
|
161
|
+
str_val = "MetricDefinition: name={}, type={}, unit={}".format(
|
|
162
|
+
self._name, self._metric_type.value, self._unit
|
|
163
|
+
)
|
|
164
|
+
return str_val
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the MetricMeasurement class representing an immutable
|
|
3
|
+
single metric data point.
|
|
4
|
+
|
|
5
|
+
MetricMeasurement objects contain a metric name, a float value,
|
|
6
|
+
a timestamp, and a labels dictionary of string key-value pairs.
|
|
7
|
+
The timestamp defaults to the current UTC time when not explicitly
|
|
8
|
+
provided. All fields are exposed as read-only properties to
|
|
9
|
+
preserve immutability after construction.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
|
|
14
|
+
from datetime import datetime
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class MetricMeasurement:
|
|
18
|
+
"""
|
|
19
|
+
An immutable object representing a single metric data point.
|
|
20
|
+
|
|
21
|
+
Contains the metric name, the value as a float, a timestamp,
|
|
22
|
+
and a labels dictionary of string key-value pairs. The timestamp
|
|
23
|
+
defaults to the current UTC time when not explicitly provided.
|
|
24
|
+
|
|
25
|
+
:param metric_name: The name of the metric being measured.
|
|
26
|
+
:param value: The metric value as a float.
|
|
27
|
+
:param timestamp: Optional timestamp for the measurement.
|
|
28
|
+
Defaults to the current UTC time if not provided.
|
|
29
|
+
:param labels: Optional dictionary of string key-value labels
|
|
30
|
+
for dimensional context.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, metric_name: str, value: float,
|
|
34
|
+
timestamp: datetime = None, labels: dict = None) -> None:
|
|
35
|
+
|
|
36
|
+
self._metric_name = metric_name
|
|
37
|
+
self._value = value
|
|
38
|
+
|
|
39
|
+
if timestamp is not None:
|
|
40
|
+
self._timestamp = timestamp
|
|
41
|
+
else:
|
|
42
|
+
self._timestamp = datetime.utcnow()
|
|
43
|
+
|
|
44
|
+
if labels is not None:
|
|
45
|
+
self._labels = dict(labels)
|
|
46
|
+
else:
|
|
47
|
+
self._labels = {}
|
|
48
|
+
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def metric_name(self) -> str:
|
|
53
|
+
"""
|
|
54
|
+
The name of the metric being measured.
|
|
55
|
+
|
|
56
|
+
:returns: The metric name string.
|
|
57
|
+
"""
|
|
58
|
+
return self._metric_name
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def value(self) -> float:
|
|
62
|
+
"""
|
|
63
|
+
The metric value as a float.
|
|
64
|
+
|
|
65
|
+
:returns: The metric value.
|
|
66
|
+
"""
|
|
67
|
+
return self._value
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def timestamp(self) -> datetime:
|
|
71
|
+
"""
|
|
72
|
+
The timestamp when this measurement was recorded.
|
|
73
|
+
|
|
74
|
+
:returns: The datetime timestamp.
|
|
75
|
+
"""
|
|
76
|
+
return self._timestamp
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def labels(self) -> dict:
|
|
80
|
+
"""
|
|
81
|
+
A copy of the labels dictionary of string key-value pairs.
|
|
82
|
+
Returns a copy to preserve immutability.
|
|
83
|
+
|
|
84
|
+
:returns: A dictionary copy of the labels.
|
|
85
|
+
"""
|
|
86
|
+
result = dict(self._labels)
|
|
87
|
+
return result
|
|
88
|
+
|
|
89
|
+
def as_dict(self) -> dict:
|
|
90
|
+
"""
|
|
91
|
+
Returns a dictionary representation of the measurement fields.
|
|
92
|
+
|
|
93
|
+
The timestamp is serialized as an ISO format string for
|
|
94
|
+
consistent representation.
|
|
95
|
+
|
|
96
|
+
:returns: A dictionary containing all measurement fields.
|
|
97
|
+
"""
|
|
98
|
+
result = {
|
|
99
|
+
"metric_name": self._metric_name,
|
|
100
|
+
"value": self._value,
|
|
101
|
+
"timestamp": self._timestamp.isoformat(),
|
|
102
|
+
"labels": dict(self._labels)
|
|
103
|
+
}
|
|
104
|
+
return result
|
|
105
|
+
|
|
106
|
+
def to_json(self) -> str:
|
|
107
|
+
"""
|
|
108
|
+
Returns a JSON string representation of the measurement fields.
|
|
109
|
+
|
|
110
|
+
:returns: A JSON string containing all measurement fields.
|
|
111
|
+
"""
|
|
112
|
+
data = self.as_dict()
|
|
113
|
+
json_str = json.dumps(data)
|
|
114
|
+
return json_str
|
|
115
|
+
|
|
116
|
+
@classmethod
|
|
117
|
+
def from_dict(cls, data: dict) -> "MetricMeasurement":
|
|
118
|
+
"""
|
|
119
|
+
Constructs a MetricMeasurement from a dictionary.
|
|
120
|
+
|
|
121
|
+
The timestamp field is expected to be an ISO format string
|
|
122
|
+
and is parsed back into a datetime object.
|
|
123
|
+
|
|
124
|
+
:param data: A dictionary containing measurement fields.
|
|
125
|
+
|
|
126
|
+
:returns: A MetricMeasurement instance reconstructed from
|
|
127
|
+
the dictionary.
|
|
128
|
+
"""
|
|
129
|
+
metric_name = data["metric_name"]
|
|
130
|
+
value = data["value"]
|
|
131
|
+
timestamp = datetime.fromisoformat(data["timestamp"])
|
|
132
|
+
labels = data.get("labels", None)
|
|
133
|
+
|
|
134
|
+
measurement = cls(
|
|
135
|
+
metric_name=metric_name,
|
|
136
|
+
value=value,
|
|
137
|
+
timestamp=timestamp,
|
|
138
|
+
labels=labels
|
|
139
|
+
)
|
|
140
|
+
return measurement
|
|
141
|
+
|
|
142
|
+
@classmethod
|
|
143
|
+
def from_json(cls, json_str: str) -> "MetricMeasurement":
|
|
144
|
+
"""
|
|
145
|
+
Deserializes a JSON string into a MetricMeasurement instance.
|
|
146
|
+
|
|
147
|
+
:param json_str: A JSON string containing measurement fields.
|
|
148
|
+
|
|
149
|
+
:returns: A MetricMeasurement instance reconstructed from
|
|
150
|
+
the JSON data.
|
|
151
|
+
"""
|
|
152
|
+
data = json.loads(json_str)
|
|
153
|
+
measurement = cls.from_dict(data)
|
|
154
|
+
return measurement
|
|
155
|
+
|
|
156
|
+
def __repr__(self) -> str:
|
|
157
|
+
"""
|
|
158
|
+
Returns a detailed string representation including class name,
|
|
159
|
+
metric name, and value.
|
|
160
|
+
|
|
161
|
+
:returns: A repr string for debugging.
|
|
162
|
+
"""
|
|
163
|
+
repr_str = "MetricMeasurement(metric_name={!r}, value={!r})".format(
|
|
164
|
+
self._metric_name, self._value
|
|
165
|
+
)
|
|
166
|
+
return repr_str
|
|
167
|
+
|
|
168
|
+
def __str__(self) -> str:
|
|
169
|
+
"""
|
|
170
|
+
Returns a human-readable summary including the metric name,
|
|
171
|
+
value, and labels.
|
|
172
|
+
|
|
173
|
+
:returns: A human-readable string.
|
|
174
|
+
"""
|
|
175
|
+
str_val = "MetricMeasurement: metric_name={}, value={}, labels={}".format(
|
|
176
|
+
self._metric_name, self._value, self._labels
|
|
177
|
+
)
|
|
178
|
+
return str_val
|