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,581 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the AgentConfiguration class for declarative agent configuration
|
|
3
|
+
in the codecraftai-agent-kit framework.
|
|
4
|
+
|
|
5
|
+
AgentConfiguration supports loading from dictionaries, JSON, and YAML,
|
|
6
|
+
with validation of required fields, credential reference resolution,
|
|
7
|
+
data profile reference resolution, and serialization that excludes
|
|
8
|
+
resolved credential secret values.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
|
|
14
|
+
from typing import Any
|
|
15
|
+
from typing import List
|
|
16
|
+
from typing import Optional
|
|
17
|
+
|
|
18
|
+
import yaml
|
|
19
|
+
|
|
20
|
+
from ccai.agentkit.errors import ConfigurationError
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AgentConfiguration:
|
|
24
|
+
"""
|
|
25
|
+
Declarative configuration for an agent.
|
|
26
|
+
|
|
27
|
+
Supports loading from dict, JSON string, JSON file, YAML string,
|
|
28
|
+
and YAML file. Validates required fields, resolves credential and
|
|
29
|
+
data profile references through external packages, and provides
|
|
30
|
+
serialization methods that exclude resolved credential secret values.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
REQUIRED_FIELDS: List[str] = ["identity"]
|
|
34
|
+
REQUIRED_IDENTITY_FIELDS: List[str] = ["name", "version"]
|
|
35
|
+
|
|
36
|
+
def __init__(self, identity: dict, settings: Optional[dict] = None,
|
|
37
|
+
credentials: Optional[dict] = None,
|
|
38
|
+
data_profiles: Optional[dict] = None,
|
|
39
|
+
sub_agents: Optional[list] = None,
|
|
40
|
+
resolved_credentials: Optional[dict] = None,
|
|
41
|
+
resolved_data_profiles: Optional[dict] = None) -> None:
|
|
42
|
+
"""
|
|
43
|
+
Initializes an AgentConfiguration instance.
|
|
44
|
+
|
|
45
|
+
This constructor is not intended to be called directly.
|
|
46
|
+
Use the class methods from_dict, from_json, from_yaml,
|
|
47
|
+
from_json_file, or from_yaml_file instead.
|
|
48
|
+
|
|
49
|
+
:param identity: Dictionary containing identity fields.
|
|
50
|
+
:param settings: Optional dictionary of agent settings.
|
|
51
|
+
:param credentials: Optional dictionary of credential references.
|
|
52
|
+
:param data_profiles: Optional dictionary of data profile references.
|
|
53
|
+
:param sub_agents: Optional list of sub-agent configuration dicts.
|
|
54
|
+
:param resolved_credentials: Optional dictionary of resolved credential objects.
|
|
55
|
+
:param resolved_data_profiles: Optional dictionary of resolved data profile objects.
|
|
56
|
+
"""
|
|
57
|
+
self._identity = dict(identity)
|
|
58
|
+
|
|
59
|
+
if settings is not None:
|
|
60
|
+
self._settings = dict(settings)
|
|
61
|
+
else:
|
|
62
|
+
self._settings = {}
|
|
63
|
+
|
|
64
|
+
if credentials is not None:
|
|
65
|
+
self._credentials = dict(credentials)
|
|
66
|
+
else:
|
|
67
|
+
self._credentials = {}
|
|
68
|
+
|
|
69
|
+
if data_profiles is not None:
|
|
70
|
+
self._data_profiles = dict(data_profiles)
|
|
71
|
+
else:
|
|
72
|
+
self._data_profiles = {}
|
|
73
|
+
|
|
74
|
+
if sub_agents is not None:
|
|
75
|
+
self._sub_agents = list(sub_agents)
|
|
76
|
+
else:
|
|
77
|
+
self._sub_agents = []
|
|
78
|
+
|
|
79
|
+
if resolved_credentials is not None:
|
|
80
|
+
self._resolved_credentials = dict(resolved_credentials)
|
|
81
|
+
else:
|
|
82
|
+
self._resolved_credentials = {}
|
|
83
|
+
|
|
84
|
+
if resolved_data_profiles is not None:
|
|
85
|
+
self._resolved_data_profiles = dict(resolved_data_profiles)
|
|
86
|
+
else:
|
|
87
|
+
self._resolved_data_profiles = {}
|
|
88
|
+
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def identity(self) -> dict:
|
|
93
|
+
"""
|
|
94
|
+
A defensive copy of the identity configuration dictionary.
|
|
95
|
+
|
|
96
|
+
:returns: A dictionary containing identity fields.
|
|
97
|
+
"""
|
|
98
|
+
return dict(self._identity)
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def settings(self) -> dict:
|
|
102
|
+
"""
|
|
103
|
+
A defensive copy of the settings dictionary.
|
|
104
|
+
|
|
105
|
+
:returns: A dictionary containing agent settings.
|
|
106
|
+
"""
|
|
107
|
+
return dict(self._settings)
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def credentials(self) -> dict:
|
|
111
|
+
"""
|
|
112
|
+
A defensive copy of the credential reference dictionary.
|
|
113
|
+
|
|
114
|
+
Contains reference names only, not resolved secret values.
|
|
115
|
+
|
|
116
|
+
:returns: A dictionary of credential references.
|
|
117
|
+
"""
|
|
118
|
+
return dict(self._credentials)
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def data_profiles(self) -> dict:
|
|
122
|
+
"""
|
|
123
|
+
A defensive copy of the data profile reference dictionary.
|
|
124
|
+
|
|
125
|
+
Contains reference names only, not resolved values.
|
|
126
|
+
|
|
127
|
+
:returns: A dictionary of data profile references.
|
|
128
|
+
"""
|
|
129
|
+
return dict(self._data_profiles)
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def sub_agents(self) -> list:
|
|
133
|
+
"""
|
|
134
|
+
A defensive copy of the sub-agent configuration list.
|
|
135
|
+
|
|
136
|
+
:returns: A list of sub-agent configuration dictionaries.
|
|
137
|
+
"""
|
|
138
|
+
return list(self._sub_agents)
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def resolved_credentials(self) -> dict:
|
|
142
|
+
"""
|
|
143
|
+
A defensive copy of the resolved credential objects.
|
|
144
|
+
|
|
145
|
+
:returns: A dictionary of resolved credential objects.
|
|
146
|
+
"""
|
|
147
|
+
return dict(self._resolved_credentials)
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def resolved_data_profiles(self) -> dict:
|
|
151
|
+
"""
|
|
152
|
+
A defensive copy of the resolved data profile objects.
|
|
153
|
+
|
|
154
|
+
:returns: A dictionary of resolved data profile objects.
|
|
155
|
+
"""
|
|
156
|
+
return dict(self._resolved_data_profiles)
|
|
157
|
+
|
|
158
|
+
@classmethod
|
|
159
|
+
def _validate_config_data(cls, config_data: dict) -> None:
|
|
160
|
+
"""
|
|
161
|
+
Validates that the configuration dictionary contains all required fields.
|
|
162
|
+
|
|
163
|
+
:param config_data: The configuration dictionary to validate.
|
|
164
|
+
|
|
165
|
+
:raises: ConfigurationError
|
|
166
|
+
"""
|
|
167
|
+
if not isinstance(config_data, dict):
|
|
168
|
+
err_msg_lines = [
|
|
169
|
+
"Configuration data must be a dictionary."
|
|
170
|
+
]
|
|
171
|
+
err_msg_lines.append(" Received type: {}".format(type(config_data).__name__))
|
|
172
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
173
|
+
raise ConfigurationError(err_msg)
|
|
174
|
+
|
|
175
|
+
for field in cls.REQUIRED_FIELDS:
|
|
176
|
+
has_field = field in config_data
|
|
177
|
+
if has_field is not True:
|
|
178
|
+
err_msg_lines = [
|
|
179
|
+
"Missing required configuration field."
|
|
180
|
+
]
|
|
181
|
+
err_msg_lines.append(" Missing field: {!r}".format(field))
|
|
182
|
+
err_msg_lines.append(" Required fields: {}".format(cls.REQUIRED_FIELDS))
|
|
183
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
184
|
+
raise ConfigurationError(err_msg)
|
|
185
|
+
|
|
186
|
+
identity_data = config_data["identity"]
|
|
187
|
+
|
|
188
|
+
if not isinstance(identity_data, dict):
|
|
189
|
+
err_msg_lines = [
|
|
190
|
+
"The 'identity' field must be a dictionary."
|
|
191
|
+
]
|
|
192
|
+
err_msg_lines.append(" Received type: {}".format(type(identity_data).__name__))
|
|
193
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
194
|
+
raise ConfigurationError(err_msg)
|
|
195
|
+
|
|
196
|
+
for field in cls.REQUIRED_IDENTITY_FIELDS:
|
|
197
|
+
has_field = field in identity_data
|
|
198
|
+
if has_field is not True:
|
|
199
|
+
err_msg_lines = [
|
|
200
|
+
"Missing required identity field."
|
|
201
|
+
]
|
|
202
|
+
err_msg_lines.append(" Missing field: {!r}".format(field))
|
|
203
|
+
err_msg_lines.append(" Required identity fields: {}".format(cls.REQUIRED_IDENTITY_FIELDS))
|
|
204
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
205
|
+
raise ConfigurationError(err_msg)
|
|
206
|
+
|
|
207
|
+
return
|
|
208
|
+
|
|
209
|
+
@classmethod
|
|
210
|
+
def _resolve_credentials(cls, credentials_data: dict, app_context: Any) -> dict:
|
|
211
|
+
"""
|
|
212
|
+
Resolves credential references through the credential manager.
|
|
213
|
+
|
|
214
|
+
:param credentials_data: Dictionary of credential reference entries.
|
|
215
|
+
:param app_context: The application context providing credential manager access.
|
|
216
|
+
|
|
217
|
+
:returns: A dictionary mapping credential names to resolved credential objects.
|
|
218
|
+
:raises: ConfigurationError
|
|
219
|
+
"""
|
|
220
|
+
resolved = {}
|
|
221
|
+
|
|
222
|
+
for cred_name, cred_ref in credentials_data.items():
|
|
223
|
+
provider = cred_ref.get("provider", "")
|
|
224
|
+
key = cred_ref.get("key", "")
|
|
225
|
+
|
|
226
|
+
try:
|
|
227
|
+
credential_manager = app_context.credential_manager
|
|
228
|
+
resolved_cred = credential_manager.lookup_credential(key)
|
|
229
|
+
# A core ccai.errors ConfigurationError (e.g. a missing vault key)
|
|
230
|
+
# derives from BaseException and deliberately passes through this
|
|
231
|
+
# handler: a wrong configuration must terminate the run.
|
|
232
|
+
except Exception as exc:
|
|
233
|
+
err_msg_lines = [
|
|
234
|
+
"Failed to resolve credential reference."
|
|
235
|
+
]
|
|
236
|
+
err_msg_lines.append(" Credential name: {!r}".format(cred_name))
|
|
237
|
+
err_msg_lines.append(" Provider: {!r}".format(provider))
|
|
238
|
+
err_msg_lines.append(" Key: {!r}".format(key))
|
|
239
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
240
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
241
|
+
|
|
242
|
+
if resolved_cred is None:
|
|
243
|
+
err_msg_lines = [
|
|
244
|
+
"Unresolvable credential reference."
|
|
245
|
+
]
|
|
246
|
+
err_msg_lines.append(" Credential name: {!r}".format(cred_name))
|
|
247
|
+
err_msg_lines.append(" Provider: {!r}".format(provider))
|
|
248
|
+
err_msg_lines.append(" Key: {!r}".format(key))
|
|
249
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
250
|
+
raise ConfigurationError(err_msg)
|
|
251
|
+
|
|
252
|
+
resolved[cred_name] = resolved_cred
|
|
253
|
+
|
|
254
|
+
return resolved
|
|
255
|
+
|
|
256
|
+
@classmethod
|
|
257
|
+
def _resolve_data_profiles(cls, data_profiles_data: dict, app_context: Any) -> dict:
|
|
258
|
+
"""
|
|
259
|
+
Resolves data profile references through the data profile manager.
|
|
260
|
+
|
|
261
|
+
:param data_profiles_data: Dictionary of data profile reference entries.
|
|
262
|
+
:param app_context: The application context providing data profile manager access.
|
|
263
|
+
|
|
264
|
+
:returns: A dictionary mapping data profile names to resolved data profile objects.
|
|
265
|
+
:raises: ConfigurationError
|
|
266
|
+
"""
|
|
267
|
+
resolved = {}
|
|
268
|
+
|
|
269
|
+
for profile_name, profile_ref in data_profiles_data.items():
|
|
270
|
+
provider = profile_ref.get("provider", "")
|
|
271
|
+
key = profile_ref.get("key", "")
|
|
272
|
+
|
|
273
|
+
try:
|
|
274
|
+
data_profile_manager = app_context.data_profile_manager
|
|
275
|
+
resolved_profile = data_profile_manager.lookup_data_profile(key)
|
|
276
|
+
except Exception as exc:
|
|
277
|
+
err_msg_lines = [
|
|
278
|
+
"Failed to resolve data profile reference."
|
|
279
|
+
]
|
|
280
|
+
err_msg_lines.append(" Data profile name: {!r}".format(profile_name))
|
|
281
|
+
err_msg_lines.append(" Provider: {!r}".format(provider))
|
|
282
|
+
err_msg_lines.append(" Key: {!r}".format(key))
|
|
283
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
284
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
285
|
+
|
|
286
|
+
if resolved_profile is None:
|
|
287
|
+
err_msg_lines = [
|
|
288
|
+
"Unresolvable data profile reference."
|
|
289
|
+
]
|
|
290
|
+
err_msg_lines.append(" Data profile name: {!r}".format(profile_name))
|
|
291
|
+
err_msg_lines.append(" Provider: {!r}".format(provider))
|
|
292
|
+
err_msg_lines.append(" Key: {!r}".format(key))
|
|
293
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
294
|
+
raise ConfigurationError(err_msg)
|
|
295
|
+
|
|
296
|
+
resolved[profile_name] = resolved_profile
|
|
297
|
+
|
|
298
|
+
return resolved
|
|
299
|
+
|
|
300
|
+
@classmethod
|
|
301
|
+
def from_dict(cls, config_data: dict, app_context: Any = None) -> "AgentConfiguration":
|
|
302
|
+
"""
|
|
303
|
+
Creates an AgentConfiguration from a dictionary.
|
|
304
|
+
|
|
305
|
+
Validates required fields, resolves credential and data profile
|
|
306
|
+
references if present, and returns a configured instance.
|
|
307
|
+
|
|
308
|
+
:param config_data: The configuration dictionary.
|
|
309
|
+
:param app_context: Optional application context for resolving
|
|
310
|
+
credentials, data profiles, file paths, and environment variables.
|
|
311
|
+
|
|
312
|
+
:returns: An AgentConfiguration instance.
|
|
313
|
+
:raises: ConfigurationError
|
|
314
|
+
"""
|
|
315
|
+
cls._validate_config_data(config_data)
|
|
316
|
+
|
|
317
|
+
identity_data = dict(config_data["identity"])
|
|
318
|
+
settings_data = config_data.get("settings", None)
|
|
319
|
+
credentials_data = config_data.get("credentials", None)
|
|
320
|
+
data_profiles_data = config_data.get("data_profiles", None)
|
|
321
|
+
sub_agents_data = config_data.get("sub_agents", None)
|
|
322
|
+
|
|
323
|
+
resolved_credentials = {}
|
|
324
|
+
resolved_data_profiles = {}
|
|
325
|
+
|
|
326
|
+
has_credentials = credentials_data is not None and len(credentials_data) > 0
|
|
327
|
+
has_data_profiles = data_profiles_data is not None and len(data_profiles_data) > 0
|
|
328
|
+
|
|
329
|
+
needs_app_context = has_credentials or has_data_profiles
|
|
330
|
+
|
|
331
|
+
if needs_app_context is True and app_context is None:
|
|
332
|
+
err_msg_lines = [
|
|
333
|
+
"Application context is required but was not provided."
|
|
334
|
+
]
|
|
335
|
+
err_msg_lines.append(" codecraftai-this-app must be initialized before creating agents.")
|
|
336
|
+
err_msg_lines.append(" App context is needed to resolve credential and data profile references.")
|
|
337
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
338
|
+
raise ConfigurationError(err_msg)
|
|
339
|
+
|
|
340
|
+
if has_credentials is True:
|
|
341
|
+
resolved_credentials = cls._resolve_credentials(credentials_data, app_context)
|
|
342
|
+
|
|
343
|
+
if has_data_profiles is True:
|
|
344
|
+
resolved_data_profiles = cls._resolve_data_profiles(data_profiles_data, app_context)
|
|
345
|
+
|
|
346
|
+
configuration = cls(
|
|
347
|
+
identity=identity_data,
|
|
348
|
+
settings=settings_data,
|
|
349
|
+
credentials=credentials_data,
|
|
350
|
+
data_profiles=data_profiles_data,
|
|
351
|
+
sub_agents=sub_agents_data,
|
|
352
|
+
resolved_credentials=resolved_credentials,
|
|
353
|
+
resolved_data_profiles=resolved_data_profiles
|
|
354
|
+
)
|
|
355
|
+
return configuration
|
|
356
|
+
|
|
357
|
+
@classmethod
|
|
358
|
+
def from_json(cls, json_str: str, app_context: Any = None) -> "AgentConfiguration":
|
|
359
|
+
"""
|
|
360
|
+
Creates an AgentConfiguration from a JSON string.
|
|
361
|
+
|
|
362
|
+
:param json_str: A JSON string containing configuration data.
|
|
363
|
+
:param app_context: Optional application context for resolving references.
|
|
364
|
+
|
|
365
|
+
:returns: An AgentConfiguration instance.
|
|
366
|
+
:raises: ConfigurationError
|
|
367
|
+
"""
|
|
368
|
+
try:
|
|
369
|
+
config_data = json.loads(json_str)
|
|
370
|
+
except (json.JSONDecodeError, TypeError) as exc:
|
|
371
|
+
err_msg_lines = [
|
|
372
|
+
"Failed to parse JSON configuration string."
|
|
373
|
+
]
|
|
374
|
+
err_msg_lines.append(" Error: {}".format(str(exc)))
|
|
375
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
376
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
377
|
+
|
|
378
|
+
configuration = cls.from_dict(config_data, app_context=app_context)
|
|
379
|
+
return configuration
|
|
380
|
+
|
|
381
|
+
@classmethod
|
|
382
|
+
def from_json_file(cls, file_path: str, app_context: Any = None) -> "AgentConfiguration":
|
|
383
|
+
"""
|
|
384
|
+
Creates an AgentConfiguration from a JSON file.
|
|
385
|
+
|
|
386
|
+
If app_context is provided, the file path is resolved relative
|
|
387
|
+
to the AppContext directory.
|
|
388
|
+
|
|
389
|
+
:param file_path: Path to the JSON configuration file.
|
|
390
|
+
:param app_context: Optional application context for resolving
|
|
391
|
+
the file path and references.
|
|
392
|
+
|
|
393
|
+
:returns: An AgentConfiguration instance.
|
|
394
|
+
:raises: ConfigurationError
|
|
395
|
+
"""
|
|
396
|
+
resolved_path = file_path
|
|
397
|
+
|
|
398
|
+
if app_context is not None:
|
|
399
|
+
try:
|
|
400
|
+
base_dir = app_context.directory
|
|
401
|
+
resolved_path = os.path.join(base_dir, file_path)
|
|
402
|
+
except Exception:
|
|
403
|
+
resolved_path = file_path
|
|
404
|
+
|
|
405
|
+
try:
|
|
406
|
+
with open(resolved_path, "r") as file_handle:
|
|
407
|
+
json_str = file_handle.read()
|
|
408
|
+
except (OSError, IOError) as exc:
|
|
409
|
+
err_msg_lines = [
|
|
410
|
+
"Failed to read JSON configuration file."
|
|
411
|
+
]
|
|
412
|
+
err_msg_lines.append(" File path: {!r}".format(resolved_path))
|
|
413
|
+
err_msg_lines.append(" Error: {}".format(str(exc)))
|
|
414
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
415
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
416
|
+
|
|
417
|
+
configuration = cls.from_json(json_str, app_context=app_context)
|
|
418
|
+
return configuration
|
|
419
|
+
|
|
420
|
+
@classmethod
|
|
421
|
+
def from_yaml(cls, yaml_str: str, app_context: Any = None) -> "AgentConfiguration":
|
|
422
|
+
"""
|
|
423
|
+
Creates an AgentConfiguration from a YAML string.
|
|
424
|
+
|
|
425
|
+
:param yaml_str: A YAML string containing configuration data.
|
|
426
|
+
:param app_context: Optional application context for resolving references.
|
|
427
|
+
|
|
428
|
+
:returns: An AgentConfiguration instance.
|
|
429
|
+
:raises: ConfigurationError
|
|
430
|
+
"""
|
|
431
|
+
try:
|
|
432
|
+
config_data = yaml.safe_load(yaml_str)
|
|
433
|
+
except yaml.YAMLError as exc:
|
|
434
|
+
err_msg_lines = [
|
|
435
|
+
"Failed to parse YAML configuration string."
|
|
436
|
+
]
|
|
437
|
+
err_msg_lines.append(" Error: {}".format(str(exc)))
|
|
438
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
439
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
440
|
+
|
|
441
|
+
configuration = cls.from_dict(config_data, app_context=app_context)
|
|
442
|
+
return configuration
|
|
443
|
+
|
|
444
|
+
@classmethod
|
|
445
|
+
def from_yaml_file(cls, file_path: str, app_context: Any = None) -> "AgentConfiguration":
|
|
446
|
+
"""
|
|
447
|
+
Creates an AgentConfiguration from a YAML file.
|
|
448
|
+
|
|
449
|
+
If app_context is provided, the file path is resolved relative
|
|
450
|
+
to the AppContext directory.
|
|
451
|
+
|
|
452
|
+
:param file_path: Path to the YAML configuration file.
|
|
453
|
+
:param app_context: Optional application context for resolving
|
|
454
|
+
the file path and references.
|
|
455
|
+
|
|
456
|
+
:returns: An AgentConfiguration instance.
|
|
457
|
+
:raises: ConfigurationError
|
|
458
|
+
"""
|
|
459
|
+
resolved_path = file_path
|
|
460
|
+
|
|
461
|
+
if app_context is not None:
|
|
462
|
+
try:
|
|
463
|
+
base_dir = app_context.directory
|
|
464
|
+
resolved_path = os.path.join(base_dir, file_path)
|
|
465
|
+
except Exception:
|
|
466
|
+
resolved_path = file_path
|
|
467
|
+
|
|
468
|
+
try:
|
|
469
|
+
with open(resolved_path, "r") as file_handle:
|
|
470
|
+
yaml_str = file_handle.read()
|
|
471
|
+
except (OSError, IOError) as exc:
|
|
472
|
+
err_msg_lines = [
|
|
473
|
+
"Failed to read YAML configuration file."
|
|
474
|
+
]
|
|
475
|
+
err_msg_lines.append(" File path: {!r}".format(resolved_path))
|
|
476
|
+
err_msg_lines.append(" Error: {}".format(str(exc)))
|
|
477
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
478
|
+
raise ConfigurationError(err_msg, cause=exc)
|
|
479
|
+
|
|
480
|
+
configuration = cls.from_yaml(yaml_str, app_context=app_context)
|
|
481
|
+
return configuration
|
|
482
|
+
|
|
483
|
+
def as_dict(self) -> dict:
|
|
484
|
+
"""
|
|
485
|
+
Returns a dictionary representation of the configuration.
|
|
486
|
+
|
|
487
|
+
Excludes resolved credential secret values. Includes credential
|
|
488
|
+
reference names but not resolved values.
|
|
489
|
+
|
|
490
|
+
:returns: A dictionary containing the configuration data.
|
|
491
|
+
"""
|
|
492
|
+
result = {
|
|
493
|
+
"identity": dict(self._identity)
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if len(self._settings) > 0:
|
|
497
|
+
result["settings"] = dict(self._settings)
|
|
498
|
+
|
|
499
|
+
if len(self._credentials) > 0:
|
|
500
|
+
result["credentials"] = dict(self._credentials)
|
|
501
|
+
|
|
502
|
+
if len(self._data_profiles) > 0:
|
|
503
|
+
result["data_profiles"] = dict(self._data_profiles)
|
|
504
|
+
|
|
505
|
+
if len(self._sub_agents) > 0:
|
|
506
|
+
result["sub_agents"] = list(self._sub_agents)
|
|
507
|
+
|
|
508
|
+
return result
|
|
509
|
+
|
|
510
|
+
def to_json(self) -> str:
|
|
511
|
+
"""
|
|
512
|
+
Returns a JSON string representation of the configuration.
|
|
513
|
+
|
|
514
|
+
Excludes resolved credential secret values.
|
|
515
|
+
|
|
516
|
+
:returns: A JSON string containing the configuration data.
|
|
517
|
+
"""
|
|
518
|
+
data = self.as_dict()
|
|
519
|
+
json_str = json.dumps(data)
|
|
520
|
+
return json_str
|
|
521
|
+
|
|
522
|
+
def to_yaml(self) -> str:
|
|
523
|
+
"""
|
|
524
|
+
Returns a YAML string representation of the configuration.
|
|
525
|
+
|
|
526
|
+
Excludes resolved credential secret values.
|
|
527
|
+
|
|
528
|
+
:returns: A YAML string containing the configuration data.
|
|
529
|
+
"""
|
|
530
|
+
data = self.as_dict()
|
|
531
|
+
yaml_str = yaml.dump(data, default_flow_style=False)
|
|
532
|
+
return yaml_str
|
|
533
|
+
|
|
534
|
+
def get_platform_configuration(self):
|
|
535
|
+
"""
|
|
536
|
+
Returns a PlatformConfiguration from the settings dictionary
|
|
537
|
+
if a 'platform' key is present, otherwise returns None.
|
|
538
|
+
|
|
539
|
+
The platform configuration is constructed from the 'platform'
|
|
540
|
+
sub-dictionary within settings using PlatformConfiguration.from_dict.
|
|
541
|
+
|
|
542
|
+
:returns: A PlatformConfiguration instance or None.
|
|
543
|
+
"""
|
|
544
|
+
platform_data = self._settings.get("platform", None)
|
|
545
|
+
if platform_data is None:
|
|
546
|
+
rtnval = None
|
|
547
|
+
return rtnval
|
|
548
|
+
|
|
549
|
+
from ccai.agentkit.platform.platformconfiguration import PlatformConfiguration
|
|
550
|
+
|
|
551
|
+
rtnval = PlatformConfiguration.from_dict(platform_data)
|
|
552
|
+
return rtnval
|
|
553
|
+
|
|
554
|
+
def __repr__(self) -> str:
|
|
555
|
+
"""
|
|
556
|
+
Returns a detailed string representation including class name
|
|
557
|
+
and identity configuration. Excludes resolved credential values.
|
|
558
|
+
|
|
559
|
+
:returns: A repr string for debugging.
|
|
560
|
+
"""
|
|
561
|
+
repr_str = "AgentConfiguration(identity={!r})".format(self._identity)
|
|
562
|
+
return repr_str
|
|
563
|
+
|
|
564
|
+
def __str__(self) -> str:
|
|
565
|
+
"""
|
|
566
|
+
Returns a human-readable summary of the configuration.
|
|
567
|
+
|
|
568
|
+
Excludes resolved credential values.
|
|
569
|
+
|
|
570
|
+
:returns: A human-readable string.
|
|
571
|
+
"""
|
|
572
|
+
identity_name = self._identity.get("name", "unknown")
|
|
573
|
+
identity_version = self._identity.get("version", "unknown")
|
|
574
|
+
cred_count = len(self._credentials)
|
|
575
|
+
profile_count = len(self._data_profiles)
|
|
576
|
+
settings_count = len(self._settings)
|
|
577
|
+
|
|
578
|
+
str_val = "AgentConfiguration: {} v{} (credentials={}, data_profiles={}, settings={})".format(
|
|
579
|
+
identity_name, identity_version, cred_count, profile_count, settings_count
|
|
580
|
+
)
|
|
581
|
+
return str_val
|