agentengine-sdk-python 0.8.1__py3-none-any.whl → 0.8.2__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.
- {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/METADATA +22 -2
- {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/RECORD +356 -222
- ksadk/a2a/_space_client_events.py +381 -0
- ksadk/a2a/event_adapter.py +156 -64
- ksadk/a2a/executor.py +179 -63
- ksadk/a2a/space_client.py +6 -333
- ksadk/a2ui/core.py +222 -53
- ksadk/agui/_agent_helpers.py +243 -0
- ksadk/agui/a2ui_projection.py +12 -5
- ksadk/agui/agent.py +443 -259
- ksadk/api/client.py +525 -27
- ksadk/builders/code_builder.py +284 -8
- ksadk/builders/container_builder.py +8 -1
- ksadk/builders/managed_runtime_builder.py +39 -35
- ksadk/cli/__init__.py +17 -0
- ksadk/cli/cmd_dashboard.py +15 -1
- ksadk/cli/cmd_deploy.py +10 -2
- ksadk/cli/cmd_eval.py +66 -9
- ksadk/cli/cmd_evalset.py +284 -0
- ksadk/cli/cmd_files.py +5 -1
- ksadk/cli/cmd_hermes.py +1 -126
- ksadk/cli/cmd_invoke.py +28 -38
- ksadk/cli/cmd_managed_runtime.py +95 -0
- ksadk/cli/cmd_observe.py +85 -0
- ksadk/cli/cmd_openclaw.py +1 -435
- ksadk/cli/cmd_replay.py +28 -4
- ksadk/cli/cmd_studio.py +99 -8
- ksadk/cli/cmd_web.py +10 -2
- ksadk/cli/hermes_env.py +151 -0
- ksadk/cli/invoke_payload.py +49 -0
- ksadk/cli/openclaw_env.py +458 -0
- ksadk/codex/client.py +180 -30
- ksadk/codex/runtime.py +428 -326
- ksadk/configs/env_registry.py +66 -12
- ksadk/configs/env_registry_pcm.py +181 -0
- ksadk/configs/env_var_spec.py +18 -0
- ksadk/configs/global_config.py +5 -0
- ksadk/context_engine/__init__.py +98 -0
- ksadk/context_engine/assembler.py +176 -0
- ksadk/context_engine/baseline.py +419 -0
- ksadk/context_engine/cache_observability.py +228 -0
- ksadk/context_engine/capabilities.py +443 -0
- ksadk/context_engine/contributors.py +344 -0
- ksadk/context_engine/hosted_pipeline.py +417 -0
- ksadk/context_engine/models.py +117 -0
- ksadk/context_engine/planner.py +698 -0
- ksadk/context_engine/policies.py +319 -0
- ksadk/context_engine/projection.py +31 -0
- ksadk/context_engine/shadow_plan.py +266 -0
- ksadk/context_engine/tokenizer.py +164 -0
- ksadk/conversations/context.py +126 -6
- ksadk/conversations/message_projection.py +292 -28
- ksadk/conversations/model_context.py +49 -3
- ksadk/conversations/runtime_compaction.py +207 -5
- ksadk/conversations/runtime_input.py +184 -2
- ksadk/conversations/runtime_invocation.py +81 -3
- ksadk/conversations/runtime_observability.py +141 -0
- ksadk/conversations/runtime_payloads.py +42 -0
- ksadk/conversations/runtime_preparation.py +272 -2
- ksadk/conversations/runtime_resume.py +20 -1
- ksadk/conversations/runtime_stream_events.py +94 -9
- ksadk/conversations/semantic_summary.py +311 -1
- ksadk/conversations/session_lock.py +51 -0
- ksadk/deployment/env_forward.py +72 -0
- ksadk/deployment/managed_runtime.py +5 -0
- ksadk/deployment/providers/serverless.py +143 -69
- ksadk/evaluation/__init__.py +32 -0
- ksadk/evaluation/a2a_adapter.py +9 -1
- ksadk/evaluation/adapters.py +18 -5
- ksadk/evaluation/agent_eval_client.py +395 -0
- ksadk/evaluation/cloud_binding.py +80 -0
- ksadk/evaluation/cloud_converter.py +194 -0
- ksadk/evaluation/cloud_service.py +199 -0
- ksadk/evaluation/contracts.py +73 -4
- ksadk/evaluation/evaluators.py +183 -17
- ksadk/evaluation/evidence.py +258 -0
- ksadk/evaluation/executor.py +31 -6
- ksadk/evaluation/local_adapter.py +550 -0
- ksadk/evaluation/service_env.py +27 -0
- ksadk/evaluation/studio_build_adapter.py +253 -0
- ksadk/evaluation/target.py +15 -6
- ksadk/events/__init__.py +13 -13
- ksadk/events/_v1_compat/__init__.py +1 -0
- ksadk/events/_v1_compat/models.py +299 -0
- ksadk/events/_v1_compat/parser.py +247 -0
- ksadk/events/_v1_compat/projection.py +753 -0
- ksadk/events/adapters/__init__.py +34 -0
- ksadk/events/adapters/_a2a_snapshot.py +622 -0
- ksadk/events/adapters/_a2a_support.py +275 -0
- ksadk/events/adapters/_codex_interactions.py +375 -0
- ksadk/events/adapters/_codex_items.py +801 -0
- ksadk/events/adapters/_codex_validators.py +311 -0
- ksadk/events/adapters/_langgraph_support.py +785 -0
- ksadk/events/adapters/a2a.py +841 -0
- ksadk/events/adapters/adk.py +503 -0
- ksadk/events/adapters/codex.py +717 -0
- ksadk/events/adapters/langgraph.py +745 -0
- ksadk/events/canonical.py +440 -0
- ksadk/events/canonical_replay.py +497 -0
- ksadk/events/canonical_store.py +468 -0
- ksadk/events/cold_recovery.py +257 -0
- ksadk/events/content.py +89 -0
- ksadk/events/identity.py +86 -0
- ksadk/events/pipeline.py +455 -0
- ksadk/events/projections.py +66 -0
- ksadk/events/reducer.py +661 -0
- ksadk/events/replay.py +3 -36
- ksadk/events/runtime_event.py +20 -265
- ksadk/events/session_event.py +324 -0
- ksadk/events/store.py +3 -316
- ksadk/events/v1_compat.py +41 -0
- ksadk/harness/runtime.py +160 -57
- ksadk/identity/resolver.py +4 -3
- ksadk/interaction/__init__.py +28 -0
- ksadk/interaction/contracts.py +136 -0
- ksadk/interaction/ledger.py +189 -0
- ksadk/interaction/provider.py +122 -0
- ksadk/interaction/providers/__init__.py +52 -0
- ksadk/interaction/providers/adk.py +40 -0
- ksadk/interaction/providers/codex.py +94 -0
- ksadk/interaction/providers/langgraph.py +58 -0
- ksadk/kernel/__init__.py +117 -0
- ksadk/kernel/authorization.py +258 -0
- ksadk/kernel/bootstrap.py +1074 -0
- ksadk/kernel/contract_fingerprints.py +61 -0
- ksadk/kernel/contracts.py +362 -0
- ksadk/kernel/control.py +219 -0
- ksadk/kernel/errors.py +79 -0
- ksadk/kernel/ingress.py +1102 -0
- ksadk/kernel/mapping.py +111 -0
- ksadk/kernel/memory_store.py +1133 -0
- ksadk/kernel/postgres_store.py +1756 -0
- ksadk/kernel/recovery.py +452 -0
- ksadk/kernel/runtime_identity.py +103 -0
- ksadk/kernel/sql/001_agent_kernel.sql +120 -0
- ksadk/kernel/sqlite_store.py +1410 -0
- ksadk/kernel/state.py +145 -0
- ksadk/kernel/store.py +232 -0
- ksadk/kernel/worker.py +953 -0
- ksadk/knowledge_base/client.py +7 -0
- ksadk/knowledge_base/service.py +32 -5
- ksadk/memory/__init__.py +61 -0
- ksadk/memory/adk/backends/base_ltm_backend.py +96 -1
- ksadk/memory/adk/backends/http_ltm_backend.py +14 -5
- ksadk/memory/adk/backends/inmemory_ltm_backend.py +136 -3
- ksadk/memory/adk/backends/sdk_ltm_backend.py +384 -2
- ksadk/memory/adk/backends/sqlite_ltm_backend.py +95 -0
- ksadk/memory/coordinator.py +461 -0
- ksadk/memory/events.py +202 -0
- ksadk/memory/extraction.py +228 -0
- ksadk/memory/ltm_backend_factory.py +16 -3
- ksadk/memory/models.py +316 -0
- ksadk/memory/policy.py +215 -0
- ksadk/memory/provider.py +47 -0
- ksadk/memory/provider_adapter.py +159 -0
- ksadk/memory/provider_resolver.py +71 -0
- ksadk/memory/providers/__init__.py +5 -0
- ksadk/memory/providers/local_sqlite.py +490 -0
- ksadk/memory/resolved_policy.py +145 -0
- ksadk/memory/service.py +188 -6
- ksadk/model_proxy/bootstrap.py +16 -9
- ksadk/model_proxy/detect.py +202 -9
- ksadk/model_proxy/namespace.py +39 -15
- ksadk/model_proxy/server.py +24 -5
- ksadk/model_proxy/transform.py +60 -2
- ksadk/observability/__init__.py +25 -0
- ksadk/observability/session_log.py +420 -0
- ksadk/observability/trajectory.py +105 -0
- ksadk/prompts/__init__.py +71 -0
- ksadk/prompts/compiler.py +215 -0
- ksadk/prompts/models.py +82 -0
- ksadk/prompts/projection.py +89 -0
- ksadk/prompts/resolved.py +137 -0
- ksadk/prompts/sources.py +233 -0
- ksadk/runners/_langgraph_runner_streams.py +822 -0
- ksadk/runners/adk_runner.py +5 -5
- ksadk/runners/base_runner.py +16 -0
- ksadk/runners/factory.py +1 -2
- ksadk/runners/langgraph_runner.py +198 -437
- ksadk/runtime/_runner_adapter/__init__.py +1 -0
- ksadk/runtime/_runner_adapter/stream_mapping.py +788 -0
- ksadk/runtime/adapter.py +118 -2
- ksadk/runtime/conversation_execution.py +316 -182
- ksadk/runtime/executor.py +144 -3
- ksadk/runtime/factory.py +193 -7
- ksadk/runtime/hosted_finalizer.py +268 -0
- ksadk/runtime/launch.py +14 -1
- ksadk/runtime/preprocessing.py +25 -3
- ksadk/runtime/runner_adapter.py +288 -508
- ksadk/runtime/usage.py +33 -0
- ksadk/sandbox/backends/e2b.py +35 -2
- ksadk/server/composition.py +8 -0
- ksadk/server/factory.py +69 -6
- ksadk/server/routes/kernel_ingress.py +258 -0
- ksadk/server/routes/openai_compat.py +88 -8
- ksadk/server/routes/projection.py +35 -20
- ksadk/server/routes/run.py +94 -0
- ksadk/server/routes/sessions.py +2 -0
- ksadk/server/routes/streaming.py +5 -2
- ksadk/server/static/assets/{ArtifactsPanel-CakCqxEN.js → ArtifactsPanel-DSU1sWD_.js} +1 -1
- ksadk/server/static/assets/{CodeBlock-CynLknyO.js → CodeBlock-DOH6MVcn.js} +4 -4
- ksadk/server/static/assets/{MathMessageMarkdown-3sQdOysS.js → MathMessageMarkdown-BL8my1R2.js} +4 -4
- ksadk/server/static/assets/MathMessageMarkdown-BorAY7qD.css +1 -0
- ksadk/server/static/assets/MermaidBlock-Dz4IP-Tx.js +312 -0
- ksadk/server/static/assets/NativeTerminalPanel-DUrK0JpZ.js +1 -0
- ksadk/server/static/assets/abnfDiagram-VCTEODGH-g20pFzNV.js +1 -0
- ksadk/server/static/assets/arc-C4FzinUA.js +1 -0
- ksadk/server/static/assets/architecture-7GRP2DOG-DjKratdf.js +1 -0
- ksadk/server/static/assets/architectureDiagram-5GKGNRK7-DpIqL5h4.js +36 -0
- ksadk/server/static/assets/blockDiagram-NRAW4CY4-BjkljTNz.js +129 -0
- ksadk/server/static/assets/c4Diagram-UCG6FXSJ-Dk_ieq2X.js +38 -0
- ksadk/server/static/assets/channel-4cQHKtx1.js +1 -0
- ksadk/server/static/assets/chunk-2Q5K7J3B-DmgWkESh.js +1 -0
- ksadk/server/static/assets/{chunk-FMBD7UC4-B_fH2YuH.js → chunk-5VM5RSS4-BVHAchFb.js} +1 -1
- ksadk/server/static/assets/{chunk-ND2GUHAM-D6rFLaVV.js → chunk-F27PBJKO-C-ipQzuS.js} +1 -1
- ksadk/server/static/assets/chunk-G27WJ6UU-C2EyJbIK.js +231 -0
- ksadk/server/static/assets/{chunk-4BX2VUAB-B9drTgOW.js → chunk-JWPE2WC7-vYvVJb_M.js} +1 -1
- ksadk/server/static/assets/chunk-LCL6LL3I-BcI6ysPT.js +206 -0
- ksadk/server/static/assets/chunk-POPQ4Y6H-C030x_Z1.js +1 -0
- ksadk/server/static/assets/chunk-RHFEMEQ7-yyGpsz4n.js +168 -0
- ksadk/server/static/assets/chunk-SVP7TREG-BLTlmMU7.js +88 -0
- ksadk/server/static/assets/chunk-XXDRQBXY-C_32ArgP.js +1 -0
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DLFd9Xi0.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DLFd9Xi0.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-S5V4N54A-ChNs_Mdk.js → cose-bilkent-JH36ORCC-9YQYwdl0.js} +1 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-DjEM48Qp.js +1 -0
- ksadk/server/static/assets/cynefinDiagram-5FMLGOSQ-ErLF5N13.js +62 -0
- ksadk/server/static/assets/cytoscape.esm-CyCl8rPi.js +321 -0
- ksadk/server/static/assets/dagre-3AP2YEHR-DFiQF-6f.js +4 -0
- ksadk/server/static/assets/dagre-BuhGnRI1.js +1 -0
- ksadk/server/static/assets/diagram-S7CK7UJ4-Bt1v8-GC.js +30 -0
- ksadk/server/static/assets/diagram-UQ7AKVKN-DSCxJdBK.js +41 -0
- ksadk/server/static/assets/diagram-VSXAHHWV-DHfYwp_9.js +3 -0
- ksadk/server/static/assets/diagram-VX7I27RA-DdzD-4Le.js +24 -0
- ksadk/server/static/assets/diagram-Z3DM3KII-Du-nAJ9F.js +24 -0
- ksadk/server/static/assets/{dist-Dli7qW-B.js → dist-8hqcx0sU.js} +1 -1
- ksadk/server/static/assets/dist-B7seoj3d.js +1 -0
- ksadk/server/static/assets/{dist-C1sz5Eo3.js → dist-BE7bu-DL.js} +1 -1
- ksadk/server/static/assets/{dist-fhOuWds5.js → dist-BVDffZ0U.js} +1 -1
- ksadk/server/static/assets/{dist-BjOdlDjj.js → dist-BX8z72IC.js} +1 -1
- ksadk/server/static/assets/{dist-DsHPdk3W.js → dist-Bf2M8m3N.js} +1 -1
- ksadk/server/static/assets/{dist-o2OVmKvt.js → dist-BjU6y-A2.js} +1 -1
- ksadk/server/static/assets/{dist-DWKByxWV.js → dist-BytlxIDT.js} +1 -1
- ksadk/server/static/assets/{dist-DJN_6Y39.js → dist-CSh_DE14.js} +1 -1
- ksadk/server/static/assets/{dist-DQU9EWw-.js → dist-CXYYBw3_.js} +1 -1
- ksadk/server/static/assets/{dist-4N2NMVYg.js → dist-C_wsv-Qd.js} +1 -1
- ksadk/server/static/assets/{dist-gLnrGsoU.js → dist-ClxGviKw.js} +1 -1
- ksadk/server/static/assets/{dist-j6Dxmf_j.js → dist-CttYUqzS.js} +1 -1
- ksadk/server/static/assets/{dist-D6MpCZtz.js → dist-DNp6rLRA.js} +1 -1
- ksadk/server/static/assets/{dist-BB3-OwTQ.js → dist-DUX-id_F.js} +1 -1
- ksadk/server/static/assets/{dist-_pHPTyZ-.js → dist-DmldrHd_.js} +1 -1
- ksadk/server/static/assets/{dist-CWV4lDr1.js → dist-DnfXs8Vn.js} +2 -2
- ksadk/server/static/assets/{dist-B5oS1zcj.js → dist-Dq9gLD7L.js} +1 -1
- ksadk/server/static/assets/{dist-B-jNR6Vn.js → dist-W-TIVntx.js} +1 -1
- ksadk/server/static/assets/{dist-BIlKoW0k.js → dist-dDdADKFA.js} +1 -1
- ksadk/server/static/assets/{dist-X4TnqwOK.js → dist-dydu68Fl.js} +1 -1
- ksadk/server/static/assets/{dist-CmZHzlwZ.js → dist-ngtN0DJB.js} +1 -1
- ksadk/server/static/assets/ebnfDiagram-PWID7BFC-Da9C9NO1.js +1 -0
- ksadk/server/static/assets/erDiagram-SSCWMZ5O-EAGqqR79.js +99 -0
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-CMgMaJrC.js +1 -0
- ksadk/server/static/assets/flowDiagram-A5DVABFB-BBKL0x3P.js +1 -0
- ksadk/server/static/assets/ganttDiagram-EL5Y4UJY-DqJsKb59.js +292 -0
- ksadk/server/static/assets/gitGraph-4MIJSDKK-Dw63mrhw.js +1 -0
- ksadk/server/static/assets/gitGraphDiagram-WWUBYQGX-B6g4dtDi.js +106 -0
- ksadk/server/static/assets/index-8ipRcQ-M.js +240 -0
- ksadk/server/static/assets/index-ByFCqjlh.css +2 -0
- ksadk/server/static/assets/info-A6RAGUB7-B6iAblII.js +1 -0
- ksadk/server/static/assets/infoDiagram-RXCK75RN-Djm_nbd5.js +2 -0
- ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-K0OOfVna.js → ishikawaDiagram-5VMMS53U-DWya9SG2.js} +6 -6
- ksadk/server/static/assets/{journeyDiagram-JHISSGLW-8LeOJaZp.js → journeyDiagram-EYS64GPL-DutxhSNI.js} +6 -6
- ksadk/server/static/assets/{kanban-definition-UN3LZRKU-C6uCgZrW.js → kanban-definition-3QL26DDD-DJdOF8Fm.js} +10 -10
- ksadk/server/static/assets/katex-vFWytM5c.js +257 -0
- ksadk/server/static/assets/{linear-hdBcYzM8.js → linear-BHjG8b-J.js} +1 -1
- ksadk/server/static/assets/mermaid-parser.core-KGSy4jWT.js +166 -0
- ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-Bjy_2v4_.js → mindmap-definition-FBJOCRG2-9-HC88D4.js} +29 -29
- ksadk/server/static/assets/packet-AYTQ26CC-BOYAipuq.js +1 -0
- ksadk/server/static/assets/pegDiagram-XKGWAZYB-DrEZd4fD.js +1 -0
- ksadk/server/static/assets/pie-WAS4IAKB-Ctq0Kbku.js +1 -0
- ksadk/server/static/assets/pieDiagram-E7YTZNPT-DpjqOFFp.js +39 -0
- ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-BmkRbwCg.js → quadrantDiagram-AXDQQJYC-BiNhgOXX.js} +6 -6
- ksadk/server/static/assets/radar-RG4KPBEZ-DN0-ul_0.js +1 -0
- ksadk/server/static/assets/railroad-74A4TZTK-C6cC_to0.js +1 -0
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-BimjIuRc.js +1 -0
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-CvY65ABq.js +1 -0
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-D72Iq_Tv.js +1 -0
- ksadk/server/static/assets/railroadDiagram-O6MQD6OU-_Y3Ojg6G.js +1 -0
- ksadk/server/static/assets/requirementDiagram-EFPCY7ZU-DeCFdg9K.js +84 -0
- ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-l6iXmU65.js → sankeyDiagram-P5KCCOFB-CPH75rhw.js} +7 -7
- ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-Cq6UBeQB.js → sequenceDiagram-WJ2MYXX4-OEpQQdr4.js} +10 -10
- ksadk/server/static/assets/sizeCapture-X5ZJPWSS-heUErzhI.js +1 -0
- ksadk/server/static/assets/stateDiagram-HBIQ2CUA-DvA3jSMB.js +1 -0
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-BgQY03nz.js +1 -0
- ksadk/server/static/assets/swimlanes-XN3QIQJK-CR-dfN_t.js +1 -0
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-DLVw3q5Q.js +8 -0
- ksadk/server/static/assets/{timeline-definition-PNZ67QCA-DEz24vV0.js → timeline-definition-24CTP7MA-DAVJf1TX.js} +7 -7
- ksadk/server/static/assets/treeView-Q6P3EWNA-BMpO0wsB.js +1 -0
- ksadk/server/static/assets/treemap-WGGIJYW6-Et0aqzU3.js +1 -0
- ksadk/server/static/assets/vennDiagram-4TSXK5OY-DwM8eDkh.js +34 -0
- ksadk/server/static/assets/wardley-WFR3VGLG-CbY0mhpl.js +1 -0
- ksadk/server/static/assets/wardleyDiagram-VM6X3IG4-DZL-Zz2t.js +78 -0
- ksadk/server/static/assets/xychartDiagram-S5SC5T6Z-Dy6Yh_hu.js +7 -0
- ksadk/server/static/index.html +2 -2
- ksadk/sessions/__init__.py +26 -9
- ksadk/sessions/_local_service_sync.py +688 -0
- ksadk/sessions/_local_tables.py +21 -0
- ksadk/sessions/_postgres_schema.py +305 -0
- ksadk/sessions/_postgres_tables.py +15 -0
- ksadk/sessions/base.py +80 -1
- ksadk/sessions/in_memory.py +53 -2
- ksadk/sessions/local_service.py +63 -604
- ksadk/sessions/postgres_service.py +58 -148
- ksadk/sessions/resilient.py +35 -1
- ksadk/studio/api.py +577 -25
- ksadk/studio/api_contracts.py +114 -5
- ksadk/studio/api_memory_routes.py +82 -0
- ksadk/studio/authoring.py +252 -27
- ksadk/studio/authoring_coordinator.py +799 -67
- ksadk/studio/builder.py +88 -11
- ksadk/studio/capabilities.py +17 -0
- ksadk/studio/cloud.py +1916 -95
- ksadk/studio/codex_agent_service.py +125 -14
- ksadk/studio/codex_authoring.py +469 -0
- ksadk/studio/codex_builder.py +138 -25
- ksadk/studio/codex_manifest.py +51 -22
- ksadk/studio/codex_run.py +46 -3
- ksadk/studio/compiler.py +1 -0
- ksadk/studio/contracts.py +114 -3
- ksadk/studio/event_store.py +25 -95
- ksadk/studio/framework_run.py +231 -3
- ksadk/studio/hosted_kernel.py +317 -0
- ksadk/studio/manifest_resolver.py +131 -0
- ksadk/studio/model_client.py +95 -9
- ksadk/studio/model_profile_service.py +1 -1
- ksadk/studio/operations.py +37 -5
- ksadk/studio/otel_trace.py +348 -42
- ksadk/studio/pcm_memory.py +85 -0
- ksadk/studio/repository.py +23 -2
- ksadk/studio/resource_catalog.py +43 -0
- ksadk/studio/run_service.py +563 -137
- ksadk/studio/runtime_source.py +42 -16
- ksadk/studio/service.py +1180 -72
- ksadk/studio/shared_web.py +32 -22
- ksadk/studio/static/assets/index-BLpcdrgW.css +1 -0
- ksadk/studio/static/assets/index-CYekR2Xv.js +260 -0
- ksadk/studio/static/index.html +2 -2
- ksadk/studio/templates.py +100 -8
- ksadk/studio/validator.py +19 -0
- ksadk/studio/workspace.py +30 -32
- ksadk/tracing/setup.py +304 -3
- ksadk/version.py +1 -1
- ksadk_runtime_common/schemas/runtime_event_v1.json +37 -0
- ksadk_runtime_common/schemas/runtime_event_v2.json +271 -0
- ksadk/events/parser.py +0 -191
- ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +0 -1
- ksadk/server/static/assets/MermaidBlock-NERD_ef7.js +0 -303
- ksadk/server/static/assets/NativeTerminalPanel-CiHWf82q.js +0 -1
- ksadk/server/static/assets/arc-DrgjcKhl.js +0 -1
- ksadk/server/static/assets/architecture-7EHR7CIX-CpZLRCcY.js +0 -1
- ksadk/server/static/assets/architectureDiagram-3BPJPVTR-BXoVRbQ6.js +0 -36
- ksadk/server/static/assets/blockDiagram-GPEHLZMM-BnaB3Ywv.js +0 -132
- ksadk/server/static/assets/c4Diagram-AAUBKEIU-Dw4weZcp.js +0 -10
- ksadk/server/static/assets/channel-Dt3rQTFI.js +0 -1
- ksadk/server/static/assets/chunk-2J33WTMH-ChjpLK7j.js +0 -1
- ksadk/server/static/assets/chunk-55IACEB6-CK4ROATy.js +0 -1
- ksadk/server/static/assets/chunk-727SXJPM-B9KtTTgw.js +0 -206
- ksadk/server/static/assets/chunk-AQP2D5EJ-1O1mki3m.js +0 -231
- ksadk/server/static/assets/chunk-QZHKN3VN-iXEZtKQc.js +0 -1
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-DIveV17Q.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-DIveV17Q.js +0 -1
- ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +0 -321
- ksadk/server/static/assets/dagre-BM42HDAG-D0QXg_MQ.js +0 -4
- ksadk/server/static/assets/dagre-Bx709z4p.js +0 -1
- ksadk/server/static/assets/diagram-2AECGRRQ-DBDDKwBQ.js +0 -43
- ksadk/server/static/assets/diagram-5GNKFQAL-BkwDOxmO.js +0 -10
- ksadk/server/static/assets/diagram-KO2AKTUF-Bv8waYvY.js +0 -3
- ksadk/server/static/assets/diagram-LMA3HP47-e1VECDdu.js +0 -24
- ksadk/server/static/assets/diagram-OG6HWLK6-Ds9adfRl.js +0 -24
- ksadk/server/static/assets/dist-B5J2uhNk.js +0 -1
- ksadk/server/static/assets/erDiagram-TEJ5UH35-BPItFKH6.js +0 -85
- ksadk/server/static/assets/eventmodeling-FCH6USID-DYFSxbqr.js +0 -1
- ksadk/server/static/assets/flowDiagram-I6XJVG4X-BbYB9w5Y.js +0 -162
- ksadk/server/static/assets/ganttDiagram-6RSMTGT7-TQXa0KXv.js +0 -292
- ksadk/server/static/assets/gitGraph-WXDBUCRP-DyNYp6BN.js +0 -1
- ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-bKblCnpa.js +0 -106
- ksadk/server/static/assets/graphlib-B8gBHxth.js +0 -1
- ksadk/server/static/assets/index-R52pJJvg.js +0 -177
- ksadk/server/static/assets/index-jJr3_955.css +0 -2
- ksadk/server/static/assets/info-J43DQDTF-WUx7qTde.js +0 -1
- ksadk/server/static/assets/infoDiagram-5YYISTIA-BGVT7J_i.js +0 -2
- ksadk/server/static/assets/katex-CYWseY5E.js +0 -265
- ksadk/server/static/assets/mermaid-parser.core-BWrDjSZM.js +0 -161
- ksadk/server/static/assets/packet-YPE3B663-BN13y_xl.js +0 -1
- ksadk/server/static/assets/pie-LRSECV5Y-ftSLXhhc.js +0 -1
- ksadk/server/static/assets/pieDiagram-4H26LBE5-GmmqNiVH.js +0 -30
- ksadk/server/static/assets/radar-GUYGQ44K-jaICkIeO.js +0 -1
- ksadk/server/static/assets/requirementDiagram-4Y6WPE33-DSWFqL7c.js +0 -84
- ksadk/server/static/assets/stateDiagram-AJRCARHV-qzTQpg3Y.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-BYCoYGAN.js +0 -1
- ksadk/server/static/assets/treeView-BLDUP644-Cpib_vlz.js +0 -1
- ksadk/server/static/assets/treemap-LRROVOQU-DQxfmVHK.js +0 -1
- ksadk/server/static/assets/vennDiagram-CIIHVFJN-CMCixki2.js +0 -34
- ksadk/server/static/assets/wardley-L42UT6IY-BQYHnnkU.js +0 -1
- ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-CVzB8F9K.js +0 -78
- ksadk/server/static/assets/xychartDiagram-2RQKCTM6-BFBqBLc1.js +0 -7
- ksadk/studio/evaluation.py +0 -192
- ksadk/studio/static/assets/index-CaEN0eTR.css +0 -1
- ksadk/studio/static/assets/index-DI2eY_NH.js +0 -252
- {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/WHEEL +0 -0
- {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/top_level.txt +0 -0
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import json
|
|
5
|
+
import time
|
|
5
6
|
from typing import Any, Callable, Dict, Mapping, Optional, Sequence
|
|
6
7
|
|
|
7
8
|
from ksadk.conversations.reasoning_markup import strip_reasoning_markup
|
|
@@ -32,10 +33,13 @@ from ksadk.conversations.runtime_metadata import _update_session_metadata_after_
|
|
|
32
33
|
from ksadk.conversations.runtime_observability import (
|
|
33
34
|
_conversation_span_scope,
|
|
34
35
|
_normalize_usage_payload,
|
|
36
|
+
_set_context_plan_attributes,
|
|
35
37
|
_set_conversation_input_attributes,
|
|
36
38
|
_set_conversation_output_attributes,
|
|
37
39
|
_set_conversation_span_attributes,
|
|
38
40
|
_set_conversation_usage_attributes,
|
|
41
|
+
_set_prompt_cache_attributes,
|
|
42
|
+
_set_prompt_source_attributes,
|
|
39
43
|
_span_feedback_metadata,
|
|
40
44
|
)
|
|
41
45
|
from ksadk.conversations.runtime_persistence import (
|
|
@@ -59,6 +63,42 @@ from ksadk.runtime_context import (
|
|
|
59
63
|
from ksadk.sessions import resolve_session_service
|
|
60
64
|
|
|
61
65
|
|
|
66
|
+
def _perf_monotonic() -> float:
|
|
67
|
+
return time.monotonic()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _record_baseline_turn(
|
|
71
|
+
*,
|
|
72
|
+
prepared: Any,
|
|
73
|
+
model: str | None,
|
|
74
|
+
usage: Mapping[str, Any] | None,
|
|
75
|
+
ptl: bool,
|
|
76
|
+
attempts: int,
|
|
77
|
+
turn_start_monotonic: float | None,
|
|
78
|
+
) -> None:
|
|
79
|
+
"""env-gated 旁路采集:未启用时 no-op,启用时记录一条 turn 基线。
|
|
80
|
+
|
|
81
|
+
只读 prepared.shadow_context_plan + usage + PTL/latency 信号,不进决策路径、不抛异常。
|
|
82
|
+
"""
|
|
83
|
+
from ksadk.context_engine.baseline import record_baseline_turn
|
|
84
|
+
|
|
85
|
+
latency_ms = None
|
|
86
|
+
if turn_start_monotonic is not None:
|
|
87
|
+
latency_ms = int((time.monotonic() - turn_start_monotonic) * 1000)
|
|
88
|
+
record_baseline_turn(
|
|
89
|
+
getattr(prepared, "shadow_context_plan", None),
|
|
90
|
+
session_id=getattr(prepared, "session_id", ""),
|
|
91
|
+
invocation_id=getattr(prepared, "invocation_id", ""),
|
|
92
|
+
model=str(model or ""),
|
|
93
|
+
usage=usage,
|
|
94
|
+
compaction_triggered=bool(getattr(prepared, "compaction_triggered", False)),
|
|
95
|
+
compaction_trigger=str(getattr(prepared, "compaction_trigger", "") or ""),
|
|
96
|
+
prompt_too_long=ptl,
|
|
97
|
+
retry_attempts=attempts,
|
|
98
|
+
turn_latency_ms=latency_ms,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
62
102
|
async def invoke_conversation_once(
|
|
63
103
|
*,
|
|
64
104
|
runner: Any,
|
|
@@ -80,6 +120,9 @@ async def invoke_conversation_once(
|
|
|
80
120
|
invocation_id: Optional[str] = None,
|
|
81
121
|
session_service_provider: Callable[[], Any] | None = None,
|
|
82
122
|
run_mode: str = RUN_MODE_FOREGROUND,
|
|
123
|
+
agent_system: str = "",
|
|
124
|
+
agent_task: str = "",
|
|
125
|
+
prompt_integration_mode: str = "",
|
|
83
126
|
) -> tuple[str, dict[str, Any]]:
|
|
84
127
|
"""非流式 turn 编排入口。
|
|
85
128
|
|
|
@@ -111,6 +154,11 @@ async def invoke_conversation_once(
|
|
|
111
154
|
governance_state=governance,
|
|
112
155
|
session_service_provider=provider,
|
|
113
156
|
run_mode=entry_run_mode,
|
|
157
|
+
runner=runner,
|
|
158
|
+
runtime_type=_runner_type_name(runner),
|
|
159
|
+
agent_system=agent_system,
|
|
160
|
+
agent_task=agent_task,
|
|
161
|
+
prompt_integration_mode=prompt_integration_mode,
|
|
114
162
|
)
|
|
115
163
|
# prepared 之后的 run_status 写入复用 prepared 的 mode/trigger
|
|
116
164
|
run_mode = prepared.run_mode
|
|
@@ -135,6 +183,7 @@ async def invoke_conversation_once(
|
|
|
135
183
|
user_id=user_id,
|
|
136
184
|
user_input=prepared.user_input,
|
|
137
185
|
)
|
|
186
|
+
prepared.memory_recall_events = ambient_contexts.get("memory_recall_events", [])
|
|
138
187
|
runtime_context = PlatformInvocationContext(
|
|
139
188
|
agent_id=agent_id,
|
|
140
189
|
user_id=user_id,
|
|
@@ -155,9 +204,7 @@ async def invoke_conversation_once(
|
|
|
155
204
|
model_options=prepared.model_options,
|
|
156
205
|
kb_context=ambient_contexts.get("kb_context"),
|
|
157
206
|
memory_context=ambient_contexts.get("memory_context"),
|
|
158
|
-
tool_approval_mode=str(
|
|
159
|
-
prepared.request_metadata.get("tool_approval_mode") or ""
|
|
160
|
-
),
|
|
207
|
+
tool_approval_mode=str(prepared.request_metadata.get("tool_approval_mode") or ""),
|
|
161
208
|
)
|
|
162
209
|
runner_name = _runner_name(runner)
|
|
163
210
|
async with _conversation_span_scope(runner_name) as span:
|
|
@@ -172,7 +219,11 @@ async def invoke_conversation_once(
|
|
|
172
219
|
response_id=response_id,
|
|
173
220
|
)
|
|
174
221
|
_set_conversation_input_attributes(span, prepared.user_input or prepared.user_display_input)
|
|
222
|
+
_set_context_plan_attributes(span, prepared.shadow_context_plan)
|
|
175
223
|
trace_metadata = _span_feedback_metadata(span)
|
|
224
|
+
_baseline_turn_start = _perf_monotonic()
|
|
225
|
+
_baseline_ptl = False
|
|
226
|
+
_baseline_attempts = 0
|
|
176
227
|
await append_run_status_event(
|
|
177
228
|
session_id=prepared.session_id,
|
|
178
229
|
author=runner_name,
|
|
@@ -218,6 +269,8 @@ async def invoke_conversation_once(
|
|
|
218
269
|
raise
|
|
219
270
|
except Exception as exc:
|
|
220
271
|
if attempt == 0 and _is_prompt_too_long_error(exc):
|
|
272
|
+
_baseline_ptl = True
|
|
273
|
+
_baseline_attempts = attempt + 1
|
|
221
274
|
try:
|
|
222
275
|
checkpoint = await _compact_conversation_history_with_governance(
|
|
223
276
|
governance,
|
|
@@ -230,6 +283,16 @@ async def invoke_conversation_once(
|
|
|
230
283
|
trigger="prompt_too_long",
|
|
231
284
|
keep_tail_groups=PTL_RETRY_KEEP_TAIL_GROUPS,
|
|
232
285
|
session_service_provider=provider,
|
|
286
|
+
# PR D1:PTL 路径仍 force=True(trigger_band=emergency),
|
|
287
|
+
# 透传 ownership 便于未来按门控调 PTL 策略;当前行为等价。
|
|
288
|
+
prompt_integration_mode=getattr(
|
|
289
|
+
prepared, "prompt_integration_mode", ""
|
|
290
|
+
),
|
|
291
|
+
compaction_owner=str(
|
|
292
|
+
(getattr(prepared, "shadow_context_plan", None) or {}).get(
|
|
293
|
+
"compaction_owner", ""
|
|
294
|
+
)
|
|
295
|
+
),
|
|
233
296
|
)
|
|
234
297
|
except RuntimeCircuitOpen as circuit_exc:
|
|
235
298
|
await append_run_status_event(
|
|
@@ -293,6 +356,21 @@ async def invoke_conversation_once(
|
|
|
293
356
|
) or (result_usage if result_usage else {})
|
|
294
357
|
_set_conversation_output_attributes(span, output_text)
|
|
295
358
|
_set_conversation_usage_attributes(span, result_usage)
|
|
359
|
+
_set_prompt_cache_attributes(
|
|
360
|
+
span,
|
|
361
|
+
session_id=prepared.session_id,
|
|
362
|
+
plan=prepared.shadow_context_plan,
|
|
363
|
+
usage=result_usage,
|
|
364
|
+
)
|
|
365
|
+
_set_prompt_source_attributes(span, getattr(prepared, "compiled_prompt", None))
|
|
366
|
+
_record_baseline_turn(
|
|
367
|
+
prepared=prepared,
|
|
368
|
+
model=model,
|
|
369
|
+
usage=result_usage,
|
|
370
|
+
ptl=_baseline_ptl,
|
|
371
|
+
attempts=_baseline_attempts,
|
|
372
|
+
turn_start_monotonic=_baseline_turn_start,
|
|
373
|
+
)
|
|
296
374
|
result_agentengine_metadata = _extract_agentengine_metadata(result)
|
|
297
375
|
assistant_metadata: dict[str, Any] = {
|
|
298
376
|
**trace_metadata,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import json
|
|
3
4
|
from contextlib import asynccontextmanager, nullcontext
|
|
4
5
|
from typing import Any, Mapping, Sequence
|
|
5
6
|
|
|
@@ -256,6 +257,62 @@ def _set_span_attribute(span: Any | None, key: str, value: Any) -> None:
|
|
|
256
257
|
return
|
|
257
258
|
|
|
258
259
|
|
|
260
|
+
def _set_context_plan_attributes(span: Any | None, plan: Any | None) -> None:
|
|
261
|
+
"""把 shadow ContextPlan 的统计/ownership/精度挂到 conversation span。
|
|
262
|
+
|
|
263
|
+
``plan`` 为 None 或空时直接 return,对现有 span 无影响。只记录 hash/统计/精度,
|
|
264
|
+
不落完整 Prompt/Memory/Tool 内容(方案 8.8 / 安全要求)。第一个 PR 只挂 plan_id/
|
|
265
|
+
policy_version/tokenizer/planned_input_tokens/integration_mode/accounting_accuracy/
|
|
266
|
+
tokens_by_kind(json)/stable_prefix_hash + ownership 摘要;projected/runtime_reported
|
|
267
|
+
等留后续 PR。
|
|
268
|
+
"""
|
|
269
|
+
if span is None or not plan:
|
|
270
|
+
return
|
|
271
|
+
if not isinstance(plan, Mapping):
|
|
272
|
+
return
|
|
273
|
+
_set_span_attribute(span, "context.plan_id", plan.get("plan_id"))
|
|
274
|
+
_set_span_attribute(span, "context.policy_version", plan.get("policy_version"))
|
|
275
|
+
_set_span_attribute(span, "context.tokenizer", plan.get("tokenizer"))
|
|
276
|
+
_set_span_attribute(span, "context.deployment_mode", plan.get("deployment_mode"))
|
|
277
|
+
_set_span_attribute(span, "context.runtime_type", plan.get("runtime_type"))
|
|
278
|
+
_set_span_attribute(span, "context.planned_input_tokens", plan.get("planned_input_tokens"))
|
|
279
|
+
# 方案 §6.3:projected/runtime_reported 贯穿 Trace(缺口 6)。projected=Adapter 实际投影给
|
|
280
|
+
# Runner 的;runtime_reported=Provider/Runner 回报的实际。None 表示该口径不可得(诚实标注)。
|
|
281
|
+
_set_span_attribute(span, "context.projected_input_tokens", plan.get("projected_input_tokens"))
|
|
282
|
+
_set_span_attribute(
|
|
283
|
+
span, "context.runtime_reported_input_tokens", plan.get("runtime_reported_input_tokens")
|
|
284
|
+
)
|
|
285
|
+
_set_span_attribute(span, "context.integration_mode", plan.get("integration_mode"))
|
|
286
|
+
_set_span_attribute(span, "context.accounting_accuracy", plan.get("accounting_accuracy"))
|
|
287
|
+
_set_span_attribute(span, "context.prompt_owner", plan.get("prompt_owner"))
|
|
288
|
+
_set_span_attribute(span, "context.history_owner", plan.get("history_owner"))
|
|
289
|
+
_set_span_attribute(span, "context.compaction_owner", plan.get("compaction_owner"))
|
|
290
|
+
_set_span_attribute(span, "context.memory_owner", plan.get("memory_owner"))
|
|
291
|
+
_set_span_attribute(span, "context.skill_owner", plan.get("skill_owner"))
|
|
292
|
+
# 方案 §6.3 / 缺口 7:native compaction 不可见时的统一展示规范。compaction_owner=native 且
|
|
293
|
+
# actual 不可见时,标 compaction_visibility=opaque,不把 planned 伪装成 actual。
|
|
294
|
+
compaction_owner = str(plan.get("compaction_owner") or "")
|
|
295
|
+
accuracy = str(plan.get("accounting_accuracy") or "")
|
|
296
|
+
if compaction_owner == "native" and accuracy in ("opaque", "estimated"):
|
|
297
|
+
_set_span_attribute(span, "context.compaction_visibility", "opaque")
|
|
298
|
+
_set_span_attribute(
|
|
299
|
+
span,
|
|
300
|
+
"context.compaction_note",
|
|
301
|
+
"native runtime 内部 compaction 不可见,仅记录平台 projection",
|
|
302
|
+
)
|
|
303
|
+
tokens_by_kind = plan.get("tokens_by_kind")
|
|
304
|
+
if tokens_by_kind:
|
|
305
|
+
try:
|
|
306
|
+
_set_span_attribute(
|
|
307
|
+
span,
|
|
308
|
+
"context.tokens_by_kind",
|
|
309
|
+
json.dumps(dict(tokens_by_kind), ensure_ascii=False),
|
|
310
|
+
)
|
|
311
|
+
except (TypeError, ValueError):
|
|
312
|
+
pass
|
|
313
|
+
_set_span_attribute(span, "context.stable_prefix_hash", plan.get("stable_prefix_hash"))
|
|
314
|
+
|
|
315
|
+
|
|
259
316
|
def _set_conversation_input_attributes(span: Any | None, input_text: str | None) -> None:
|
|
260
317
|
text = " ".join(str(input_text or "").split())
|
|
261
318
|
if not text:
|
|
@@ -365,3 +422,87 @@ def _set_conversation_span_attributes(
|
|
|
365
422
|
span.set_attribute("ksadk.response_id", response_id)
|
|
366
423
|
except Exception:
|
|
367
424
|
return
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def _set_prompt_cache_attributes(
|
|
428
|
+
span: Any | None,
|
|
429
|
+
*,
|
|
430
|
+
session_id: str | None,
|
|
431
|
+
plan: Any | None,
|
|
432
|
+
usage: Mapping[str, Any] | None,
|
|
433
|
+
) -> None:
|
|
434
|
+
"""PR2:记录 shadow CompiledPrompt hash + Provider prompt cache 信号 + 失效诊断到 span。
|
|
435
|
+
|
|
436
|
+
``plan`` 为 ``PreparedConversationTurn.shadow_context_plan``(plain dict)。``usage`` 为
|
|
437
|
+
Runtime 返回的 normalized usage。诊断用进程内 best-effort registry 记录上一稳定前缀,
|
|
438
|
+
pod 重启后清空,精度如实标注。只记录 hash/usage/break reason,不落完整 Prompt(安全要求)。
|
|
439
|
+
plan/usage 缺失时 no-op,对现有 span 无影响。
|
|
440
|
+
"""
|
|
441
|
+
if span is None or not isinstance(plan, Mapping):
|
|
442
|
+
return
|
|
443
|
+
from ksadk.context_engine.cache_observability import (
|
|
444
|
+
diagnose_cache_break,
|
|
445
|
+
get_default_cache_break_registry,
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
stable_prefix_hash = str(
|
|
449
|
+
plan.get("prompt_stable_prefix_hash") or plan.get("stable_prefix_hash") or ""
|
|
450
|
+
)
|
|
451
|
+
accounting_accuracy = str(plan.get("accounting_accuracy") or "opaque")
|
|
452
|
+
_set_span_attribute(span, "prompt.content_hash", plan.get("prompt_content_hash"))
|
|
453
|
+
_set_span_attribute(span, "prompt.stable_prefix_hash", stable_prefix_hash or None)
|
|
454
|
+
section_hashes = plan.get("prompt_section_hashes")
|
|
455
|
+
if isinstance(section_hashes, Mapping) and section_hashes:
|
|
456
|
+
_set_span_attribute(span, "prompt.section_count", len(section_hashes))
|
|
457
|
+
|
|
458
|
+
registry = get_default_cache_break_registry()
|
|
459
|
+
previous_hash = registry.previous(session_id) if session_id else None
|
|
460
|
+
diagnosis = diagnose_cache_break(
|
|
461
|
+
stable_prefix_hash=stable_prefix_hash,
|
|
462
|
+
previous_stable_prefix_hash=previous_hash,
|
|
463
|
+
usage=usage,
|
|
464
|
+
accounting_accuracy=accounting_accuracy, # type: ignore[arg-type]
|
|
465
|
+
)
|
|
466
|
+
_set_span_attribute(span, "prompt.cache.read_input_tokens", diagnosis.cache_read_tokens or None)
|
|
467
|
+
_set_span_attribute(
|
|
468
|
+
span, "prompt.cache.creation_input_tokens", diagnosis.cache_creation_tokens or None
|
|
469
|
+
)
|
|
470
|
+
_set_span_attribute(
|
|
471
|
+
span, "prompt.cache.expected_invalidation", diagnosis.expected_invalidation or None
|
|
472
|
+
)
|
|
473
|
+
_set_span_attribute(span, "prompt.cache.unexpected_break", diagnosis.unexpected_break or None)
|
|
474
|
+
_set_span_attribute(span, "prompt.cache.break_reason", diagnosis.break_reason or None)
|
|
475
|
+
_set_span_attribute(span, "prompt.cache.status", diagnosis.status)
|
|
476
|
+
# 记录本轮稳定前缀供下一轮诊断(best-effort,进程内)。
|
|
477
|
+
if session_id and stable_prefix_hash:
|
|
478
|
+
registry.record(session_id, stable_prefix_hash)
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def _set_prompt_source_attributes(span: Any | None, compiled_prompt: Any | None) -> None:
|
|
482
|
+
"""PR A:记录真实 CompiledPrompt 的 source hash/version/section count 到 span。
|
|
483
|
+
|
|
484
|
+
``compiled_prompt`` 为 ``PreparedConversationTurn.compiled_prompt``(plain dict,agent_system/
|
|
485
|
+
agent_task 非空时由 ResolvedPromptSources 编译)。None 时 no-op。只记 hash/version/count,
|
|
486
|
+
不记 Prompt 正文(安全要求)。
|
|
487
|
+
"""
|
|
488
|
+
if span is None or not isinstance(compiled_prompt, Mapping):
|
|
489
|
+
return
|
|
490
|
+
section_hashes = compiled_prompt.get("prompt_section_hashes")
|
|
491
|
+
if isinstance(section_hashes, Mapping) and section_hashes:
|
|
492
|
+
_set_span_attribute(
|
|
493
|
+
span, "prompt.source.agent_system_hash", section_hashes.get("agent_identity")
|
|
494
|
+
)
|
|
495
|
+
_set_span_attribute(
|
|
496
|
+
span, "prompt.source.agent_task_hash", section_hashes.get("agent_policy")
|
|
497
|
+
)
|
|
498
|
+
_set_span_attribute(span, "prompt.source.section_count", len(section_hashes))
|
|
499
|
+
_set_span_attribute(
|
|
500
|
+
span,
|
|
501
|
+
"prompt.source.platform_policy_version",
|
|
502
|
+
compiled_prompt.get("prompt_platform_policy_version"),
|
|
503
|
+
)
|
|
504
|
+
_set_span_attribute(
|
|
505
|
+
span,
|
|
506
|
+
"prompt.source.resolved_sources_version",
|
|
507
|
+
compiled_prompt.get("prompt_resolved_sources_version"),
|
|
508
|
+
)
|
|
@@ -55,6 +55,42 @@ class PreparedConversationTurn:
|
|
|
55
55
|
request_history: list[dict[str, str]] = field(default_factory=list)
|
|
56
56
|
request_responses_history: list[dict[str, Any]] = field(default_factory=list)
|
|
57
57
|
responses_history: list[dict[str, Any]] = field(default_factory=list)
|
|
58
|
+
# shadow ContextPlan 的 plain dict 投影(P0 可观测基线)。
|
|
59
|
+
# 仅用启发式 tokenizer 按 kind 累加 tokens_by_kind + 标注 ownership/精度,
|
|
60
|
+
# 不进任何决策路径、不进 runner payload。None 表示尚未生成(resume 旁路也会填最小值)。
|
|
61
|
+
shadow_context_plan: dict[str, Any] | None = None
|
|
62
|
+
# PR A:真实 CompiledPrompt 的 plain dict 投影(agent_system/agent_task 非空时由
|
|
63
|
+
# ResolvedPromptSources 编译)。仅用于 hash/trace/future projection,不进 Runner payload。
|
|
64
|
+
# None=instructions-only 回退(canonical 路径无 agent_system/agent_task,或 resume 旁路)。
|
|
65
|
+
compiled_prompt: dict[str, Any] | None = None
|
|
66
|
+
# PR B:per-Build 接管标记。非空("ksadk_hosted")表示本 turn 由 ksadk 编译并接管
|
|
67
|
+
# Runner 的 instructions(仅 prompt_owner=ksadk + ksadk_hosted LangGraph 满足)。
|
|
68
|
+
# 默认空=framework 拥有,Runner 输入与旧逻辑一致。
|
|
69
|
+
prompt_integration_mode: str = ""
|
|
70
|
+
# PR D2:最新 checkpoint 的 WorkingState 审计 dict(仅 ksadk_hosted 路径填充)。
|
|
71
|
+
# 含 current_goal/active_files/pending_tools/pending_approvals/source_seq_range/content_hash。
|
|
72
|
+
# 用于门控重注入 Runner payload(非门控为 None,零注入)。
|
|
73
|
+
working_state: dict[str, Any] | None = None
|
|
74
|
+
# PR E:真实 ContextPlan 与组装输入(仅 ksadk_hosted + KSADK_CONTEXT_ENGINE_V2_ENABLED 时
|
|
75
|
+
# 由 hosted_pipeline 生成)。``context_plan`` 是 ``ContextPlan`` 的 plain dict 投影(含
|
|
76
|
+
# selected/decisions/budget),``assembled_input`` 是 AssembledInput 的 plain dict
|
|
77
|
+
memory_recall_events: list[dict[str, Any]] = field(default_factory=list)
|
|
78
|
+
# 平台 Memory Provider 的本轮召回结果。native runtime 由 Adapter 投影,
|
|
79
|
+
# framework/hosted 路径可继续通过 canonical payload 消费。
|
|
80
|
+
memory_context: dict[str, Any] | None = None
|
|
81
|
+
# (system + messages)。二者都进 trace 与 runner payload 接管;非门控为 None,零影响。
|
|
82
|
+
context_plan: dict[str, Any] | None = None
|
|
83
|
+
assembled_input: dict[str, Any] | None = None
|
|
84
|
+
# 可信 Principal,供平台 Memory 写入与召回使用。不能用 session_id 代替 user scope。
|
|
85
|
+
user_id: str = ""
|
|
86
|
+
agent_id: str = ""
|
|
87
|
+
# AgentVersion 级 Memory 写入灰度。None=旧环境策略;off/shadow=不写;enabled=写入。
|
|
88
|
+
memory_write_rollout: str | None = None
|
|
89
|
+
memory_enabled: bool | None = None
|
|
90
|
+
memory_recall_enabled: bool | None = None
|
|
91
|
+
memory_write_mode: str = "candidate"
|
|
92
|
+
flush_before_compaction: bool = True
|
|
93
|
+
provider_ref: str = "local-default"
|
|
58
94
|
|
|
59
95
|
|
|
60
96
|
@dataclass
|
|
@@ -76,6 +112,12 @@ class CompactionPlan:
|
|
|
76
112
|
compacted_until_seq_id: int | None = None
|
|
77
113
|
pinned_group_indexes: list[int] = field(default_factory=list)
|
|
78
114
|
pinned_state: dict[str, Any] = field(default_factory=dict)
|
|
115
|
+
# PR D1:双阈值(仅 ksadk_hosted 路径填充)。非门控路径为 None。
|
|
116
|
+
# trigger_band:"" / "none" / "soft" / "hard" / "emergency"。empty=非门控走旧单阈值;
|
|
117
|
+
# "emergency"=PTL force。soft/hard 用于 proactive 整理 vs 强制压缩区分。
|
|
118
|
+
soft_limit_tokens: int | None = None
|
|
119
|
+
hard_limit_tokens: int | None = None
|
|
120
|
+
trigger_band: str = ""
|
|
79
121
|
|
|
80
122
|
|
|
81
123
|
def build_responses_payload(
|