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,546 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Declarative configuration for the observability system of an Agent.
|
|
3
|
+
|
|
4
|
+
Provides the ObservabilityConfiguration class that defines logging format,
|
|
5
|
+
log level, tracing enablement, metrics enablement, recording enablement,
|
|
6
|
+
debug mode enablement, sampling rates, and exporter settings. Supports
|
|
7
|
+
loading from dict, JSON string, JSON file, YAML string, and YAML file.
|
|
8
|
+
Validates required fields and excludes resolved credential secret values
|
|
9
|
+
from serialization output.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
from typing import Any, Optional
|
|
16
|
+
|
|
17
|
+
import yaml
|
|
18
|
+
|
|
19
|
+
from ccai.agentkit.errors import ConfigurationError
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ObservabilityConfiguration:
|
|
23
|
+
"""
|
|
24
|
+
A configuration object that defines the observability system settings
|
|
25
|
+
for an Agent.
|
|
26
|
+
|
|
27
|
+
Supports loading from dict, JSON string, JSON file, YAML string,
|
|
28
|
+
and YAML file. Validates log_level, log_format, and sampling_rate.
|
|
29
|
+
Excludes resolved credential secret values from serialization output.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
VALID_LOG_LEVELS = ("debug", "info", "warning", "error", "critical")
|
|
33
|
+
VALID_LOG_FORMATS = ("json", "key_value", "human_readable")
|
|
34
|
+
|
|
35
|
+
def __init__(self, log_level: str = "info", log_format: str = "human_readable",
|
|
36
|
+
tracing_enabled: bool = False, metrics_enabled: bool = False,
|
|
37
|
+
recording_enabled: bool = False, debug_mode_enabled: bool = False,
|
|
38
|
+
sampling_rate: float = 1.0, exporter_settings: Optional[dict] = None,
|
|
39
|
+
credentials: Optional[dict] = None,
|
|
40
|
+
resolved_credentials: Optional[dict] = None) -> None:
|
|
41
|
+
"""
|
|
42
|
+
Initializes an ObservabilityConfiguration instance.
|
|
43
|
+
|
|
44
|
+
:param log_level: The log level string, one of VALID_LOG_LEVELS.
|
|
45
|
+
:param log_format: The log format string, one of VALID_LOG_FORMATS.
|
|
46
|
+
:param tracing_enabled: Whether distributed tracing is enabled.
|
|
47
|
+
:param metrics_enabled: Whether metrics collection is enabled.
|
|
48
|
+
:param recording_enabled: Whether execution recording is enabled.
|
|
49
|
+
:param debug_mode_enabled: Whether debug mode is enabled.
|
|
50
|
+
:param sampling_rate: The sampling rate as a float between 0.0 and 1.0.
|
|
51
|
+
:param exporter_settings: Optional dictionary of exporter settings.
|
|
52
|
+
:param credentials: Optional dictionary of credential references.
|
|
53
|
+
:param resolved_credentials: Optional dictionary of resolved credential objects.
|
|
54
|
+
|
|
55
|
+
:raises: ConfigurationError
|
|
56
|
+
"""
|
|
57
|
+
self._validate_log_level(log_level)
|
|
58
|
+
self._validate_log_format(log_format)
|
|
59
|
+
self._validate_sampling_rate(sampling_rate)
|
|
60
|
+
|
|
61
|
+
self._log_level = log_level
|
|
62
|
+
self._log_format = log_format
|
|
63
|
+
self._tracing_enabled = tracing_enabled
|
|
64
|
+
self._metrics_enabled = metrics_enabled
|
|
65
|
+
self._recording_enabled = recording_enabled
|
|
66
|
+
self._debug_mode_enabled = debug_mode_enabled
|
|
67
|
+
self._sampling_rate = sampling_rate
|
|
68
|
+
|
|
69
|
+
if exporter_settings is not None:
|
|
70
|
+
self._exporter_settings = dict(exporter_settings)
|
|
71
|
+
else:
|
|
72
|
+
self._exporter_settings = {}
|
|
73
|
+
|
|
74
|
+
if credentials is not None:
|
|
75
|
+
self._credentials = dict(credentials)
|
|
76
|
+
else:
|
|
77
|
+
self._credentials = {}
|
|
78
|
+
|
|
79
|
+
if resolved_credentials is not None:
|
|
80
|
+
self._resolved_credentials = dict(resolved_credentials)
|
|
81
|
+
else:
|
|
82
|
+
self._resolved_credentials = {}
|
|
83
|
+
|
|
84
|
+
return
|
|
85
|
+
|
|
86
|
+
@classmethod
|
|
87
|
+
def _validate_log_level(cls, log_level: str) -> None:
|
|
88
|
+
"""
|
|
89
|
+
Validates that the log level is one of the valid log levels.
|
|
90
|
+
|
|
91
|
+
:param log_level: The log level string to validate.
|
|
92
|
+
|
|
93
|
+
:raises: ConfigurationError
|
|
94
|
+
"""
|
|
95
|
+
is_valid = log_level in cls.VALID_LOG_LEVELS
|
|
96
|
+
if is_valid is not True:
|
|
97
|
+
err_msg_lines = [
|
|
98
|
+
"Invalid log level provided."
|
|
99
|
+
]
|
|
100
|
+
err_msg_lines.append(" Provided log level: {!r}".format(log_level))
|
|
101
|
+
err_msg_lines.append(" Valid log levels: {}".format(list(cls.VALID_LOG_LEVELS)))
|
|
102
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
103
|
+
raise ConfigurationError(err_msg)
|
|
104
|
+
|
|
105
|
+
return
|
|
106
|
+
|
|
107
|
+
@classmethod
|
|
108
|
+
def _validate_log_format(cls, log_format: str) -> None:
|
|
109
|
+
"""
|
|
110
|
+
Validates that the log format is one of the valid log formats.
|
|
111
|
+
|
|
112
|
+
:param log_format: The log format string to validate.
|
|
113
|
+
|
|
114
|
+
:raises: ConfigurationError
|
|
115
|
+
"""
|
|
116
|
+
is_valid = log_format in cls.VALID_LOG_FORMATS
|
|
117
|
+
if is_valid is not True:
|
|
118
|
+
err_msg_lines = [
|
|
119
|
+
"Invalid log format provided."
|
|
120
|
+
]
|
|
121
|
+
err_msg_lines.append(" Provided log format: {!r}".format(log_format))
|
|
122
|
+
err_msg_lines.append(" Valid log formats: {}".format(list(cls.VALID_LOG_FORMATS)))
|
|
123
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
124
|
+
raise ConfigurationError(err_msg)
|
|
125
|
+
|
|
126
|
+
return
|
|
127
|
+
|
|
128
|
+
@classmethod
|
|
129
|
+
def _validate_sampling_rate(cls, sampling_rate: float) -> None:
|
|
130
|
+
"""
|
|
131
|
+
Validates that the sampling rate is between 0.0 and 1.0 inclusive.
|
|
132
|
+
|
|
133
|
+
:param sampling_rate: The sampling rate to validate.
|
|
134
|
+
|
|
135
|
+
:raises: ConfigurationError
|
|
136
|
+
"""
|
|
137
|
+
is_valid = 0.0 <= sampling_rate <= 1.0
|
|
138
|
+
if is_valid is not True:
|
|
139
|
+
err_msg_lines = [
|
|
140
|
+
"Invalid sampling rate provided."
|
|
141
|
+
]
|
|
142
|
+
err_msg_lines.append(" Provided sampling rate: {!r}".format(sampling_rate))
|
|
143
|
+
err_msg_lines.append(" Sampling rate must be between 0.0 and 1.0 inclusive.")
|
|
144
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
145
|
+
raise ConfigurationError(err_msg)
|
|
146
|
+
|
|
147
|
+
return
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def log_level(self) -> str:
|
|
151
|
+
"""
|
|
152
|
+
The configured log level.
|
|
153
|
+
|
|
154
|
+
:returns: The log level string.
|
|
155
|
+
"""
|
|
156
|
+
return self._log_level
|
|
157
|
+
|
|
158
|
+
@property
|
|
159
|
+
def log_format(self) -> str:
|
|
160
|
+
"""
|
|
161
|
+
The configured log format.
|
|
162
|
+
|
|
163
|
+
:returns: The log format string.
|
|
164
|
+
"""
|
|
165
|
+
return self._log_format
|
|
166
|
+
|
|
167
|
+
@property
|
|
168
|
+
def tracing_enabled(self) -> bool:
|
|
169
|
+
"""
|
|
170
|
+
Whether distributed tracing is enabled.
|
|
171
|
+
|
|
172
|
+
:returns: True if tracing is enabled, False otherwise.
|
|
173
|
+
"""
|
|
174
|
+
return self._tracing_enabled
|
|
175
|
+
|
|
176
|
+
@property
|
|
177
|
+
def metrics_enabled(self) -> bool:
|
|
178
|
+
"""
|
|
179
|
+
Whether metrics collection is enabled.
|
|
180
|
+
|
|
181
|
+
:returns: True if metrics collection is enabled, False otherwise.
|
|
182
|
+
"""
|
|
183
|
+
return self._metrics_enabled
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def recording_enabled(self) -> bool:
|
|
187
|
+
"""
|
|
188
|
+
Whether execution recording is enabled.
|
|
189
|
+
|
|
190
|
+
:returns: True if recording is enabled, False otherwise.
|
|
191
|
+
"""
|
|
192
|
+
return self._recording_enabled
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def debug_mode_enabled(self) -> bool:
|
|
196
|
+
"""
|
|
197
|
+
Whether debug mode is enabled.
|
|
198
|
+
|
|
199
|
+
:returns: True if debug mode is enabled, False otherwise.
|
|
200
|
+
"""
|
|
201
|
+
return self._debug_mode_enabled
|
|
202
|
+
|
|
203
|
+
@property
|
|
204
|
+
def sampling_rate(self) -> float:
|
|
205
|
+
"""
|
|
206
|
+
The configured sampling rate.
|
|
207
|
+
|
|
208
|
+
:returns: The sampling rate as a float between 0.0 and 1.0.
|
|
209
|
+
"""
|
|
210
|
+
return self._sampling_rate
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def exporter_settings(self) -> dict:
|
|
214
|
+
"""
|
|
215
|
+
A defensive copy of the exporter settings dictionary.
|
|
216
|
+
|
|
217
|
+
:returns: A dictionary containing exporter settings.
|
|
218
|
+
"""
|
|
219
|
+
return dict(self._exporter_settings)
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def credentials(self) -> dict:
|
|
223
|
+
"""
|
|
224
|
+
A defensive copy of the credential reference dictionary.
|
|
225
|
+
|
|
226
|
+
Contains reference names only, not resolved secret values.
|
|
227
|
+
|
|
228
|
+
:returns: A dictionary of credential references.
|
|
229
|
+
"""
|
|
230
|
+
return dict(self._credentials)
|
|
231
|
+
|
|
232
|
+
@property
|
|
233
|
+
def resolved_credentials(self) -> dict:
|
|
234
|
+
"""
|
|
235
|
+
A defensive copy of the resolved credential objects.
|
|
236
|
+
|
|
237
|
+
:returns: A dictionary of resolved credential objects.
|
|
238
|
+
"""
|
|
239
|
+
return dict(self._resolved_credentials)
|
|
240
|
+
|
|
241
|
+
def as_dict(self) -> dict:
|
|
242
|
+
"""
|
|
243
|
+
Returns a dictionary representation of the configuration.
|
|
244
|
+
|
|
245
|
+
Excludes resolved credential secret values. Includes credential
|
|
246
|
+
reference names but not resolved values.
|
|
247
|
+
|
|
248
|
+
:returns: A dictionary containing the configuration data.
|
|
249
|
+
"""
|
|
250
|
+
result = {
|
|
251
|
+
"log_level": self._log_level,
|
|
252
|
+
"log_format": self._log_format,
|
|
253
|
+
"tracing_enabled": self._tracing_enabled,
|
|
254
|
+
"metrics_enabled": self._metrics_enabled,
|
|
255
|
+
"recording_enabled": self._recording_enabled,
|
|
256
|
+
"debug_mode_enabled": self._debug_mode_enabled,
|
|
257
|
+
"sampling_rate": self._sampling_rate,
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if len(self._exporter_settings) > 0:
|
|
261
|
+
result["exporter_settings"] = dict(self._exporter_settings)
|
|
262
|
+
|
|
263
|
+
if len(self._credentials) > 0:
|
|
264
|
+
result["credentials"] = dict(self._credentials)
|
|
265
|
+
|
|
266
|
+
return result
|
|
267
|
+
|
|
268
|
+
def to_json(self) -> str:
|
|
269
|
+
"""
|
|
270
|
+
Returns a JSON string representation of the configuration.
|
|
271
|
+
|
|
272
|
+
Excludes resolved credential secret values.
|
|
273
|
+
|
|
274
|
+
:returns: A JSON string containing the configuration data.
|
|
275
|
+
"""
|
|
276
|
+
data = self.as_dict()
|
|
277
|
+
json_str = json.dumps(data)
|
|
278
|
+
return json_str
|
|
279
|
+
|
|
280
|
+
def to_yaml(self) -> str:
|
|
281
|
+
"""
|
|
282
|
+
Returns a YAML string representation of the configuration.
|
|
283
|
+
|
|
284
|
+
Excludes resolved credential secret values.
|
|
285
|
+
|
|
286
|
+
:returns: A YAML string containing the configuration data.
|
|
287
|
+
"""
|
|
288
|
+
data = self.as_dict()
|
|
289
|
+
yaml_str = yaml.dump(data, default_flow_style=False)
|
|
290
|
+
return yaml_str
|
|
291
|
+
|
|
292
|
+
@classmethod
|
|
293
|
+
def from_dict(cls, data: dict, app_context: Any = None) -> "ObservabilityConfiguration":
|
|
294
|
+
"""
|
|
295
|
+
Creates an ObservabilityConfiguration from a dictionary.
|
|
296
|
+
|
|
297
|
+
Validates fields, resolves credential references if present,
|
|
298
|
+
and returns a configured instance.
|
|
299
|
+
|
|
300
|
+
:param data: The configuration dictionary.
|
|
301
|
+
:param app_context: Optional application context for resolving
|
|
302
|
+
credentials and file paths.
|
|
303
|
+
|
|
304
|
+
:returns: An ObservabilityConfiguration instance.
|
|
305
|
+
:raises: ConfigurationError
|
|
306
|
+
"""
|
|
307
|
+
if not isinstance(data, dict):
|
|
308
|
+
err_msg_lines = [
|
|
309
|
+
"Configuration data must be a dictionary."
|
|
310
|
+
]
|
|
311
|
+
err_msg_lines.append(" Received type: {}".format(type(data).__name__))
|
|
312
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
313
|
+
raise ConfigurationError(err_msg)
|
|
314
|
+
|
|
315
|
+
log_level = data.get("log_level", "info")
|
|
316
|
+
log_format = data.get("log_format", "human_readable")
|
|
317
|
+
tracing_enabled = data.get("tracing_enabled", False)
|
|
318
|
+
metrics_enabled = data.get("metrics_enabled", False)
|
|
319
|
+
recording_enabled = data.get("recording_enabled", False)
|
|
320
|
+
debug_mode_enabled = data.get("debug_mode_enabled", False)
|
|
321
|
+
sampling_rate = data.get("sampling_rate", 1.0)
|
|
322
|
+
exporter_settings = data.get("exporter_settings", None)
|
|
323
|
+
credentials_data = data.get("credentials", None)
|
|
324
|
+
|
|
325
|
+
resolved_credentials = {}
|
|
326
|
+
|
|
327
|
+
has_credentials = credentials_data is not None and len(credentials_data) > 0
|
|
328
|
+
|
|
329
|
+
if has_credentials is True and app_context is not None:
|
|
330
|
+
resolved_credentials = cls._resolve_credentials(credentials_data, app_context)
|
|
331
|
+
|
|
332
|
+
configuration = cls(
|
|
333
|
+
log_level=log_level,
|
|
334
|
+
log_format=log_format,
|
|
335
|
+
tracing_enabled=tracing_enabled,
|
|
336
|
+
metrics_enabled=metrics_enabled,
|
|
337
|
+
recording_enabled=recording_enabled,
|
|
338
|
+
debug_mode_enabled=debug_mode_enabled,
|
|
339
|
+
sampling_rate=sampling_rate,
|
|
340
|
+
exporter_settings=exporter_settings,
|
|
341
|
+
credentials=credentials_data,
|
|
342
|
+
resolved_credentials=resolved_credentials,
|
|
343
|
+
)
|
|
344
|
+
return configuration
|
|
345
|
+
|
|
346
|
+
@classmethod
|
|
347
|
+
def _resolve_credentials(cls, credentials_data: dict, app_context: Any) -> dict:
|
|
348
|
+
"""
|
|
349
|
+
Resolves credential references through the credential manager.
|
|
350
|
+
|
|
351
|
+
:param credentials_data: Dictionary of credential reference entries.
|
|
352
|
+
:param app_context: The application context providing credential manager access.
|
|
353
|
+
|
|
354
|
+
:returns: A dictionary mapping credential names to resolved credential objects.
|
|
355
|
+
:raises: ConfigurationError
|
|
356
|
+
"""
|
|
357
|
+
resolved = {}
|
|
358
|
+
|
|
359
|
+
for cred_name, cred_ref in credentials_data.items():
|
|
360
|
+
provider = cred_ref.get("provider", "")
|
|
361
|
+
key = cred_ref.get("key", "")
|
|
362
|
+
|
|
363
|
+
try:
|
|
364
|
+
credential_manager = app_context.credential_manager
|
|
365
|
+
resolved_cred = credential_manager.lookup_credential(key)
|
|
366
|
+
# A core ccai.errors ConfigurationError (e.g. a missing vault key)
|
|
367
|
+
# derives from BaseException and deliberately passes through this
|
|
368
|
+
# handler: a wrong configuration must terminate the run.
|
|
369
|
+
except Exception as exc:
|
|
370
|
+
err_msg_lines = [
|
|
371
|
+
"Failed to resolve credential reference."
|
|
372
|
+
]
|
|
373
|
+
err_msg_lines.append(" Credential name: {!r}".format(cred_name))
|
|
374
|
+
err_msg_lines.append(" Provider: {!r}".format(provider))
|
|
375
|
+
err_msg_lines.append(" Key: {!r}".format(key))
|
|
376
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
377
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
378
|
+
|
|
379
|
+
if resolved_cred is None:
|
|
380
|
+
err_msg_lines = [
|
|
381
|
+
"Unresolvable credential reference."
|
|
382
|
+
]
|
|
383
|
+
err_msg_lines.append(" Credential name: {!r}".format(cred_name))
|
|
384
|
+
err_msg_lines.append(" Provider: {!r}".format(provider))
|
|
385
|
+
err_msg_lines.append(" Key: {!r}".format(key))
|
|
386
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
387
|
+
raise ConfigurationError(err_msg)
|
|
388
|
+
|
|
389
|
+
resolved[cred_name] = resolved_cred
|
|
390
|
+
|
|
391
|
+
return resolved
|
|
392
|
+
|
|
393
|
+
@classmethod
|
|
394
|
+
def from_json(cls, json_str: str, app_context: Any = None) -> "ObservabilityConfiguration":
|
|
395
|
+
"""
|
|
396
|
+
Creates an ObservabilityConfiguration from a JSON string.
|
|
397
|
+
|
|
398
|
+
:param json_str: A JSON string containing configuration data.
|
|
399
|
+
:param app_context: Optional application context for resolving references.
|
|
400
|
+
|
|
401
|
+
:returns: An ObservabilityConfiguration instance.
|
|
402
|
+
:raises: ConfigurationError
|
|
403
|
+
"""
|
|
404
|
+
try:
|
|
405
|
+
data = json.loads(json_str)
|
|
406
|
+
except (json.JSONDecodeError, TypeError) as exc:
|
|
407
|
+
err_msg_lines = [
|
|
408
|
+
"Failed to parse JSON configuration string."
|
|
409
|
+
]
|
|
410
|
+
err_msg_lines.append(" Error: {}".format(str(exc)))
|
|
411
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
412
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
413
|
+
|
|
414
|
+
configuration = cls.from_dict(data, app_context=app_context)
|
|
415
|
+
return configuration
|
|
416
|
+
|
|
417
|
+
@classmethod
|
|
418
|
+
def from_yaml(cls, yaml_str: str, app_context: Any = None) -> "ObservabilityConfiguration":
|
|
419
|
+
"""
|
|
420
|
+
Creates an ObservabilityConfiguration from a YAML string.
|
|
421
|
+
|
|
422
|
+
:param yaml_str: A YAML string containing configuration data.
|
|
423
|
+
:param app_context: Optional application context for resolving references.
|
|
424
|
+
|
|
425
|
+
:returns: An ObservabilityConfiguration instance.
|
|
426
|
+
:raises: ConfigurationError
|
|
427
|
+
"""
|
|
428
|
+
try:
|
|
429
|
+
data = yaml.safe_load(yaml_str)
|
|
430
|
+
except yaml.YAMLError as exc:
|
|
431
|
+
err_msg_lines = [
|
|
432
|
+
"Failed to parse YAML configuration string."
|
|
433
|
+
]
|
|
434
|
+
err_msg_lines.append(" Error: {}".format(str(exc)))
|
|
435
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
436
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
437
|
+
|
|
438
|
+
configuration = cls.from_dict(data, app_context=app_context)
|
|
439
|
+
return configuration
|
|
440
|
+
|
|
441
|
+
@classmethod
|
|
442
|
+
def from_json_file(cls, file_path: str, app_context: Any = None) -> "ObservabilityConfiguration":
|
|
443
|
+
"""
|
|
444
|
+
Creates an ObservabilityConfiguration from a JSON file.
|
|
445
|
+
|
|
446
|
+
If app_context is provided, the file path is resolved relative
|
|
447
|
+
to the AppContext directory.
|
|
448
|
+
|
|
449
|
+
:param file_path: Path to the JSON configuration file.
|
|
450
|
+
:param app_context: Optional application context for resolving
|
|
451
|
+
the file path and references.
|
|
452
|
+
|
|
453
|
+
:returns: An ObservabilityConfiguration instance.
|
|
454
|
+
:raises: ConfigurationError
|
|
455
|
+
"""
|
|
456
|
+
resolved_path = file_path
|
|
457
|
+
|
|
458
|
+
if app_context is not None:
|
|
459
|
+
try:
|
|
460
|
+
base_dir = app_context.directory
|
|
461
|
+
resolved_path = os.path.join(base_dir, file_path)
|
|
462
|
+
except Exception:
|
|
463
|
+
resolved_path = file_path
|
|
464
|
+
|
|
465
|
+
try:
|
|
466
|
+
with open(resolved_path, "r") as file_handle:
|
|
467
|
+
json_str = file_handle.read()
|
|
468
|
+
except (OSError, IOError) as exc:
|
|
469
|
+
err_msg_lines = [
|
|
470
|
+
"Failed to read JSON configuration file."
|
|
471
|
+
]
|
|
472
|
+
err_msg_lines.append(" File path: {!r}".format(resolved_path))
|
|
473
|
+
err_msg_lines.append(" Error: {}".format(str(exc)))
|
|
474
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
475
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
476
|
+
|
|
477
|
+
configuration = cls.from_json(json_str, app_context=app_context)
|
|
478
|
+
return configuration
|
|
479
|
+
|
|
480
|
+
@classmethod
|
|
481
|
+
def from_yaml_file(cls, file_path: str, app_context: Any = None) -> "ObservabilityConfiguration":
|
|
482
|
+
"""
|
|
483
|
+
Creates an ObservabilityConfiguration from a YAML file.
|
|
484
|
+
|
|
485
|
+
If app_context is provided, the file path is resolved relative
|
|
486
|
+
to the AppContext directory.
|
|
487
|
+
|
|
488
|
+
:param file_path: Path to the YAML configuration file.
|
|
489
|
+
:param app_context: Optional application context for resolving
|
|
490
|
+
the file path and references.
|
|
491
|
+
|
|
492
|
+
:returns: An ObservabilityConfiguration instance.
|
|
493
|
+
:raises: ConfigurationError
|
|
494
|
+
"""
|
|
495
|
+
resolved_path = file_path
|
|
496
|
+
|
|
497
|
+
if app_context is not None:
|
|
498
|
+
try:
|
|
499
|
+
base_dir = app_context.directory
|
|
500
|
+
resolved_path = os.path.join(base_dir, file_path)
|
|
501
|
+
except Exception:
|
|
502
|
+
resolved_path = file_path
|
|
503
|
+
|
|
504
|
+
try:
|
|
505
|
+
with open(resolved_path, "r") as file_handle:
|
|
506
|
+
yaml_str = file_handle.read()
|
|
507
|
+
except (OSError, IOError) as exc:
|
|
508
|
+
err_msg_lines = [
|
|
509
|
+
"Failed to read YAML configuration file."
|
|
510
|
+
]
|
|
511
|
+
err_msg_lines.append(" File path: {!r}".format(resolved_path))
|
|
512
|
+
err_msg_lines.append(" Error: {}".format(str(exc)))
|
|
513
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
514
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
515
|
+
|
|
516
|
+
configuration = cls.from_yaml(yaml_str, app_context=app_context)
|
|
517
|
+
return configuration
|
|
518
|
+
|
|
519
|
+
def __repr__(self) -> str:
|
|
520
|
+
"""
|
|
521
|
+
Returns a detailed string representation including class name,
|
|
522
|
+
log level, log format, and tracing enabled status.
|
|
523
|
+
|
|
524
|
+
:returns: A repr string for debugging.
|
|
525
|
+
"""
|
|
526
|
+
repr_str = "ObservabilityConfiguration(log_level={!r}, log_format={!r}, tracing_enabled={!r})".format(
|
|
527
|
+
self._log_level, self._log_format, self._tracing_enabled
|
|
528
|
+
)
|
|
529
|
+
return repr_str
|
|
530
|
+
|
|
531
|
+
def __str__(self) -> str:
|
|
532
|
+
"""
|
|
533
|
+
Returns a human-readable summary of the configuration.
|
|
534
|
+
|
|
535
|
+
:returns: A human-readable string.
|
|
536
|
+
"""
|
|
537
|
+
str_val = (
|
|
538
|
+
"ObservabilityConfiguration: log_level={}, log_format={}, "
|
|
539
|
+
"tracing={}, metrics={}, recording={}, debug={}, sampling_rate={}".format(
|
|
540
|
+
self._log_level, self._log_format,
|
|
541
|
+
self._tracing_enabled, self._metrics_enabled,
|
|
542
|
+
self._recording_enabled, self._debug_mode_enabled,
|
|
543
|
+
self._sampling_rate
|
|
544
|
+
)
|
|
545
|
+
)
|
|
546
|
+
return str_val
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Exception class for observability operation failures.
|
|
3
|
+
|
|
4
|
+
Provides ObservabilityError as a specialized subclass of AgentKitError,
|
|
5
|
+
raised when an observability operation fails due to an exporter error,
|
|
6
|
+
recording error, or pipeline configuration error.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
from ccai.agentkit.errors import AgentKitError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ObservabilityError(AgentKitError):
|
|
15
|
+
"""
|
|
16
|
+
Raised when an observability operation fails due to an exporter
|
|
17
|
+
error, recording error, or pipeline configuration error.
|
|
18
|
+
|
|
19
|
+
:param component_name: The name of the component where the failure occurred
|
|
20
|
+
(e.g., exporter class name, recorder name).
|
|
21
|
+
:param operation_name: The name of the operation that failed.
|
|
22
|
+
:param message: A descriptive error message.
|
|
23
|
+
:param cause: An optional exception that caused this error.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, component_name: str, operation_name: str, message: str,
|
|
27
|
+
cause: Optional[Exception] = None) -> None:
|
|
28
|
+
self._component_name = component_name
|
|
29
|
+
self._operation_name = operation_name
|
|
30
|
+
|
|
31
|
+
super().__init__(message, cause=cause)
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def component_name(self) -> str:
|
|
36
|
+
"""
|
|
37
|
+
The name of the component where the failure occurred.
|
|
38
|
+
|
|
39
|
+
:returns: The component name string.
|
|
40
|
+
"""
|
|
41
|
+
return self._component_name
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def operation_name(self) -> str:
|
|
45
|
+
"""
|
|
46
|
+
The name of the operation that failed.
|
|
47
|
+
|
|
48
|
+
:returns: The operation name string.
|
|
49
|
+
"""
|
|
50
|
+
return self._operation_name
|
|
51
|
+
|
|
52
|
+
def __repr__(self) -> str:
|
|
53
|
+
"""
|
|
54
|
+
Returns a detailed string representation including class name,
|
|
55
|
+
component name, operation name, and message.
|
|
56
|
+
|
|
57
|
+
:returns: A repr string for debugging.
|
|
58
|
+
"""
|
|
59
|
+
repr_str = (
|
|
60
|
+
"{}(component_name={!r}, operation_name={!r}, message={!r})"
|
|
61
|
+
).format(
|
|
62
|
+
self.__class__.__name__,
|
|
63
|
+
self._component_name,
|
|
64
|
+
self._operation_name,
|
|
65
|
+
self._message
|
|
66
|
+
)
|
|
67
|
+
return repr_str
|