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,185 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the WorkflowRegistry class for tracking
|
|
3
|
+
WorkflowDefinition instances available to an Agent in the
|
|
4
|
+
Workflow & Orchestration feature.
|
|
5
|
+
|
|
6
|
+
The WorkflowRegistry uses a composite key of workflow name
|
|
7
|
+
and version for registration and lookup. It supports
|
|
8
|
+
registration, deregistration, lookup (with latest-version
|
|
9
|
+
fallback), enumeration, and existence checks.
|
|
10
|
+
|
|
11
|
+
Requirements: 16.1-16.9, 23.19, 23.20
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from ccai.agentkit.errors import SemanticError
|
|
15
|
+
from ccai.agentkit.workflowdefinition import WorkflowDefinition
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class WorkflowRegistry:
|
|
19
|
+
"""
|
|
20
|
+
Registry tracking WorkflowDefinition instances for an Agent.
|
|
21
|
+
|
|
22
|
+
Uses a composite key of workflow name and version. Supports
|
|
23
|
+
registration with duplicate detection, deregistration,
|
|
24
|
+
lookup with optional latest-version fallback, enumeration,
|
|
25
|
+
and existence checks.
|
|
26
|
+
|
|
27
|
+
:raises SemanticError: When registering a duplicate
|
|
28
|
+
name+version combination.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self) -> None:
|
|
32
|
+
self._workflows = {}
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
def register(self, workflow: WorkflowDefinition) -> None:
|
|
36
|
+
"""
|
|
37
|
+
Registers a WorkflowDefinition using name+version as
|
|
38
|
+
the composite key.
|
|
39
|
+
|
|
40
|
+
:param workflow: The WorkflowDefinition to register.
|
|
41
|
+
|
|
42
|
+
:raises SemanticError: If a WorkflowDefinition with
|
|
43
|
+
the same name and version is already registered.
|
|
44
|
+
"""
|
|
45
|
+
key = (workflow.name, workflow.version)
|
|
46
|
+
|
|
47
|
+
if key in self._workflows:
|
|
48
|
+
errmsg = (
|
|
49
|
+
"A workflow with name '{}' and version '{}' is "
|
|
50
|
+
"already registered."
|
|
51
|
+
).format(workflow.name, workflow.version)
|
|
52
|
+
raise SemanticError(errmsg)
|
|
53
|
+
|
|
54
|
+
self._workflows[key] = workflow
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
def deregister(self, name: str, version: str) -> None:
|
|
58
|
+
"""
|
|
59
|
+
Removes a WorkflowDefinition by name and version.
|
|
60
|
+
|
|
61
|
+
If no matching workflow is found, the operation is
|
|
62
|
+
a no-op.
|
|
63
|
+
|
|
64
|
+
:param name: The workflow name.
|
|
65
|
+
:param version: The workflow version.
|
|
66
|
+
"""
|
|
67
|
+
key = (name, version)
|
|
68
|
+
|
|
69
|
+
if key in self._workflows:
|
|
70
|
+
del self._workflows[key]
|
|
71
|
+
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
def lookup(self, name: str,
|
|
75
|
+
version: str = None) -> WorkflowDefinition:
|
|
76
|
+
"""
|
|
77
|
+
Returns the WorkflowDefinition matching name and
|
|
78
|
+
version.
|
|
79
|
+
|
|
80
|
+
When version is None, returns the workflow with the
|
|
81
|
+
latest version string (lexicographic ordering).
|
|
82
|
+
Returns None when no matching workflow is found.
|
|
83
|
+
|
|
84
|
+
:param name: The workflow name.
|
|
85
|
+
:param version: The optional workflow version. When
|
|
86
|
+
None, the latest version is returned.
|
|
87
|
+
|
|
88
|
+
:returns: The matching WorkflowDefinition or None.
|
|
89
|
+
"""
|
|
90
|
+
if version is not None:
|
|
91
|
+
key = (name, version)
|
|
92
|
+
rtnval = self._workflows.get(key, None)
|
|
93
|
+
return rtnval
|
|
94
|
+
|
|
95
|
+
# Find all workflows with the given name and return the
|
|
96
|
+
# one with the latest version (lexicographic ordering).
|
|
97
|
+
candidates = [
|
|
98
|
+
wf for (wf_name, wf_version), wf in self._workflows.items()
|
|
99
|
+
if wf_name == name
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
if len(candidates) == 0:
|
|
103
|
+
return None
|
|
104
|
+
|
|
105
|
+
candidates.sort(key=lambda wf: wf.version)
|
|
106
|
+
rtnval = candidates[-1]
|
|
107
|
+
return rtnval
|
|
108
|
+
|
|
109
|
+
def list_all(self) -> list:
|
|
110
|
+
"""
|
|
111
|
+
Returns all registered WorkflowDefinition instances
|
|
112
|
+
as a list.
|
|
113
|
+
|
|
114
|
+
:returns: A list of WorkflowDefinition instances.
|
|
115
|
+
"""
|
|
116
|
+
rtnval = list(self._workflows.values())
|
|
117
|
+
return rtnval
|
|
118
|
+
|
|
119
|
+
def has_workflow(self, name: str,
|
|
120
|
+
version: str = None) -> bool:
|
|
121
|
+
"""
|
|
122
|
+
Returns True if a matching WorkflowDefinition is
|
|
123
|
+
registered.
|
|
124
|
+
|
|
125
|
+
When version is None, returns True if any version
|
|
126
|
+
of the named workflow is registered.
|
|
127
|
+
|
|
128
|
+
:param name: The workflow name.
|
|
129
|
+
:param version: The optional workflow version.
|
|
130
|
+
|
|
131
|
+
:returns: True if a matching workflow is registered.
|
|
132
|
+
"""
|
|
133
|
+
if version is not None:
|
|
134
|
+
key = (name, version)
|
|
135
|
+
rtnval = key in self._workflows
|
|
136
|
+
return rtnval
|
|
137
|
+
|
|
138
|
+
for (wf_name, _wf_version) in self._workflows:
|
|
139
|
+
if wf_name == name:
|
|
140
|
+
return True
|
|
141
|
+
|
|
142
|
+
return False
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def count(self) -> int:
|
|
146
|
+
"""
|
|
147
|
+
The count of currently registered workflows.
|
|
148
|
+
|
|
149
|
+
:returns: An integer count.
|
|
150
|
+
"""
|
|
151
|
+
rtnval = len(self._workflows)
|
|
152
|
+
return rtnval
|
|
153
|
+
|
|
154
|
+
def __repr__(self) -> str:
|
|
155
|
+
"""
|
|
156
|
+
Returns a detailed string representation including the
|
|
157
|
+
class name and the count of registered workflows.
|
|
158
|
+
|
|
159
|
+
:returns: A repr string for debugging.
|
|
160
|
+
"""
|
|
161
|
+
repr_str = "{}(count={})".format(
|
|
162
|
+
self.__class__.__name__, self.count
|
|
163
|
+
)
|
|
164
|
+
return repr_str
|
|
165
|
+
|
|
166
|
+
def __str__(self) -> str:
|
|
167
|
+
"""
|
|
168
|
+
Returns a human-readable summary listing the registered
|
|
169
|
+
workflow names and versions.
|
|
170
|
+
|
|
171
|
+
:returns: A human-readable string describing the
|
|
172
|
+
registry contents.
|
|
173
|
+
"""
|
|
174
|
+
if self.count == 0:
|
|
175
|
+
str_val = "WorkflowRegistry: 0 workflows registered"
|
|
176
|
+
return str_val
|
|
177
|
+
|
|
178
|
+
entries = []
|
|
179
|
+
for (wf_name, wf_version) in sorted(self._workflows.keys()):
|
|
180
|
+
entries.append("{}@{}".format(wf_name, wf_version))
|
|
181
|
+
|
|
182
|
+
str_val = "WorkflowRegistry: {} workflow(s) registered [{}]".format(
|
|
183
|
+
self.count, ", ".join(entries)
|
|
184
|
+
)
|
|
185
|
+
return str_val
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the WorkflowResult class representing an immutable object
|
|
3
|
+
encapsulating the outcome of a workflow execution in the Workflow
|
|
4
|
+
& Orchestration feature.
|
|
5
|
+
|
|
6
|
+
A WorkflowResult contains the workflow name, overall execution
|
|
7
|
+
status, the list of individual StepResult objects, the final
|
|
8
|
+
output dictionary from terminal steps, total execution duration
|
|
9
|
+
in seconds, and optional error information. The class provides
|
|
10
|
+
JSON serialization and deserialization for persistence and
|
|
11
|
+
transmission.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
|
|
16
|
+
from typing import List, Optional
|
|
17
|
+
|
|
18
|
+
from ccai.agentkit.workflowexecutionstatus import WorkflowExecutionStatus
|
|
19
|
+
from ccai.agentkit.stepresult import StepResult
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class WorkflowResult:
|
|
23
|
+
"""
|
|
24
|
+
Immutable object encapsulating the outcome of a workflow
|
|
25
|
+
execution.
|
|
26
|
+
|
|
27
|
+
A WorkflowResult captures the workflow name, overall
|
|
28
|
+
execution status, the list of StepResult objects for each
|
|
29
|
+
executed step, the final output dictionary from terminal
|
|
30
|
+
steps, total execution duration in seconds, and optional
|
|
31
|
+
error information. All fields are exposed as read-only
|
|
32
|
+
properties. The is_success property returns True when the
|
|
33
|
+
execution status is COMPLETED.
|
|
34
|
+
|
|
35
|
+
:param workflow_name: The name of the executed workflow.
|
|
36
|
+
:param status: The WorkflowExecutionStatus indicating the
|
|
37
|
+
overall outcome.
|
|
38
|
+
:param step_results: An optional list of StepResult objects
|
|
39
|
+
for each executed step. Defaults to an empty list.
|
|
40
|
+
:param final_output: An optional dictionary of final output
|
|
41
|
+
values from terminal steps. Defaults to an empty dictionary.
|
|
42
|
+
:param duration: The total execution duration in seconds as
|
|
43
|
+
a float. Defaults to 0.0.
|
|
44
|
+
:param error: An optional error message string when the
|
|
45
|
+
workflow failed or encountered an error.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def __init__(self, workflow_name: str, status: WorkflowExecutionStatus,
|
|
49
|
+
step_results: Optional[List[StepResult]] = None,
|
|
50
|
+
final_output: Optional[dict] = None,
|
|
51
|
+
duration: float = 0.0,
|
|
52
|
+
error: Optional[str] = None) -> None:
|
|
53
|
+
self._workflow_name = workflow_name
|
|
54
|
+
self._status = status
|
|
55
|
+
self._step_results = list(step_results) if step_results is not None else []
|
|
56
|
+
self._final_output = dict(final_output) if final_output is not None else {}
|
|
57
|
+
self._duration = duration
|
|
58
|
+
self._error = error
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def workflow_name(self) -> str:
|
|
63
|
+
"""
|
|
64
|
+
The name of the executed workflow.
|
|
65
|
+
|
|
66
|
+
:returns: The workflow name string.
|
|
67
|
+
"""
|
|
68
|
+
return self._workflow_name
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def status(self) -> WorkflowExecutionStatus:
|
|
72
|
+
"""
|
|
73
|
+
The overall execution status indicating the outcome of
|
|
74
|
+
the workflow.
|
|
75
|
+
|
|
76
|
+
:returns: The WorkflowExecutionStatus member.
|
|
77
|
+
"""
|
|
78
|
+
return self._status
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def step_results(self) -> List[StepResult]:
|
|
82
|
+
"""
|
|
83
|
+
The list of StepResult objects for each executed step
|
|
84
|
+
in the workflow.
|
|
85
|
+
|
|
86
|
+
:returns: A list of StepResult objects. Empty list when
|
|
87
|
+
no steps were executed.
|
|
88
|
+
"""
|
|
89
|
+
return self._step_results
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def final_output(self) -> dict:
|
|
93
|
+
"""
|
|
94
|
+
The dictionary of final output values from terminal steps
|
|
95
|
+
in the workflow.
|
|
96
|
+
|
|
97
|
+
:returns: A dictionary of final output values. Empty
|
|
98
|
+
dictionary when no terminal output was produced.
|
|
99
|
+
"""
|
|
100
|
+
return self._final_output
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def duration(self) -> float:
|
|
104
|
+
"""
|
|
105
|
+
The total execution duration in seconds.
|
|
106
|
+
|
|
107
|
+
:returns: The duration as a float in seconds.
|
|
108
|
+
"""
|
|
109
|
+
return self._duration
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def error(self) -> Optional[str]:
|
|
113
|
+
"""
|
|
114
|
+
The error message string when the workflow failed or
|
|
115
|
+
encountered an error.
|
|
116
|
+
|
|
117
|
+
:returns: The error message string or None when no
|
|
118
|
+
error occurred.
|
|
119
|
+
"""
|
|
120
|
+
return self._error
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def is_success(self) -> bool:
|
|
124
|
+
"""
|
|
125
|
+
Indicates whether the workflow execution completed
|
|
126
|
+
successfully.
|
|
127
|
+
|
|
128
|
+
:returns: True when the execution status is COMPLETED,
|
|
129
|
+
False otherwise.
|
|
130
|
+
"""
|
|
131
|
+
rtnval = self._status == WorkflowExecutionStatus.COMPLETED
|
|
132
|
+
return rtnval
|
|
133
|
+
|
|
134
|
+
def get_step_result(self, step_id: str) -> Optional[StepResult]:
|
|
135
|
+
"""
|
|
136
|
+
Returns the StepResult for the step with the given
|
|
137
|
+
identifier, or None when the step was not executed.
|
|
138
|
+
|
|
139
|
+
Iterates the step_results list to find a StepResult
|
|
140
|
+
whose step_id matches the provided identifier.
|
|
141
|
+
|
|
142
|
+
:param step_id: The unique identifier of the step to
|
|
143
|
+
look up.
|
|
144
|
+
|
|
145
|
+
:returns: The matching StepResult or None when the step
|
|
146
|
+
identifier is not found.
|
|
147
|
+
"""
|
|
148
|
+
for step_result in self._step_results:
|
|
149
|
+
if step_result.step_id == step_id:
|
|
150
|
+
return step_result
|
|
151
|
+
|
|
152
|
+
return None
|
|
153
|
+
|
|
154
|
+
def as_dict(self) -> dict:
|
|
155
|
+
"""
|
|
156
|
+
Returns a dictionary representation of the workflow
|
|
157
|
+
result fields.
|
|
158
|
+
|
|
159
|
+
The status is serialized as its string value. The
|
|
160
|
+
step_results are serialized as a list of dictionaries
|
|
161
|
+
using each StepResult's as_dict method.
|
|
162
|
+
|
|
163
|
+
:returns: A dictionary containing workflow_name, status,
|
|
164
|
+
step_results, final_output, duration, and error.
|
|
165
|
+
"""
|
|
166
|
+
step_results_dicts = [sr.as_dict() for sr in self._step_results]
|
|
167
|
+
|
|
168
|
+
rtnval = {
|
|
169
|
+
"workflow_name": self._workflow_name,
|
|
170
|
+
"status": self._status.value,
|
|
171
|
+
"step_results": step_results_dicts,
|
|
172
|
+
"final_output": self._final_output,
|
|
173
|
+
"duration": self._duration,
|
|
174
|
+
"error": self._error
|
|
175
|
+
}
|
|
176
|
+
return rtnval
|
|
177
|
+
|
|
178
|
+
def to_json(self) -> str:
|
|
179
|
+
"""
|
|
180
|
+
Returns a JSON string representation of the workflow
|
|
181
|
+
result fields.
|
|
182
|
+
|
|
183
|
+
:returns: A JSON string containing all workflow result
|
|
184
|
+
fields.
|
|
185
|
+
"""
|
|
186
|
+
data = self.as_dict()
|
|
187
|
+
rtnval = json.dumps(data)
|
|
188
|
+
return rtnval
|
|
189
|
+
|
|
190
|
+
@classmethod
|
|
191
|
+
def from_json(cls, json_str: str) -> "WorkflowResult":
|
|
192
|
+
"""
|
|
193
|
+
Deserializes a JSON string into a WorkflowResult instance.
|
|
194
|
+
|
|
195
|
+
The status field is deserialized using
|
|
196
|
+
WorkflowExecutionStatus.from_string. Each entry in the
|
|
197
|
+
step_results list is deserialized using StepResult.from_json.
|
|
198
|
+
|
|
199
|
+
:param json_str: A JSON string containing workflow result
|
|
200
|
+
fields.
|
|
201
|
+
|
|
202
|
+
:returns: A WorkflowResult instance reconstructed from the
|
|
203
|
+
JSON data.
|
|
204
|
+
"""
|
|
205
|
+
data = json.loads(json_str)
|
|
206
|
+
|
|
207
|
+
status = WorkflowExecutionStatus.from_string(data["status"])
|
|
208
|
+
|
|
209
|
+
step_results = []
|
|
210
|
+
raw_step_results = data.get("step_results", [])
|
|
211
|
+
for sr_data in raw_step_results:
|
|
212
|
+
sr_json = json.dumps(sr_data)
|
|
213
|
+
step_result = StepResult.from_json(sr_json)
|
|
214
|
+
step_results.append(step_result)
|
|
215
|
+
|
|
216
|
+
rtnval = cls(
|
|
217
|
+
workflow_name=data["workflow_name"],
|
|
218
|
+
status=status,
|
|
219
|
+
step_results=step_results,
|
|
220
|
+
final_output=data.get("final_output"),
|
|
221
|
+
duration=data.get("duration", 0.0),
|
|
222
|
+
error=data.get("error")
|
|
223
|
+
)
|
|
224
|
+
return rtnval
|
|
225
|
+
|
|
226
|
+
def __repr__(self) -> str:
|
|
227
|
+
"""
|
|
228
|
+
Returns a detailed string representation including the
|
|
229
|
+
class name, workflow name, and execution status.
|
|
230
|
+
|
|
231
|
+
:returns: A repr string for debugging.
|
|
232
|
+
"""
|
|
233
|
+
repr_str = "{}(workflow_name={!r}, status={})".format(
|
|
234
|
+
self.__class__.__name__, self._workflow_name, self._status.value
|
|
235
|
+
)
|
|
236
|
+
return repr_str
|
|
237
|
+
|
|
238
|
+
def __str__(self) -> str:
|
|
239
|
+
"""
|
|
240
|
+
Returns a human-readable summary including the workflow
|
|
241
|
+
name, status, step count, and total duration.
|
|
242
|
+
|
|
243
|
+
:returns: A human-readable string describing the workflow
|
|
244
|
+
result.
|
|
245
|
+
"""
|
|
246
|
+
step_count = len(self._step_results)
|
|
247
|
+
str_val = "WorkflowResult: {} [status: {}, steps: {}, duration: {:.3f}s]".format(
|
|
248
|
+
self._workflow_name, self._status.value, step_count, self._duration
|
|
249
|
+
)
|
|
250
|
+
return str_val
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the WorkflowStep abstract base class representing a single
|
|
3
|
+
unit of work within a workflow in the Workflow & Orchestration
|
|
4
|
+
feature.
|
|
5
|
+
|
|
6
|
+
A WorkflowStep has a unique step identifier, a human-readable name,
|
|
7
|
+
a step type string, optional input and output schemas, optional tags
|
|
8
|
+
for categorization, and an optional retry policy. Concrete subclasses
|
|
9
|
+
must implement the execute method which accepts a WorkflowContext and
|
|
10
|
+
returns a StepResult.
|
|
11
|
+
|
|
12
|
+
The base class validates that a step identifier and name are provided
|
|
13
|
+
at construction time, raising a SemanticError when either is missing
|
|
14
|
+
or empty.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import abc
|
|
18
|
+
|
|
19
|
+
from typing import Optional
|
|
20
|
+
|
|
21
|
+
from ccai.agentkit.errors import SemanticError
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class WorkflowStep(abc.ABC):
|
|
25
|
+
"""
|
|
26
|
+
Abstract base class representing a single unit of work within
|
|
27
|
+
a workflow.
|
|
28
|
+
|
|
29
|
+
A WorkflowStep defines the interface for all workflow step
|
|
30
|
+
implementations. Each step has a unique identifier, a
|
|
31
|
+
human-readable name, a step type string identifying the kind
|
|
32
|
+
of step, optional input and output schemas describing the
|
|
33
|
+
expected data shapes, optional tags for categorization and
|
|
34
|
+
discovery, and an optional retry policy for configuring
|
|
35
|
+
step-level retry behavior.
|
|
36
|
+
|
|
37
|
+
Concrete subclasses must implement the execute method which
|
|
38
|
+
accepts a WorkflowContext and returns a StepResult.
|
|
39
|
+
|
|
40
|
+
:param step_id: The unique identifier for this step within
|
|
41
|
+
the workflow. Must not be None or empty.
|
|
42
|
+
:param name: The human-readable name for this step. Must
|
|
43
|
+
not be None or empty.
|
|
44
|
+
:param step_type: A string identifying the kind of step
|
|
45
|
+
(e.g. "tool", "llm", "agent", "approval", "subworkflow").
|
|
46
|
+
:param input_schema: An optional dictionary describing the
|
|
47
|
+
expected input data shape. Defaults to an empty dictionary.
|
|
48
|
+
:param output_schema: An optional dictionary describing the
|
|
49
|
+
expected output data shape. Defaults to an empty dictionary.
|
|
50
|
+
:param tags: An optional dictionary of tags for categorization
|
|
51
|
+
and discovery. Defaults to an empty dictionary.
|
|
52
|
+
:param retry_policy: An optional retry policy for configuring
|
|
53
|
+
step-level retry behavior. Defaults to None.
|
|
54
|
+
|
|
55
|
+
:raises SemanticError: When step_id is None or empty after
|
|
56
|
+
stripping whitespace.
|
|
57
|
+
:raises SemanticError: When name is None or empty after
|
|
58
|
+
stripping whitespace.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, step_id: str, name: str, step_type: str,
|
|
62
|
+
input_schema: Optional[dict] = None,
|
|
63
|
+
output_schema: Optional[dict] = None,
|
|
64
|
+
tags: Optional[dict] = None,
|
|
65
|
+
retry_policy=None) -> None:
|
|
66
|
+
self._step_id = step_id
|
|
67
|
+
self._name = name
|
|
68
|
+
self._step_type = step_type
|
|
69
|
+
self._input_schema = dict(input_schema) if input_schema is not None else {}
|
|
70
|
+
self._output_schema = dict(output_schema) if output_schema is not None else {}
|
|
71
|
+
self._tags = dict(tags) if tags is not None else {}
|
|
72
|
+
self._retry_policy = retry_policy
|
|
73
|
+
|
|
74
|
+
if self._step_id is None or len(self._step_id.strip()) == 0:
|
|
75
|
+
errmsg = "A step identifier is required."
|
|
76
|
+
raise SemanticError(errmsg)
|
|
77
|
+
|
|
78
|
+
if self._name is None or len(self._name.strip()) == 0:
|
|
79
|
+
errmsg = "A step name is required."
|
|
80
|
+
raise SemanticError(errmsg)
|
|
81
|
+
|
|
82
|
+
return
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def step_id(self) -> str:
|
|
86
|
+
"""
|
|
87
|
+
The unique identifier for this step within the workflow.
|
|
88
|
+
|
|
89
|
+
:returns: The step identifier string.
|
|
90
|
+
"""
|
|
91
|
+
return self._step_id
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def name(self) -> str:
|
|
95
|
+
"""
|
|
96
|
+
The human-readable name for this step.
|
|
97
|
+
|
|
98
|
+
:returns: The step name string.
|
|
99
|
+
"""
|
|
100
|
+
return self._name
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def step_type(self) -> str:
|
|
104
|
+
"""
|
|
105
|
+
A string identifying the kind of step.
|
|
106
|
+
|
|
107
|
+
:returns: The step type string.
|
|
108
|
+
"""
|
|
109
|
+
return self._step_type
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def input_schema(self) -> dict:
|
|
113
|
+
"""
|
|
114
|
+
The dictionary describing the expected input data shape
|
|
115
|
+
for this step.
|
|
116
|
+
|
|
117
|
+
:returns: A dictionary of input schema fields. Empty
|
|
118
|
+
dictionary when no input schema was provided.
|
|
119
|
+
"""
|
|
120
|
+
return self._input_schema
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def output_schema(self) -> dict:
|
|
124
|
+
"""
|
|
125
|
+
The dictionary describing the expected output data shape
|
|
126
|
+
for this step.
|
|
127
|
+
|
|
128
|
+
:returns: A dictionary of output schema fields. Empty
|
|
129
|
+
dictionary when no output schema was provided.
|
|
130
|
+
"""
|
|
131
|
+
return self._output_schema
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def tags(self) -> dict:
|
|
135
|
+
"""
|
|
136
|
+
The dictionary of tags for categorization and discovery.
|
|
137
|
+
|
|
138
|
+
:returns: A dictionary of tag key-value pairs. Empty
|
|
139
|
+
dictionary when no tags were provided.
|
|
140
|
+
"""
|
|
141
|
+
return self._tags
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
def retry_policy(self):
|
|
145
|
+
"""
|
|
146
|
+
The optional retry policy for configuring step-level
|
|
147
|
+
retry behavior.
|
|
148
|
+
|
|
149
|
+
:returns: The retry policy object or None when no retry
|
|
150
|
+
policy was configured.
|
|
151
|
+
"""
|
|
152
|
+
return self._retry_policy
|
|
153
|
+
|
|
154
|
+
@abc.abstractmethod
|
|
155
|
+
def execute(self, context) -> "StepResult":
|
|
156
|
+
"""
|
|
157
|
+
Executes this step using the provided workflow context.
|
|
158
|
+
|
|
159
|
+
Concrete subclasses must implement this method to perform
|
|
160
|
+
the step's unit of work. The method receives the current
|
|
161
|
+
WorkflowContext containing workflow inputs and prior step
|
|
162
|
+
outputs, and returns a StepResult describing the execution
|
|
163
|
+
outcome.
|
|
164
|
+
|
|
165
|
+
:param context: The WorkflowContext with inputs and prior
|
|
166
|
+
step outputs.
|
|
167
|
+
|
|
168
|
+
:returns: A StepResult with the execution outcome.
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
def __repr__(self) -> str:
|
|
172
|
+
"""
|
|
173
|
+
Returns a detailed string representation including the
|
|
174
|
+
class name, step identifier, step name, and step type.
|
|
175
|
+
|
|
176
|
+
:returns: A repr string for debugging.
|
|
177
|
+
"""
|
|
178
|
+
repr_str = "{}(step_id={!r}, name={!r}, step_type={!r})".format(
|
|
179
|
+
self.__class__.__name__, self._step_id, self._name,
|
|
180
|
+
self._step_type
|
|
181
|
+
)
|
|
182
|
+
return repr_str
|
|
183
|
+
|
|
184
|
+
def __str__(self) -> str:
|
|
185
|
+
"""
|
|
186
|
+
Returns a human-readable summary including the step name
|
|
187
|
+
and step type.
|
|
188
|
+
|
|
189
|
+
:returns: A human-readable string describing the workflow
|
|
190
|
+
step.
|
|
191
|
+
"""
|
|
192
|
+
str_val = "WorkflowStep: {} [type: {}]".format(
|
|
193
|
+
self._name, self._step_type
|
|
194
|
+
)
|
|
195
|
+
return str_val
|