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,130 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the SelfHealingResult class representing the outcome of a
|
|
3
|
+
self-healing action.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SelfHealingResult:
|
|
13
|
+
"""
|
|
14
|
+
Immutable object representing the outcome of a self-healing action.
|
|
15
|
+
|
|
16
|
+
:param check_name: The health check name.
|
|
17
|
+
:param action_name: The action name.
|
|
18
|
+
:param success: Whether the action succeeded.
|
|
19
|
+
:param error_message: Optional error message.
|
|
20
|
+
:param attempt_number: The attempt number.
|
|
21
|
+
:param timestamp: The datetime of the result. Defaults to UTC now.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, check_name: str, action_name: str, success: bool,
|
|
25
|
+
error_message: Optional[str] = None,
|
|
26
|
+
attempt_number: int = 1,
|
|
27
|
+
timestamp: Optional[datetime] = None) -> None:
|
|
28
|
+
self._check_name = check_name
|
|
29
|
+
self._action_name = action_name
|
|
30
|
+
self._success = success
|
|
31
|
+
self._error_message = error_message
|
|
32
|
+
self._attempt_number = attempt_number
|
|
33
|
+
self._timestamp = timestamp if timestamp is not None else datetime.utcnow()
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def check_name(self) -> str:
|
|
38
|
+
return self._check_name
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def action_name(self) -> str:
|
|
42
|
+
return self._action_name
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def success(self) -> bool:
|
|
46
|
+
return self._success
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def error_message(self) -> str:
|
|
50
|
+
return self._error_message
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def attempt_number(self) -> int:
|
|
54
|
+
return self._attempt_number
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def timestamp(self) -> datetime:
|
|
58
|
+
return self._timestamp
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def is_success(self) -> bool:
|
|
62
|
+
return self._success
|
|
63
|
+
|
|
64
|
+
def as_dict(self) -> dict:
|
|
65
|
+
"""
|
|
66
|
+
Returns a dictionary representation of the result fields.
|
|
67
|
+
|
|
68
|
+
:returns: A dictionary of result fields.
|
|
69
|
+
"""
|
|
70
|
+
result = {
|
|
71
|
+
"check_name": self._check_name,
|
|
72
|
+
"action_name": self._action_name,
|
|
73
|
+
"success": self._success,
|
|
74
|
+
"error_message": self._error_message,
|
|
75
|
+
"attempt_number": self._attempt_number,
|
|
76
|
+
"timestamp": self._timestamp.isoformat()
|
|
77
|
+
}
|
|
78
|
+
return result
|
|
79
|
+
|
|
80
|
+
def to_json(self) -> str:
|
|
81
|
+
"""
|
|
82
|
+
Returns a JSON string representation of the result fields.
|
|
83
|
+
|
|
84
|
+
:returns: A JSON string.
|
|
85
|
+
"""
|
|
86
|
+
data = self.as_dict()
|
|
87
|
+
json_str = json.dumps(data)
|
|
88
|
+
return json_str
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def from_dict(cls, data: dict) -> "SelfHealingResult":
|
|
92
|
+
"""
|
|
93
|
+
Constructs a SelfHealingResult from a dictionary.
|
|
94
|
+
|
|
95
|
+
:param data: Dictionary containing result fields.
|
|
96
|
+
|
|
97
|
+
:returns: A SelfHealingResult instance.
|
|
98
|
+
"""
|
|
99
|
+
result = cls(
|
|
100
|
+
check_name=data["check_name"],
|
|
101
|
+
action_name=data["action_name"],
|
|
102
|
+
success=data["success"],
|
|
103
|
+
error_message=data.get("error_message"),
|
|
104
|
+
attempt_number=data.get("attempt_number", 1),
|
|
105
|
+
timestamp=datetime.fromisoformat(data["timestamp"]) if "timestamp" in data else None
|
|
106
|
+
)
|
|
107
|
+
return result
|
|
108
|
+
|
|
109
|
+
@classmethod
|
|
110
|
+
def from_json(cls, json_str: str) -> "SelfHealingResult":
|
|
111
|
+
"""
|
|
112
|
+
Deserializes a JSON string into a SelfHealingResult instance.
|
|
113
|
+
|
|
114
|
+
:param json_str: JSON string to deserialize.
|
|
115
|
+
|
|
116
|
+
:returns: A SelfHealingResult instance.
|
|
117
|
+
"""
|
|
118
|
+
data = json.loads(json_str)
|
|
119
|
+
result = cls.from_dict(data)
|
|
120
|
+
return result
|
|
121
|
+
|
|
122
|
+
def __repr__(self) -> str:
|
|
123
|
+
return "SelfHealingResult(check_name={!r}, action={!r}, success={})".format(
|
|
124
|
+
self._check_name, self._action_name, self._success
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def __str__(self) -> str:
|
|
128
|
+
return "SelfHealingResult check='{}', action='{}', success={}, attempt={}".format(
|
|
129
|
+
self._check_name, self._action_name, self._success, self._attempt_number
|
|
130
|
+
)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the StepExecutionStatus enum representing the possible
|
|
3
|
+
states of a single step execution in the Workflow & Orchestration feature.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import enum
|
|
7
|
+
|
|
8
|
+
from ccai.agentkit.errors import SemanticError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class StepExecutionStatus(enum.Enum):
|
|
12
|
+
"""
|
|
13
|
+
Enumeration of step execution states.
|
|
14
|
+
|
|
15
|
+
PENDING: The step has not yet started execution.
|
|
16
|
+
RUNNING: The step is currently executing.
|
|
17
|
+
COMPLETED: The step has finished successfully.
|
|
18
|
+
FAILED: The step has stopped due to an error.
|
|
19
|
+
SKIPPED: The step was skipped because its condition was not met.
|
|
20
|
+
PENDING_APPROVAL: The step is paused awaiting external approval.
|
|
21
|
+
CANCELLED: The step was cancelled before completion.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
PENDING = "PENDING"
|
|
25
|
+
RUNNING = "RUNNING"
|
|
26
|
+
COMPLETED = "COMPLETED"
|
|
27
|
+
FAILED = "FAILED"
|
|
28
|
+
SKIPPED = "SKIPPED"
|
|
29
|
+
PENDING_APPROVAL = "PENDING_APPROVAL"
|
|
30
|
+
CANCELLED = "CANCELLED"
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def from_string(cls, value: str) -> "StepExecutionStatus":
|
|
34
|
+
"""
|
|
35
|
+
Returns the StepExecutionStatus member matching the given string.
|
|
36
|
+
|
|
37
|
+
:param value: The string value to match.
|
|
38
|
+
|
|
39
|
+
:returns: The matching StepExecutionStatus member.
|
|
40
|
+
:raises SemanticError: If the value does not match any member.
|
|
41
|
+
"""
|
|
42
|
+
upper_value = value.upper()
|
|
43
|
+
|
|
44
|
+
for member in cls:
|
|
45
|
+
if member.value == upper_value:
|
|
46
|
+
return member
|
|
47
|
+
|
|
48
|
+
valid_values = [m.value for m in cls]
|
|
49
|
+
errmsg = "Invalid StepExecutionStatus value '{}'. Valid values are: {}.".format(
|
|
50
|
+
value, ", ".join(valid_values)
|
|
51
|
+
)
|
|
52
|
+
raise SemanticError(errmsg)
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the StepResult class representing an immutable object
|
|
3
|
+
encapsulating the outcome of a single WorkflowStep execution
|
|
4
|
+
in the Workflow & Orchestration feature.
|
|
5
|
+
|
|
6
|
+
A StepResult contains the step identifier, step name, execution
|
|
7
|
+
status, output dictionary, execution duration in seconds, and
|
|
8
|
+
optional error information. The class provides JSON serialization
|
|
9
|
+
and deserialization for persistence and transmission.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
|
|
14
|
+
from typing import Optional
|
|
15
|
+
|
|
16
|
+
from ccai.agentkit.stepexecutionstatus import StepExecutionStatus
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class StepResult:
|
|
20
|
+
"""
|
|
21
|
+
Immutable object encapsulating the outcome of a single
|
|
22
|
+
WorkflowStep execution.
|
|
23
|
+
|
|
24
|
+
A StepResult captures the step identifier, step name,
|
|
25
|
+
execution status, output dictionary, execution duration
|
|
26
|
+
in seconds, and optional error information. All fields
|
|
27
|
+
are exposed as read-only properties. The is_success
|
|
28
|
+
property returns True when the execution status is
|
|
29
|
+
COMPLETED.
|
|
30
|
+
|
|
31
|
+
:param step_id: The unique identifier of the executed step.
|
|
32
|
+
:param step_name: The human-readable name of the executed step.
|
|
33
|
+
:param status: The StepExecutionStatus indicating the outcome.
|
|
34
|
+
:param output: An optional dictionary of output values produced
|
|
35
|
+
by the step. Defaults to an empty dictionary.
|
|
36
|
+
:param duration: The execution duration in seconds as a float.
|
|
37
|
+
Defaults to 0.0.
|
|
38
|
+
:param error: An optional error message string when the step
|
|
39
|
+
failed or encountered an error.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, step_id: str, step_name: str, status: StepExecutionStatus,
|
|
43
|
+
output: Optional[dict] = None, duration: float = 0.0,
|
|
44
|
+
error: Optional[str] = None) -> None:
|
|
45
|
+
self._step_id = step_id
|
|
46
|
+
self._step_name = step_name
|
|
47
|
+
self._status = status
|
|
48
|
+
self._output = dict(output) if output is not None else {}
|
|
49
|
+
self._duration = duration
|
|
50
|
+
self._error = error
|
|
51
|
+
return
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def step_id(self) -> str:
|
|
55
|
+
"""
|
|
56
|
+
The unique identifier of the executed step.
|
|
57
|
+
|
|
58
|
+
:returns: The step identifier string.
|
|
59
|
+
"""
|
|
60
|
+
return self._step_id
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def step_name(self) -> str:
|
|
64
|
+
"""
|
|
65
|
+
The human-readable name of the executed step.
|
|
66
|
+
|
|
67
|
+
:returns: The step name string.
|
|
68
|
+
"""
|
|
69
|
+
return self._step_name
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def status(self) -> StepExecutionStatus:
|
|
73
|
+
"""
|
|
74
|
+
The execution status indicating the outcome of the step.
|
|
75
|
+
|
|
76
|
+
:returns: The StepExecutionStatus member.
|
|
77
|
+
"""
|
|
78
|
+
return self._status
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def output(self) -> dict:
|
|
82
|
+
"""
|
|
83
|
+
The dictionary of output values produced by the step.
|
|
84
|
+
|
|
85
|
+
:returns: A dictionary of output values. Empty dictionary
|
|
86
|
+
when the step produced no output.
|
|
87
|
+
"""
|
|
88
|
+
return self._output
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def duration(self) -> float:
|
|
92
|
+
"""
|
|
93
|
+
The execution duration in seconds.
|
|
94
|
+
|
|
95
|
+
:returns: The duration as a float in seconds.
|
|
96
|
+
"""
|
|
97
|
+
return self._duration
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def error(self) -> Optional[str]:
|
|
101
|
+
"""
|
|
102
|
+
The error message string when the step failed or
|
|
103
|
+
encountered an error.
|
|
104
|
+
|
|
105
|
+
:returns: The error message string or None when no
|
|
106
|
+
error occurred.
|
|
107
|
+
"""
|
|
108
|
+
return self._error
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def is_success(self) -> bool:
|
|
112
|
+
"""
|
|
113
|
+
Indicates whether the step execution completed successfully.
|
|
114
|
+
|
|
115
|
+
:returns: True when the execution status is COMPLETED,
|
|
116
|
+
False otherwise.
|
|
117
|
+
"""
|
|
118
|
+
rtnval = self._status == StepExecutionStatus.COMPLETED
|
|
119
|
+
return rtnval
|
|
120
|
+
|
|
121
|
+
def as_dict(self) -> dict:
|
|
122
|
+
"""
|
|
123
|
+
Returns a dictionary representation of the step result fields.
|
|
124
|
+
|
|
125
|
+
The status is serialized as its string value.
|
|
126
|
+
|
|
127
|
+
:returns: A dictionary containing step_id, step_name, status,
|
|
128
|
+
output, duration, and error.
|
|
129
|
+
"""
|
|
130
|
+
rtnval = {
|
|
131
|
+
"step_id": self._step_id,
|
|
132
|
+
"step_name": self._step_name,
|
|
133
|
+
"status": self._status.value,
|
|
134
|
+
"output": self._output,
|
|
135
|
+
"duration": self._duration,
|
|
136
|
+
"error": self._error
|
|
137
|
+
}
|
|
138
|
+
return rtnval
|
|
139
|
+
|
|
140
|
+
def to_json(self) -> str:
|
|
141
|
+
"""
|
|
142
|
+
Returns a JSON string representation of the step result fields.
|
|
143
|
+
|
|
144
|
+
:returns: A JSON string containing all step result fields.
|
|
145
|
+
"""
|
|
146
|
+
data = self.as_dict()
|
|
147
|
+
rtnval = json.dumps(data)
|
|
148
|
+
return rtnval
|
|
149
|
+
|
|
150
|
+
@classmethod
|
|
151
|
+
def from_json(cls, json_str: str) -> "StepResult":
|
|
152
|
+
"""
|
|
153
|
+
Deserializes a JSON string into a StepResult instance.
|
|
154
|
+
|
|
155
|
+
The status field is deserialized using
|
|
156
|
+
StepExecutionStatus.from_string.
|
|
157
|
+
|
|
158
|
+
:param json_str: A JSON string containing step result fields.
|
|
159
|
+
|
|
160
|
+
:returns: A StepResult instance reconstructed from the JSON data.
|
|
161
|
+
"""
|
|
162
|
+
data = json.loads(json_str)
|
|
163
|
+
|
|
164
|
+
status = StepExecutionStatus.from_string(data["status"])
|
|
165
|
+
|
|
166
|
+
rtnval = cls(
|
|
167
|
+
step_id=data["step_id"],
|
|
168
|
+
step_name=data["step_name"],
|
|
169
|
+
status=status,
|
|
170
|
+
output=data.get("output"),
|
|
171
|
+
duration=data.get("duration", 0.0),
|
|
172
|
+
error=data.get("error")
|
|
173
|
+
)
|
|
174
|
+
return rtnval
|
|
175
|
+
|
|
176
|
+
def __repr__(self) -> str:
|
|
177
|
+
"""
|
|
178
|
+
Returns a detailed string representation including the class
|
|
179
|
+
name, step identifier, and execution status.
|
|
180
|
+
|
|
181
|
+
:returns: A repr string for debugging.
|
|
182
|
+
"""
|
|
183
|
+
repr_str = "{}(step_id={!r}, status={})".format(
|
|
184
|
+
self.__class__.__name__, self._step_id, self._status.value
|
|
185
|
+
)
|
|
186
|
+
return repr_str
|
|
187
|
+
|
|
188
|
+
def __str__(self) -> str:
|
|
189
|
+
"""
|
|
190
|
+
Returns a human-readable summary including the step name,
|
|
191
|
+
status, and duration.
|
|
192
|
+
|
|
193
|
+
:returns: A human-readable string describing the step result.
|
|
194
|
+
"""
|
|
195
|
+
str_val = "StepResult: {} [status: {}, duration: {:.3f}s]".format(
|
|
196
|
+
self._step_name, self._status.value, self._duration
|
|
197
|
+
)
|
|
198
|
+
return str_val
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Built-in workflow step implementations for the Workflow &
|
|
3
|
+
Orchestration feature of the codecraftai-agent-kit framework.
|
|
4
|
+
|
|
5
|
+
This package contains concrete WorkflowStep subclasses that
|
|
6
|
+
provide common step types for workflow execution, including
|
|
7
|
+
tool execution, LLM completion, cross-agent delegation,
|
|
8
|
+
approval gates, and sub-workflow execution.
|
|
9
|
+
"""
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the AgentStep class, a concrete WorkflowStep that delegates
|
|
3
|
+
execution to another Agent via the Communication & Messaging system.
|
|
4
|
+
|
|
5
|
+
AgentStep constructs a request message from the WorkflowContext,
|
|
6
|
+
sends it to the target agent with the executing agent's request
|
|
7
|
+
method, awaits the correlated response for up to the configured
|
|
8
|
+
timeout, and returns a StepResult containing the response payload
|
|
9
|
+
on success or a FAILED status on timeout or transport error.
|
|
10
|
+
|
|
11
|
+
.. module:: ccai.agentkit.steps.agentstep
|
|
12
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
13
|
+
:synopsis: Built-in workflow step for cross-agent delegation.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import logging
|
|
17
|
+
import time
|
|
18
|
+
|
|
19
|
+
from typing import Optional
|
|
20
|
+
|
|
21
|
+
from ccai.agentkit.stepexecutionstatus import StepExecutionStatus
|
|
22
|
+
from ccai.agentkit.stepresult import StepResult
|
|
23
|
+
from ccai.agentkit.workflowcontext import WorkflowContext
|
|
24
|
+
from ccai.agentkit.workflowstep import WorkflowStep
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class AgentStep(WorkflowStep):
|
|
28
|
+
"""
|
|
29
|
+
Delegates execution to another Agent via the Communication &
|
|
30
|
+
Messaging system.
|
|
31
|
+
|
|
32
|
+
AgentStep is a concrete WorkflowStep subclass that integrates
|
|
33
|
+
with the Communication & Messaging system. At execution time,
|
|
34
|
+
it constructs a request message payload from the WorkflowContext
|
|
35
|
+
inputs and accumulated step outputs, sends it to the target agent
|
|
36
|
+
through the executing agent's request method, which waits for
|
|
37
|
+
the correlated response, and wraps the response payload in a
|
|
38
|
+
StepResult. The executing agent must be receiving from the
|
|
39
|
+
transport, for example with Agent.start_receiving, so the reply
|
|
40
|
+
reaches the waiting request.
|
|
41
|
+
|
|
42
|
+
The target_agent_id identifies the remote agent to delegate to.
|
|
43
|
+
The optional transport_name specifies which communication
|
|
44
|
+
transport to use. The optional timeout specifies the maximum
|
|
45
|
+
number of seconds to wait for a response from the target agent.
|
|
46
|
+
|
|
47
|
+
:param step_id: The unique identifier for this step within
|
|
48
|
+
the workflow. Must not be None or empty.
|
|
49
|
+
:param name: The human-readable name for this step. Must
|
|
50
|
+
not be None or empty.
|
|
51
|
+
:param target_agent_id: The identifier of the Agent to
|
|
52
|
+
delegate execution to.
|
|
53
|
+
:param transport_name: An optional string specifying the
|
|
54
|
+
communication transport to use. Defaults to None, which
|
|
55
|
+
uses the agent's default transport.
|
|
56
|
+
:param timeout: An optional float specifying the maximum
|
|
57
|
+
number of seconds to wait for a response. Defaults to
|
|
58
|
+
None, which uses the agent's default request timeout.
|
|
59
|
+
:param kwargs: Additional keyword arguments passed to the
|
|
60
|
+
WorkflowStep base class constructor (e.g. input_schema,
|
|
61
|
+
output_schema, tags, retry_policy).
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
def __init__(self, step_id: str, name: str, target_agent_id: str,
|
|
65
|
+
transport_name: Optional[str] = None,
|
|
66
|
+
timeout: Optional[float] = None, **kwargs) -> None:
|
|
67
|
+
super().__init__(step_id=step_id, name=name, step_type="agent", **kwargs)
|
|
68
|
+
self._target_agent_id = target_agent_id
|
|
69
|
+
self._transport_name = transport_name
|
|
70
|
+
self._timeout = timeout
|
|
71
|
+
self._logger = logging.getLogger("ccai.agentkit.workflow.steps.agent")
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def target_agent_id(self) -> str:
|
|
76
|
+
"""
|
|
77
|
+
The identifier of the Agent to delegate execution to.
|
|
78
|
+
|
|
79
|
+
:returns: The target agent identifier string.
|
|
80
|
+
"""
|
|
81
|
+
return self._target_agent_id
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def transport_name(self) -> Optional[str]:
|
|
85
|
+
"""
|
|
86
|
+
The optional communication transport name to use when
|
|
87
|
+
sending the message to the target agent.
|
|
88
|
+
|
|
89
|
+
:returns: The transport name string or None when the
|
|
90
|
+
agent's default transport should be used.
|
|
91
|
+
"""
|
|
92
|
+
return self._transport_name
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def timeout(self) -> Optional[float]:
|
|
96
|
+
"""
|
|
97
|
+
The optional maximum number of seconds to wait for a
|
|
98
|
+
response from the target agent.
|
|
99
|
+
|
|
100
|
+
:returns: The timeout in seconds as a float or None
|
|
101
|
+
when the agent's default timeout should be used.
|
|
102
|
+
"""
|
|
103
|
+
return self._timeout
|
|
104
|
+
|
|
105
|
+
def _build_payload(self, context: WorkflowContext) -> dict:
|
|
106
|
+
"""
|
|
107
|
+
Constructs the request message payload from the
|
|
108
|
+
WorkflowContext.
|
|
109
|
+
|
|
110
|
+
The payload contains the workflow inputs and all
|
|
111
|
+
accumulated step outputs, providing the target agent
|
|
112
|
+
with the full context needed to perform the delegated
|
|
113
|
+
work.
|
|
114
|
+
|
|
115
|
+
:param context: The WorkflowContext to build the
|
|
116
|
+
payload from.
|
|
117
|
+
|
|
118
|
+
:returns: A dictionary containing "inputs" and
|
|
119
|
+
"step_outputs" keys.
|
|
120
|
+
"""
|
|
121
|
+
payload = {
|
|
122
|
+
"inputs": dict(context.inputs) if context.inputs is not None else {},
|
|
123
|
+
"step_outputs": dict(context.step_outputs) if context.step_outputs is not None else {}
|
|
124
|
+
}
|
|
125
|
+
return payload
|
|
126
|
+
|
|
127
|
+
def execute(self, context: WorkflowContext) -> StepResult:
|
|
128
|
+
"""
|
|
129
|
+
Executes this AgentStep using the provided workflow context.
|
|
130
|
+
|
|
131
|
+
Retrieves the Agent from the context, constructs a request
|
|
132
|
+
message payload from the WorkflowContext inputs and step
|
|
133
|
+
outputs, and sends it to the target agent through the
|
|
134
|
+
agent's request method with the step's transport name and
|
|
135
|
+
timeout. The request method waits for the correlated
|
|
136
|
+
response Message, and the response payload becomes the
|
|
137
|
+
step output: a dictionary payload is used as the output
|
|
138
|
+
directly and any other payload is stored under the
|
|
139
|
+
"response" key.
|
|
140
|
+
|
|
141
|
+
If the Agent is None, a StepResult with FAILED status is
|
|
142
|
+
returned. If no response arrives within the timeout, the
|
|
143
|
+
MessageTimeoutError is reported in a StepResult with FAILED
|
|
144
|
+
status. If the request raises any other transport error, a
|
|
145
|
+
StepResult with FAILED status and the error message is
|
|
146
|
+
returned.
|
|
147
|
+
|
|
148
|
+
:param context: The WorkflowContext with inputs and prior
|
|
149
|
+
step outputs.
|
|
150
|
+
|
|
151
|
+
:returns: A StepResult with the execution outcome.
|
|
152
|
+
"""
|
|
153
|
+
start_time = time.monotonic()
|
|
154
|
+
|
|
155
|
+
agent = context.agent
|
|
156
|
+
|
|
157
|
+
if agent is None:
|
|
158
|
+
duration = time.monotonic() - start_time
|
|
159
|
+
errmsg = "AgentStep '{}' failed: no agent available in the workflow context.".format(
|
|
160
|
+
self._name
|
|
161
|
+
)
|
|
162
|
+
self._logger.warning(errmsg)
|
|
163
|
+
|
|
164
|
+
result = StepResult(
|
|
165
|
+
step_id=self._step_id,
|
|
166
|
+
step_name=self._name,
|
|
167
|
+
status=StepExecutionStatus.FAILED,
|
|
168
|
+
duration=duration,
|
|
169
|
+
error=errmsg
|
|
170
|
+
)
|
|
171
|
+
return result
|
|
172
|
+
|
|
173
|
+
payload = self._build_payload(context)
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
# request() sends a REQUEST message and waits for the correlated
|
|
177
|
+
# response; None for the transport name or timeout selects the
|
|
178
|
+
# agent's messaging defaults.
|
|
179
|
+
response = agent.request(
|
|
180
|
+
recipient_id=self._target_agent_id,
|
|
181
|
+
payload=payload,
|
|
182
|
+
transport_name=self._transport_name,
|
|
183
|
+
timeout=self._timeout
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
duration = time.monotonic() - start_time
|
|
187
|
+
|
|
188
|
+
response_payload = response.payload
|
|
189
|
+
|
|
190
|
+
if isinstance(response_payload, dict):
|
|
191
|
+
output = dict(response_payload)
|
|
192
|
+
else:
|
|
193
|
+
output = {"response": response_payload}
|
|
194
|
+
|
|
195
|
+
result = StepResult(
|
|
196
|
+
step_id=self._step_id,
|
|
197
|
+
step_name=self._name,
|
|
198
|
+
status=StepExecutionStatus.COMPLETED,
|
|
199
|
+
output=output,
|
|
200
|
+
duration=duration
|
|
201
|
+
)
|
|
202
|
+
return result
|
|
203
|
+
|
|
204
|
+
except Exception as exec_err:
|
|
205
|
+
duration = time.monotonic() - start_time
|
|
206
|
+
|
|
207
|
+
error_type_name = type(exec_err).__name__
|
|
208
|
+
errmsg = "AgentStep '{}' failed requesting a response from agent '{}': [{}] {}".format(
|
|
209
|
+
self._name, self._target_agent_id, error_type_name,
|
|
210
|
+
str(exec_err)
|
|
211
|
+
)
|
|
212
|
+
self._logger.warning(errmsg)
|
|
213
|
+
|
|
214
|
+
result = StepResult(
|
|
215
|
+
step_id=self._step_id,
|
|
216
|
+
step_name=self._name,
|
|
217
|
+
status=StepExecutionStatus.FAILED,
|
|
218
|
+
duration=duration,
|
|
219
|
+
error=errmsg
|
|
220
|
+
)
|
|
221
|
+
return result
|
|
222
|
+
|
|
223
|
+
def __repr__(self) -> str:
|
|
224
|
+
"""
|
|
225
|
+
Returns a detailed string representation including the
|
|
226
|
+
class name, step identifier, step name, and target agent
|
|
227
|
+
identifier.
|
|
228
|
+
|
|
229
|
+
:returns: A repr string for debugging.
|
|
230
|
+
"""
|
|
231
|
+
repr_str = "{}(step_id={!r}, name={!r}, target_agent_id={!r})".format(
|
|
232
|
+
self.__class__.__name__, self._step_id, self._name,
|
|
233
|
+
self._target_agent_id
|
|
234
|
+
)
|
|
235
|
+
return repr_str
|
|
236
|
+
|
|
237
|
+
def __str__(self) -> str:
|
|
238
|
+
"""
|
|
239
|
+
Returns a human-readable summary including the step name
|
|
240
|
+
and target agent identifier.
|
|
241
|
+
|
|
242
|
+
:returns: A human-readable string describing the agent step.
|
|
243
|
+
"""
|
|
244
|
+
str_val = "AgentStep: {} [target: {}]".format(
|
|
245
|
+
self._name, self._target_agent_id
|
|
246
|
+
)
|
|
247
|
+
return str_val
|