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,123 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the DeadLetterQueue class for managing permanently failed
|
|
3
|
+
operations in the Error Handling & Resilience feature.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import logging
|
|
7
|
+
|
|
8
|
+
from typing import Callable
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
from ccai.agentkit.deadletterentry import DeadLetterEntry
|
|
12
|
+
from ccai.agentkit.deadletterquery import DeadLetterQuery
|
|
13
|
+
from ccai.agentkit.deadletterquery import DeadLetterQueryResult
|
|
14
|
+
from ccai.agentkit.deadletterstore import DeadLetterStore
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DeadLetterQueue:
|
|
18
|
+
"""
|
|
19
|
+
Queue for storing operations and messages that have permanently failed.
|
|
20
|
+
|
|
21
|
+
:param store: The DeadLetterStore backend.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, store: DeadLetterStore) -> None:
|
|
25
|
+
self._store = store
|
|
26
|
+
self._logger = logging.getLogger("ccai.agentkit.resilience")
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def store(self) -> DeadLetterStore:
|
|
31
|
+
return self._store
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def entry_count(self) -> int:
|
|
35
|
+
return self._store.count()
|
|
36
|
+
|
|
37
|
+
def enqueue(self, operation_type: str, payload: dict,
|
|
38
|
+
exception_info: str, retry_attempts: int,
|
|
39
|
+
source_component: str, agent_identifier: str,
|
|
40
|
+
metadata: Optional[dict] = None) -> DeadLetterEntry:
|
|
41
|
+
"""
|
|
42
|
+
Creates a DeadLetterEntry and stores it.
|
|
43
|
+
|
|
44
|
+
:returns: The created DeadLetterEntry.
|
|
45
|
+
"""
|
|
46
|
+
entry = DeadLetterEntry(
|
|
47
|
+
operation_type=operation_type,
|
|
48
|
+
payload=payload,
|
|
49
|
+
exception_info=exception_info,
|
|
50
|
+
retry_attempts=retry_attempts,
|
|
51
|
+
source_component=source_component,
|
|
52
|
+
agent_identifier=agent_identifier,
|
|
53
|
+
metadata=metadata
|
|
54
|
+
)
|
|
55
|
+
self._store.store(entry)
|
|
56
|
+
|
|
57
|
+
self._logger.warning(
|
|
58
|
+
"Dead letter enqueued: operation='%s', source='%s', agent='%s', id='%s'",
|
|
59
|
+
operation_type, source_component, agent_identifier, entry.identifier
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return entry
|
|
63
|
+
|
|
64
|
+
def query(self, query: DeadLetterQuery) -> DeadLetterQueryResult:
|
|
65
|
+
"""
|
|
66
|
+
Searches the dead letter store.
|
|
67
|
+
|
|
68
|
+
:param query: The DeadLetterQuery.
|
|
69
|
+
|
|
70
|
+
:returns: A DeadLetterQueryResult.
|
|
71
|
+
"""
|
|
72
|
+
return self._store.search(query)
|
|
73
|
+
|
|
74
|
+
def get_entry(self, identifier: str) -> Optional[DeadLetterEntry]:
|
|
75
|
+
"""
|
|
76
|
+
Retrieves a specific entry by identifier.
|
|
77
|
+
|
|
78
|
+
:param identifier: The entry identifier.
|
|
79
|
+
|
|
80
|
+
:returns: The DeadLetterEntry or None.
|
|
81
|
+
"""
|
|
82
|
+
return self._store.retrieve(identifier)
|
|
83
|
+
|
|
84
|
+
def replay(self, identifier: str, callable_op: Callable) -> bool:
|
|
85
|
+
"""
|
|
86
|
+
Replays a dead letter entry by invoking the callable with the payload.
|
|
87
|
+
Removes the entry on success, updates metadata on failure.
|
|
88
|
+
|
|
89
|
+
:param identifier: The entry identifier.
|
|
90
|
+
:param callable_op: The callable to invoke with the payload.
|
|
91
|
+
|
|
92
|
+
:returns: True if replay succeeded, False otherwise.
|
|
93
|
+
"""
|
|
94
|
+
entry = self._store.retrieve(identifier)
|
|
95
|
+
if entry is None:
|
|
96
|
+
return False
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
callable_op(entry.payload)
|
|
100
|
+
self._store.delete(identifier)
|
|
101
|
+
return True
|
|
102
|
+
except Exception as exc:
|
|
103
|
+
self._logger.warning(
|
|
104
|
+
"Dead letter replay failed for id='%s': %s", identifier, str(exc)
|
|
105
|
+
)
|
|
106
|
+
return False
|
|
107
|
+
|
|
108
|
+
def purge(self) -> None:
|
|
109
|
+
"""
|
|
110
|
+
Removes all entries from the dead letter store.
|
|
111
|
+
"""
|
|
112
|
+
self._store.purge()
|
|
113
|
+
return
|
|
114
|
+
|
|
115
|
+
def __repr__(self) -> str:
|
|
116
|
+
repr_str = "DeadLetterQueue(entry_count={})".format(self.entry_count)
|
|
117
|
+
return repr_str
|
|
118
|
+
|
|
119
|
+
def __str__(self) -> str:
|
|
120
|
+
str_val = "DeadLetterQueue: {} entries, store='{}'".format(
|
|
121
|
+
self.entry_count, self._store.store_name
|
|
122
|
+
)
|
|
123
|
+
return str_val
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the DeadLetterStore abstract base class for persisting
|
|
3
|
+
DeadLetterEntry objects.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import abc
|
|
7
|
+
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
from ccai.agentkit.deadletterentry import DeadLetterEntry
|
|
11
|
+
from ccai.agentkit.deadletterquery import DeadLetterQuery
|
|
12
|
+
from ccai.agentkit.deadletterquery import DeadLetterQueryResult
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DeadLetterStore(abc.ABC):
|
|
16
|
+
"""
|
|
17
|
+
Abstract base class for persisting DeadLetterEntry objects.
|
|
18
|
+
|
|
19
|
+
:param store_name: The name of the store.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, store_name: str) -> None:
|
|
23
|
+
self._store_name = store_name
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def store_name(self) -> str:
|
|
28
|
+
return self._store_name
|
|
29
|
+
|
|
30
|
+
@abc.abstractmethod
|
|
31
|
+
def store(self, entry: DeadLetterEntry) -> None:
|
|
32
|
+
"""
|
|
33
|
+
Persists a dead letter entry in the store.
|
|
34
|
+
|
|
35
|
+
:param entry: The dead letter entry to persist.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
@abc.abstractmethod
|
|
39
|
+
def retrieve(self, identifier: str) -> Optional[DeadLetterEntry]:
|
|
40
|
+
"""
|
|
41
|
+
Retrieves the dead letter entry with the specified identifier.
|
|
42
|
+
|
|
43
|
+
:param identifier: The identifier of the entry to retrieve.
|
|
44
|
+
|
|
45
|
+
:returns: The matching entry, or None if no entry has the identifier.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
@abc.abstractmethod
|
|
49
|
+
def search(self, query: DeadLetterQuery) -> DeadLetterQueryResult:
|
|
50
|
+
"""
|
|
51
|
+
Searches the store for dead letter entries matching a query.
|
|
52
|
+
|
|
53
|
+
:param query: The query describing the entries to match.
|
|
54
|
+
|
|
55
|
+
:returns: The query result containing the matching entries.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
@abc.abstractmethod
|
|
59
|
+
def delete(self, identifier: str) -> None:
|
|
60
|
+
"""
|
|
61
|
+
Deletes the dead letter entry with the specified identifier.
|
|
62
|
+
|
|
63
|
+
:param identifier: The identifier of the entry to delete.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
@abc.abstractmethod
|
|
67
|
+
def purge(self) -> None:
|
|
68
|
+
"""
|
|
69
|
+
Removes all dead letter entries from the store.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
@abc.abstractmethod
|
|
73
|
+
def count(self) -> int:
|
|
74
|
+
"""
|
|
75
|
+
Returns the number of dead letter entries in the store.
|
|
76
|
+
|
|
77
|
+
:returns: The number of stored entries.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
def __repr__(self) -> str:
|
|
81
|
+
repr_str = "{}(store_name={!r})".format(self.__class__.__name__, self._store_name)
|
|
82
|
+
return repr_str
|
|
83
|
+
|
|
84
|
+
def __str__(self) -> str:
|
|
85
|
+
str_val = "{} store_name='{}'".format(self.__class__.__name__, self._store_name)
|
|
86
|
+
return str_val
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the DebugInspector class that provides read-only access
|
|
3
|
+
to the current agent state during a DebugSession pause.
|
|
4
|
+
|
|
5
|
+
The DebugInspector wraps an Agent instance and exposes read-only
|
|
6
|
+
properties and methods for inspecting lifecycle state, identity,
|
|
7
|
+
correlation context, tool names, LLM providers, memory store
|
|
8
|
+
names, metrics snapshots, active spans, and execution recordings.
|
|
9
|
+
|
|
10
|
+
Uses defensive access via getattr with defaults where the Agent
|
|
11
|
+
class may not yet have all observability methods available.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DebugInspector:
|
|
16
|
+
"""
|
|
17
|
+
A component that provides read-only access to the current
|
|
18
|
+
agent state during a DebugSession pause.
|
|
19
|
+
|
|
20
|
+
Wraps an Agent instance and exposes read-only properties
|
|
21
|
+
and methods for inspecting the agent's internal state
|
|
22
|
+
without modifying agent behavior.
|
|
23
|
+
|
|
24
|
+
:param agent: The Agent instance to inspect.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, agent) -> None:
|
|
28
|
+
|
|
29
|
+
self._agent = agent
|
|
30
|
+
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def lifecycle_state(self):
|
|
35
|
+
"""
|
|
36
|
+
The agent's current lifecycle state.
|
|
37
|
+
|
|
38
|
+
:returns: The LifecycleState value, or None if not
|
|
39
|
+
available.
|
|
40
|
+
"""
|
|
41
|
+
state = getattr(self._agent, "state", None)
|
|
42
|
+
return state
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def identity(self):
|
|
46
|
+
"""
|
|
47
|
+
The agent's identity.
|
|
48
|
+
|
|
49
|
+
:returns: The AgentIdentity instance, or None if not
|
|
50
|
+
available.
|
|
51
|
+
"""
|
|
52
|
+
identity = getattr(self._agent, "identity", None)
|
|
53
|
+
return identity
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def correlation_context(self):
|
|
57
|
+
"""
|
|
58
|
+
The agent's current correlation context.
|
|
59
|
+
|
|
60
|
+
:returns: The CorrelationContext instance, or None if
|
|
61
|
+
not available.
|
|
62
|
+
"""
|
|
63
|
+
observability = getattr(self._agent, "observability", None)
|
|
64
|
+
if observability is not None:
|
|
65
|
+
logger = getattr(observability, "logger", None)
|
|
66
|
+
if logger is not None:
|
|
67
|
+
context = getattr(logger, "correlation_context", None)
|
|
68
|
+
return context
|
|
69
|
+
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
def get_tool_names(self) -> list:
|
|
73
|
+
"""
|
|
74
|
+
Returns the list of registered tool names from the
|
|
75
|
+
agent's tool registry.
|
|
76
|
+
|
|
77
|
+
:returns: A list of tool name strings, or an empty
|
|
78
|
+
list if not available.
|
|
79
|
+
"""
|
|
80
|
+
tool_registry = getattr(self._agent, "tool_registry", None)
|
|
81
|
+
if tool_registry is not None:
|
|
82
|
+
names_method = getattr(tool_registry, "list_names", None)
|
|
83
|
+
if names_method is not None:
|
|
84
|
+
names = names_method()
|
|
85
|
+
return names
|
|
86
|
+
|
|
87
|
+
return []
|
|
88
|
+
|
|
89
|
+
def get_llm_providers(self) -> list:
|
|
90
|
+
"""
|
|
91
|
+
Returns the list of registered LLM provider name-model
|
|
92
|
+
pairs from the agent's LLM provider registry.
|
|
93
|
+
|
|
94
|
+
:returns: A list of provider entries, or an empty list
|
|
95
|
+
if not available.
|
|
96
|
+
"""
|
|
97
|
+
llm_registry = getattr(self._agent, "llm_provider_registry", None)
|
|
98
|
+
if llm_registry is not None:
|
|
99
|
+
providers_method = getattr(llm_registry, "list_all", None)
|
|
100
|
+
if providers_method is not None:
|
|
101
|
+
providers = providers_method()
|
|
102
|
+
return providers
|
|
103
|
+
|
|
104
|
+
return []
|
|
105
|
+
|
|
106
|
+
def get_memory_store_names(self) -> list:
|
|
107
|
+
"""
|
|
108
|
+
Returns the list of registered memory store names from
|
|
109
|
+
the agent's memory store registry.
|
|
110
|
+
|
|
111
|
+
:returns: A list of memory store name strings, or an
|
|
112
|
+
empty list if not available.
|
|
113
|
+
"""
|
|
114
|
+
memory_registry = getattr(self._agent, "memory_store_registry", None)
|
|
115
|
+
if memory_registry is not None:
|
|
116
|
+
names_method = getattr(memory_registry, "list_names", None)
|
|
117
|
+
if names_method is not None:
|
|
118
|
+
names = names_method()
|
|
119
|
+
return names
|
|
120
|
+
|
|
121
|
+
return []
|
|
122
|
+
|
|
123
|
+
def get_metrics_snapshot(self):
|
|
124
|
+
"""
|
|
125
|
+
Returns the current MetricsSnapshot from the agent's
|
|
126
|
+
MetricsCollector.
|
|
127
|
+
|
|
128
|
+
:returns: A MetricsSnapshot instance, or None if not
|
|
129
|
+
available.
|
|
130
|
+
"""
|
|
131
|
+
observability = getattr(self._agent, "observability", None)
|
|
132
|
+
if observability is not None:
|
|
133
|
+
collector = getattr(observability, "metrics_collector", None)
|
|
134
|
+
if collector is not None:
|
|
135
|
+
snapshot_method = getattr(collector, "snapshot", None)
|
|
136
|
+
if snapshot_method is not None:
|
|
137
|
+
snapshot = snapshot_method()
|
|
138
|
+
return snapshot
|
|
139
|
+
|
|
140
|
+
return None
|
|
141
|
+
|
|
142
|
+
def get_active_span(self):
|
|
143
|
+
"""
|
|
144
|
+
Returns the current active TraceSpan from the agent's
|
|
145
|
+
Tracer.
|
|
146
|
+
|
|
147
|
+
:returns: A TraceSpan instance, or None if no span is
|
|
148
|
+
active or not available.
|
|
149
|
+
"""
|
|
150
|
+
observability = getattr(self._agent, "observability", None)
|
|
151
|
+
if observability is not None:
|
|
152
|
+
tracer = getattr(observability, "tracer", None)
|
|
153
|
+
if tracer is not None:
|
|
154
|
+
active_span = getattr(tracer, "active_span", None)
|
|
155
|
+
return active_span
|
|
156
|
+
|
|
157
|
+
return None
|
|
158
|
+
|
|
159
|
+
def get_execution_recording(self):
|
|
160
|
+
"""
|
|
161
|
+
Returns the current ExecutionRecording from the agent's
|
|
162
|
+
ExecutionRecorder.
|
|
163
|
+
|
|
164
|
+
:returns: An ExecutionRecording instance, or None if not
|
|
165
|
+
available.
|
|
166
|
+
"""
|
|
167
|
+
observability = getattr(self._agent, "observability", None)
|
|
168
|
+
if observability is not None:
|
|
169
|
+
recorder = getattr(observability, "execution_recorder", None)
|
|
170
|
+
if recorder is not None:
|
|
171
|
+
recording_method = getattr(recorder, "get_recording", None)
|
|
172
|
+
if recording_method is not None:
|
|
173
|
+
recording = recording_method()
|
|
174
|
+
return recording
|
|
175
|
+
|
|
176
|
+
return None
|
|
177
|
+
|
|
178
|
+
def __repr__(self) -> str:
|
|
179
|
+
"""
|
|
180
|
+
Returns a detailed string representation including class
|
|
181
|
+
name and agent identifier.
|
|
182
|
+
|
|
183
|
+
:returns: A repr string for debugging.
|
|
184
|
+
"""
|
|
185
|
+
agent_identity = getattr(self._agent, "identity", None)
|
|
186
|
+
if agent_identity is not None:
|
|
187
|
+
agent_id = getattr(agent_identity, "identifier", "unknown")
|
|
188
|
+
else:
|
|
189
|
+
agent_id = "unknown"
|
|
190
|
+
|
|
191
|
+
repr_str = "DebugInspector(agent_id={!r})".format(agent_id)
|
|
192
|
+
return repr_str
|
|
193
|
+
|
|
194
|
+
def __str__(self) -> str:
|
|
195
|
+
"""
|
|
196
|
+
Returns a human-readable summary including the agent
|
|
197
|
+
identifier and current lifecycle state.
|
|
198
|
+
|
|
199
|
+
:returns: A human-readable string.
|
|
200
|
+
"""
|
|
201
|
+
agent_identity = getattr(self._agent, "identity", None)
|
|
202
|
+
if agent_identity is not None:
|
|
203
|
+
agent_id = getattr(agent_identity, "identifier", "unknown")
|
|
204
|
+
else:
|
|
205
|
+
agent_id = "unknown"
|
|
206
|
+
|
|
207
|
+
state = self.lifecycle_state
|
|
208
|
+
str_val = "DebugInspector: agent_id={}, lifecycle_state={}".format(
|
|
209
|
+
agent_id, state
|
|
210
|
+
)
|
|
211
|
+
return str_val
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the DebugSession class that enables step-through execution
|
|
3
|
+
of agent operations.
|
|
4
|
+
|
|
5
|
+
A DebugSession manages a list of Breakpoint objects and pauses
|
|
6
|
+
execution when an event matches a registered breakpoint. When
|
|
7
|
+
paused, a registered pause callback is invoked with a DebugInspector
|
|
8
|
+
instance for read-only state inspection. The session supports
|
|
9
|
+
continue, step, start, and stop operations.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import Optional
|
|
13
|
+
|
|
14
|
+
from ccai.agentkit.breakpoint import Breakpoint
|
|
15
|
+
from ccai.agentkit.debuginspector import DebugInspector
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class DebugSession:
|
|
19
|
+
"""
|
|
20
|
+
A component that enables step-through execution of agent
|
|
21
|
+
operations.
|
|
22
|
+
|
|
23
|
+
Manages breakpoints and pauses execution when an event
|
|
24
|
+
matches a registered breakpoint. Provides a DebugInspector
|
|
25
|
+
for read-only state inspection during pauses.
|
|
26
|
+
|
|
27
|
+
:param agent: The Agent instance to debug.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(self, agent) -> None:
|
|
31
|
+
|
|
32
|
+
self._agent = agent
|
|
33
|
+
self._breakpoints = []
|
|
34
|
+
self._is_paused = False
|
|
35
|
+
self._is_active = False
|
|
36
|
+
self._inspector = None
|
|
37
|
+
self._pause_callback = None
|
|
38
|
+
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def is_paused(self) -> bool:
|
|
43
|
+
"""
|
|
44
|
+
Whether execution is currently paused at a breakpoint.
|
|
45
|
+
|
|
46
|
+
:returns: True if paused, False otherwise.
|
|
47
|
+
"""
|
|
48
|
+
return self._is_paused
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def is_active(self) -> bool:
|
|
52
|
+
"""
|
|
53
|
+
Whether the debug session is currently enabled.
|
|
54
|
+
|
|
55
|
+
:returns: True if the session is active, False otherwise.
|
|
56
|
+
"""
|
|
57
|
+
return self._is_active
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def inspector(self) -> Optional[DebugInspector]:
|
|
61
|
+
"""
|
|
62
|
+
The DebugInspector for the current pause, or None when
|
|
63
|
+
execution is not paused.
|
|
64
|
+
|
|
65
|
+
:returns: A DebugInspector instance or None.
|
|
66
|
+
"""
|
|
67
|
+
return self._inspector
|
|
68
|
+
|
|
69
|
+
def add_breakpoint(self, breakpoint: Breakpoint) -> None:
|
|
70
|
+
"""
|
|
71
|
+
Registers a breakpoint with the session.
|
|
72
|
+
|
|
73
|
+
:param breakpoint: The Breakpoint to register.
|
|
74
|
+
"""
|
|
75
|
+
self._breakpoints.append(breakpoint)
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
def remove_breakpoint(self, breakpoint: Breakpoint) -> None:
|
|
79
|
+
"""
|
|
80
|
+
Deregisters a breakpoint from the session.
|
|
81
|
+
|
|
82
|
+
If the breakpoint is not found, this method does nothing.
|
|
83
|
+
|
|
84
|
+
:param breakpoint: The Breakpoint to deregister.
|
|
85
|
+
"""
|
|
86
|
+
if breakpoint in self._breakpoints:
|
|
87
|
+
self._breakpoints.remove(breakpoint)
|
|
88
|
+
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
def list_breakpoints(self) -> list:
|
|
92
|
+
"""
|
|
93
|
+
Returns the list of registered Breakpoint objects.
|
|
94
|
+
|
|
95
|
+
:returns: A list copy of the registered breakpoints.
|
|
96
|
+
"""
|
|
97
|
+
result = list(self._breakpoints)
|
|
98
|
+
return result
|
|
99
|
+
|
|
100
|
+
def clear_breakpoints(self) -> None:
|
|
101
|
+
"""
|
|
102
|
+
Removes all registered breakpoints from the session.
|
|
103
|
+
"""
|
|
104
|
+
self._breakpoints.clear()
|
|
105
|
+
return
|
|
106
|
+
|
|
107
|
+
def check_breakpoint(self, event_type: str, target_name: str = None) -> None:
|
|
108
|
+
"""
|
|
109
|
+
Checks whether any registered breakpoint matches the given
|
|
110
|
+
event type and target name. If a match is found and the
|
|
111
|
+
session is active, pauses execution and invokes the
|
|
112
|
+
registered pause callback with a DebugInspector.
|
|
113
|
+
|
|
114
|
+
:param event_type: The event type string to check against.
|
|
115
|
+
:param target_name: An optional target name string to check
|
|
116
|
+
against.
|
|
117
|
+
"""
|
|
118
|
+
if not self._is_active:
|
|
119
|
+
return
|
|
120
|
+
|
|
121
|
+
matched = False
|
|
122
|
+
for bp in self._breakpoints:
|
|
123
|
+
if bp.matches(event_type, target_name=target_name):
|
|
124
|
+
matched = True
|
|
125
|
+
break
|
|
126
|
+
|
|
127
|
+
if not matched:
|
|
128
|
+
return
|
|
129
|
+
|
|
130
|
+
self._is_paused = True
|
|
131
|
+
self._inspector = DebugInspector(self._agent)
|
|
132
|
+
|
|
133
|
+
if self._pause_callback is not None:
|
|
134
|
+
self._pause_callback(self._inspector)
|
|
135
|
+
|
|
136
|
+
return
|
|
137
|
+
|
|
138
|
+
def continue_execution(self) -> None:
|
|
139
|
+
"""
|
|
140
|
+
Resumes execution after a pause. Clears the paused state
|
|
141
|
+
and the inspector.
|
|
142
|
+
"""
|
|
143
|
+
self._is_paused = False
|
|
144
|
+
self._inspector = None
|
|
145
|
+
return
|
|
146
|
+
|
|
147
|
+
def step(self) -> None:
|
|
148
|
+
"""
|
|
149
|
+
Resumes execution until the next breakpoint-eligible point
|
|
150
|
+
is reached, regardless of whether a breakpoint is registered
|
|
151
|
+
at that point. Clears the current paused state.
|
|
152
|
+
"""
|
|
153
|
+
self._is_paused = False
|
|
154
|
+
self._inspector = None
|
|
155
|
+
return
|
|
156
|
+
|
|
157
|
+
def start(self) -> None:
|
|
158
|
+
"""
|
|
159
|
+
Enables the debug session. After calling start, breakpoint
|
|
160
|
+
checks will be active.
|
|
161
|
+
"""
|
|
162
|
+
self._is_active = True
|
|
163
|
+
return
|
|
164
|
+
|
|
165
|
+
def stop(self) -> None:
|
|
166
|
+
"""
|
|
167
|
+
Disables the debug session and resumes any paused execution.
|
|
168
|
+
Clears the paused state and inspector.
|
|
169
|
+
"""
|
|
170
|
+
self._is_active = False
|
|
171
|
+
self._is_paused = False
|
|
172
|
+
self._inspector = None
|
|
173
|
+
return
|
|
174
|
+
|
|
175
|
+
def set_pause_callback(self, callback) -> None:
|
|
176
|
+
"""
|
|
177
|
+
Sets the callback function to be invoked when execution
|
|
178
|
+
is paused at a breakpoint. The callback receives a
|
|
179
|
+
DebugInspector instance as its single argument.
|
|
180
|
+
|
|
181
|
+
:param callback: A callable that accepts a DebugInspector.
|
|
182
|
+
"""
|
|
183
|
+
self._pause_callback = callback
|
|
184
|
+
return
|
|
185
|
+
|
|
186
|
+
def __repr__(self) -> str:
|
|
187
|
+
"""
|
|
188
|
+
Returns a detailed string representation including class
|
|
189
|
+
name, agent identifier, breakpoint count, and pause state.
|
|
190
|
+
|
|
191
|
+
:returns: A repr string for debugging.
|
|
192
|
+
"""
|
|
193
|
+
agent_identity = getattr(self._agent, "identity", None)
|
|
194
|
+
if agent_identity is not None:
|
|
195
|
+
agent_id = getattr(agent_identity, "identifier", "unknown")
|
|
196
|
+
else:
|
|
197
|
+
agent_id = "unknown"
|
|
198
|
+
|
|
199
|
+
breakpoint_count = len(self._breakpoints)
|
|
200
|
+
repr_str = "DebugSession(agent_id={!r}, breakpoints={}, is_paused={})".format(
|
|
201
|
+
agent_id, breakpoint_count, self._is_paused
|
|
202
|
+
)
|
|
203
|
+
return repr_str
|
|
204
|
+
|
|
205
|
+
def __str__(self) -> str:
|
|
206
|
+
"""
|
|
207
|
+
Returns a human-readable summary including the agent
|
|
208
|
+
identifier, breakpoint count, and whether execution is
|
|
209
|
+
paused.
|
|
210
|
+
|
|
211
|
+
:returns: A human-readable string.
|
|
212
|
+
"""
|
|
213
|
+
agent_identity = getattr(self._agent, "identity", None)
|
|
214
|
+
if agent_identity is not None:
|
|
215
|
+
agent_id = getattr(agent_identity, "identifier", "unknown")
|
|
216
|
+
else:
|
|
217
|
+
agent_id = "unknown"
|
|
218
|
+
|
|
219
|
+
breakpoint_count = len(self._breakpoints)
|
|
220
|
+
str_val = "DebugSession: agent_id={}, breakpoints={}, is_paused={}".format(
|
|
221
|
+
agent_id, breakpoint_count, self._is_paused
|
|
222
|
+
)
|
|
223
|
+
return str_val
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the DefaultValueStrategy for returning a configured default value
|
|
3
|
+
when a dependency is unavailable.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from ccai.agentkit.degradationstrategy import DegradationStrategy
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DefaultValueStrategy(DegradationStrategy):
|
|
12
|
+
"""
|
|
13
|
+
Returns a configured default value when the dependency is unavailable.
|
|
14
|
+
|
|
15
|
+
:param default_value: The default value to return.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, default_value) -> None:
|
|
19
|
+
super().__init__("default_value")
|
|
20
|
+
self._default_value = default_value
|
|
21
|
+
return
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def default_value(self):
|
|
25
|
+
"""
|
|
26
|
+
The configured default value.
|
|
27
|
+
|
|
28
|
+
:returns: The default value.
|
|
29
|
+
"""
|
|
30
|
+
return self._default_value
|
|
31
|
+
|
|
32
|
+
def degrade(self, dependency_name: str, exception: Exception,
|
|
33
|
+
context: Optional[dict] = None):
|
|
34
|
+
"""
|
|
35
|
+
Returns the configured default value.
|
|
36
|
+
|
|
37
|
+
:param dependency_name: Name of the unavailable dependency.
|
|
38
|
+
:param exception: The exception that triggered degradation.
|
|
39
|
+
:param context: Optional context dictionary.
|
|
40
|
+
|
|
41
|
+
:returns: The configured default value.
|
|
42
|
+
"""
|
|
43
|
+
return self._default_value
|