agentengine-sdk-python 0.8.0__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.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/METADATA +43 -7
- agentengine_sdk_python-0.8.2.dist-info/RECORD +778 -0
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/WHEEL +1 -1
- ksadk/a2a/__init__.py +2 -0
- ksadk/a2a/_space_client_events.py +381 -0
- ksadk/a2a/bootstrap.py +0 -2
- ksadk/a2a/card.py +6 -111
- ksadk/a2a/control_plane.py +239 -1
- ksadk/a2a/event_adapter.py +156 -64
- ksadk/a2a/executor.py +195 -172
- ksadk/a2a/routes.py +12 -5
- ksadk/a2a/server.py +1 -8
- ksadk/a2a/service_env.py +33 -0
- ksadk/a2a/space_client.py +43 -349
- ksadk/a2a_card.py +101 -0
- ksadk/a2ui/core.py +222 -53
- ksadk/agui/_agent_helpers.py +243 -0
- ksadk/agui/a2ui_projection.py +12 -5
- ksadk/agui/agent.py +474 -275
- ksadk/agui/config.py +11 -5
- ksadk/agui/routes.py +7 -15
- ksadk/api/client.py +530 -40
- ksadk/api/environment.py +27 -0
- ksadk/builders/code_builder.py +352 -53
- ksadk/builders/container_builder.py +71 -44
- ksadk/builders/framework_requirements.py +2 -1
- ksadk/builders/ks3_uploader.py +2 -2
- ksadk/builders/managed_runtime_builder.py +60 -28
- ksadk/cli/__init__.py +25 -0
- ksadk/cli/cmd_a2a.py +18 -31
- ksadk/cli/cmd_create.py +13 -26
- ksadk/cli/cmd_dashboard.py +15 -1
- ksadk/cli/cmd_deploy.py +28 -3
- ksadk/cli/cmd_eval.py +443 -0
- ksadk/cli/cmd_evalset.py +284 -0
- ksadk/cli/cmd_files.py +5 -1
- ksadk/cli/cmd_hermes.py +137 -163
- ksadk/cli/cmd_invoke.py +28 -38
- ksadk/cli/cmd_launch.py +12 -0
- ksadk/cli/cmd_managed_runtime.py +95 -0
- ksadk/cli/cmd_observe.py +85 -0
- ksadk/cli/cmd_openclaw.py +85 -479
- ksadk/cli/cmd_replay.py +28 -4
- ksadk/cli/cmd_run.py +29 -67
- ksadk/cli/cmd_studio.py +201 -0
- ksadk/cli/cmd_web.py +15 -6
- ksadk/cli/dry_run.py +2 -1
- ksadk/cli/env_options.py +83 -0
- ksadk/cli/global_options.py +3 -1
- ksadk/cli/hermes_env.py +151 -0
- ksadk/cli/invoke_payload.py +49 -0
- ksadk/cli/network_options.py +7 -5
- ksadk/cli/openclaw_env.py +458 -0
- ksadk/cli/runtime_bootstrap.py +51 -0
- ksadk/cli/ui.py +6 -0
- ksadk/cli/workflow_common.py +5 -5
- ksadk/codex/__init__.py +3 -3
- ksadk/codex/client.py +833 -49
- ksadk/codex/phase.py +1 -1
- ksadk/codex/runtime.py +720 -127
- ksadk/common/kop_client.py +232 -0
- ksadk/configs/__init__.py +1 -3
- ksadk/configs/env_registry.py +244 -45
- ksadk/configs/env_registry_pcm.py +181 -0
- ksadk/configs/env_var_spec.py +18 -0
- ksadk/configs/global_config.py +6 -1
- ksadk/configs/settings.py +5 -108
- 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/__init__.py +85 -94
- 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 +193 -3
- ksadk/conversations/runtime_invocation.py +81 -3
- ksadk/conversations/runtime_observability.py +157 -4
- ksadk/conversations/runtime_payloads.py +42 -0
- ksadk/conversations/runtime_preparation.py +280 -2
- ksadk/conversations/runtime_resume.py +71 -32
- ksadk/conversations/runtime_stream_events.py +94 -9
- ksadk/conversations/runtime_streaming.py +175 -22
- 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 +38 -0
- ksadk/deployment/manager.py +24 -8
- ksadk/deployment/providers/serverless.py +228 -92
- ksadk/evaluation/__init__.py +116 -0
- ksadk/evaluation/a2a_adapter.py +452 -0
- ksadk/evaluation/adapters.py +67 -0
- 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 +478 -0
- ksadk/evaluation/evalset.py +351 -0
- ksadk/evaluation/evaluators.py +627 -0
- ksadk/evaluation/evidence.py +258 -0
- ksadk/evaluation/executor.py +143 -0
- ksadk/evaluation/local_adapter.py +550 -0
- ksadk/evaluation/service_env.py +27 -0
- ksadk/evaluation/storage.py +68 -0
- ksadk/evaluation/studio_build_adapter.py +253 -0
- ksadk/evaluation/target.py +82 -0
- 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 -256
- ksadk/events/session_event.py +324 -0
- ksadk/events/store.py +3 -316
- ksadk/events/v1_compat.py +41 -0
- ksadk/harness/__init__.py +3 -2
- ksadk/harness/app.py +114 -123
- ksadk/harness/config.py +1 -1
- ksadk/harness/runtime.py +467 -0
- ksadk/hermes_terminal.py +5 -0
- 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 +22 -4
- ksadk/knowledge_base/service.py +32 -5
- ksadk/managed_a2a_card.py +160 -0
- ksadk/managed_runtime.py +16 -9
- 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 +394 -5
- ksadk/memory/adk/backends/sqlite_ltm_backend.py +95 -0
- ksadk/memory/adk/long_term_memory.py +3 -2
- 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 +198 -8
- ksadk/memory/tool.py +4 -0
- ksadk/model_proxy/bootstrap.py +16 -9
- ksadk/model_proxy/config.py +22 -1
- ksadk/model_proxy/detect.py +202 -9
- ksadk/model_proxy/namespace.py +67 -15
- ksadk/model_proxy/server.py +168 -6
- ksadk/model_proxy/transform.py +105 -3
- 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 +14 -31
- ksadk/runners/base_runner.py +44 -3
- ksadk/runners/factory.py +3 -3
- ksadk/runners/langgraph_runner.py +252 -433
- ksadk/runners/utils/__init__.py +0 -10
- ksadk/runners/utils/loader.py +16 -0
- ksadk/runtime/__init__.py +67 -41
- ksadk/runtime/_runner_adapter/__init__.py +1 -0
- ksadk/runtime/_runner_adapter/stream_mapping.py +788 -0
- ksadk/runtime/adapter.py +199 -16
- ksadk/runtime/conversation_execution.py +687 -0
- ksadk/runtime/executor.py +392 -0
- ksadk/runtime/factory.py +342 -0
- ksadk/runtime/framework_adapters.py +6 -12
- ksadk/runtime/hosted_finalizer.py +268 -0
- ksadk/runtime/launch.py +61 -0
- ksadk/runtime/preprocessing.py +49 -14
- ksadk/runtime/runner_adapter.py +330 -391
- ksadk/runtime/runner_loading.py +36 -0
- ksadk/runtime/usage.py +33 -0
- ksadk/sandbox/backends/e2b.py +36 -3
- ksadk/server/__init__.py +39 -4
- ksadk/server/app.py +18 -492
- ksadk/server/composition.py +36 -2
- ksadk/server/factory.py +210 -149
- ksadk/server/routes/common.py +15 -46
- ksadk/server/routes/control.py +13 -9
- ksadk/server/routes/kernel_ingress.py +258 -0
- ksadk/server/routes/misc.py +10 -33
- ksadk/server/routes/models.py +14 -6
- ksadk/server/routes/openai_compat.py +129 -27
- ksadk/server/routes/projection.py +84 -16
- ksadk/server/routes/run.py +347 -460
- ksadk/server/routes/sessions.py +37 -40
- ksadk/server/routes/streaming.py +52 -7
- ksadk/server/routes/workspace.py +54 -21
- ksadk/server/static/assets/{ArtifactsPanel-Cjnqt-8W.js → ArtifactsPanel-DSU1sWD_.js} +1 -1
- ksadk/server/static/assets/{CodeBlock-BqyqZfuB.js → CodeBlock-DOH6MVcn.js} +4 -4
- ksadk/server/static/assets/{MathMessageMarkdown-BpH7jiFM.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-BGhvzDYt.js → chunk-5VM5RSS4-BVHAchFb.js} +1 -1
- ksadk/server/static/assets/{chunk-ND2GUHAM-D98vPd-E.js → chunk-F27PBJKO-C-ipQzuS.js} +1 -1
- ksadk/server/static/assets/chunk-G27WJ6UU-C2EyJbIK.js +231 -0
- ksadk/server/static/assets/{chunk-4BX2VUAB-CsWIQRhc.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-CX3yotHq.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-D82mtD2s.js → dist-8hqcx0sU.js} +1 -1
- ksadk/server/static/assets/dist-B7seoj3d.js +1 -0
- ksadk/server/static/assets/{dist-DHn6nBzr.js → dist-BE7bu-DL.js} +1 -1
- ksadk/server/static/assets/{dist-eoW6tZXA.js → dist-BVDffZ0U.js} +1 -1
- ksadk/server/static/assets/{dist-C2xjE7cO.js → dist-BX8z72IC.js} +1 -1
- ksadk/server/static/assets/{dist-CgF3fj15.js → dist-Bf2M8m3N.js} +1 -1
- ksadk/server/static/assets/{dist-Bs-jQcRX.js → dist-BjU6y-A2.js} +1 -1
- ksadk/server/static/assets/{dist-Djgl2wVZ.js → dist-BytlxIDT.js} +1 -1
- ksadk/server/static/assets/{dist-CVQRZjPu.js → dist-CSh_DE14.js} +1 -1
- ksadk/server/static/assets/{dist-6CVKuTAe.js → dist-CXYYBw3_.js} +1 -1
- ksadk/server/static/assets/{dist-DlzCRy0S.js → dist-C_wsv-Qd.js} +1 -1
- ksadk/server/static/assets/{dist-DF06ORQo.js → dist-ClxGviKw.js} +1 -1
- ksadk/server/static/assets/{dist-Cf23NY4L.js → dist-CttYUqzS.js} +1 -1
- ksadk/server/static/assets/{dist-ivOya1LD.js → dist-DNp6rLRA.js} +1 -1
- ksadk/server/static/assets/{dist-BibcG1V9.js → dist-DUX-id_F.js} +1 -1
- ksadk/server/static/assets/{dist-BUHRxvDG.js → dist-DmldrHd_.js} +1 -1
- ksadk/server/static/assets/{dist-BZ9n9AjO.js → dist-DnfXs8Vn.js} +2 -2
- ksadk/server/static/assets/{dist-DqNnNFrw.js → dist-Dq9gLD7L.js} +1 -1
- ksadk/server/static/assets/{dist-CGcp2ex8.js → dist-W-TIVntx.js} +1 -1
- ksadk/server/static/assets/{dist-Cwt7koer.js → dist-dDdADKFA.js} +1 -1
- ksadk/server/static/assets/{dist-C7-3jInC.js → dist-dydu68Fl.js} +1 -1
- ksadk/server/static/assets/{dist-C99THtIA.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-DLOHGvWw.js → ishikawaDiagram-5VMMS53U-DWya9SG2.js} +6 -6
- ksadk/server/static/assets/{journeyDiagram-JHISSGLW-BIzKeejT.js → journeyDiagram-EYS64GPL-DutxhSNI.js} +6 -6
- ksadk/server/static/assets/{kanban-definition-UN3LZRKU-BWHoFSw2.js → kanban-definition-3QL26DDD-DJdOF8Fm.js} +10 -10
- ksadk/server/static/assets/katex-vFWytM5c.js +257 -0
- ksadk/server/static/assets/{linear-CvMBw9cA.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-CSAQxEAe.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-CxIR4JXI.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-DpGa6EAV.js → sankeyDiagram-P5KCCOFB-CPH75rhw.js} +7 -7
- ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-NTKNGGe5.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-jqoYs3jQ.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/skills/runtime/backends/e2b.py +1 -1
- ksadk/skills/service_client.py +13 -3
- ksadk/studio/__init__.py +5 -0
- ksadk/studio/agent_avatar_assets.py +120 -0
- ksadk/studio/agent_lifecycle.py +51 -0
- ksadk/studio/api.py +1598 -0
- ksadk/studio/api_catalog_routes.py +324 -0
- ksadk/studio/api_contracts.py +286 -0
- ksadk/studio/api_helpers.py +132 -0
- ksadk/studio/api_memory_routes.py +82 -0
- ksadk/studio/authoring.py +749 -0
- ksadk/studio/authoring_coordinator.py +1017 -0
- ksadk/studio/builder.py +397 -0
- ksadk/studio/capabilities.py +368 -0
- ksadk/studio/cloud.py +2099 -0
- ksadk/studio/codex_agent_service.py +694 -0
- ksadk/studio/codex_authoring.py +469 -0
- ksadk/studio/codex_builder.py +437 -0
- ksadk/studio/codex_manifest.py +307 -0
- ksadk/studio/codex_run.py +395 -0
- ksadk/studio/compiler.py +190 -0
- ksadk/studio/contracts.py +755 -0
- ksadk/studio/errors.py +47 -0
- ksadk/studio/event_store.py +214 -0
- ksadk/studio/framework_run.py +342 -0
- ksadk/studio/hosted_kernel.py +317 -0
- ksadk/studio/identifiers.py +33 -0
- ksadk/studio/manifest_resolver.py +131 -0
- ksadk/studio/mcp_runtime.py +229 -0
- ksadk/studio/model_client.py +629 -0
- ksadk/studio/model_profile_service.py +214 -0
- ksadk/studio/operations.py +275 -0
- ksadk/studio/otel_trace.py +1060 -0
- ksadk/studio/pagination.py +182 -0
- ksadk/studio/pcm_memory.py +85 -0
- ksadk/studio/python_tool_inspection.py +183 -0
- ksadk/studio/repository.py +327 -0
- ksadk/studio/resource_catalog.py +1260 -0
- ksadk/studio/run_service.py +1133 -0
- ksadk/studio/runtime_catalog.py +74 -0
- ksadk/studio/runtime_source.py +365 -0
- ksadk/studio/service.py +2249 -0
- ksadk/studio/shared_web.py +1004 -0
- ksadk/studio/skill_discovery.py +628 -0
- ksadk/studio/static/assets/PrismRenderer-IYN-ffww.js +3 -0
- ksadk/studio/static/assets/index-BLpcdrgW.css +1 -0
- ksadk/studio/static/assets/index-CYekR2Xv.js +260 -0
- ksadk/studio/static/assets/react-vendor-BNmTiJ-I.js +9 -0
- ksadk/studio/static/assets/rolldown-runtime-hePW80VL.js +1 -0
- ksadk/studio/static/index.html +15 -0
- ksadk/studio/templates.py +722 -0
- ksadk/studio/validator.py +265 -0
- ksadk/studio/workspace.py +135 -0
- ksadk/tools/gateway.py +9 -0
- ksadk/toolsets/__init__.py +27 -1
- ksadk/toolsets/a2a.py +426 -0
- ksadk/tracing/__init__.py +19 -21
- ksadk/tracing/setup.py +317 -403
- ksadk/tracing/span_utils.py +0 -44
- ksadk/version.py +1 -1
- ksadk_runtime_common/memory_backend/registry.py +56 -56
- ksadk_runtime_common/schemas/runtime_event_v1.json +37 -0
- ksadk_runtime_common/schemas/runtime_event_v2.json +271 -0
- ksadk_runtime_common/workspace_files/router.py +8 -2
- agentengine_sdk_python-0.8.0.dist-info/RECORD +0 -578
- ksadk/a2a/card_builder.py +0 -64
- ksadk/a2a/client.py +0 -309
- ksadk/events/parser.py +0 -191
- ksadk/harness/runner.py +0 -211
- ksadk/runners/codex_runner.py +0 -132
- ksadk/runners/utils/langfuse.py +0 -230
- ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +0 -1
- ksadk/server/static/assets/MermaidBlock-DWuxETaJ.js +0 -303
- ksadk/server/static/assets/NativeTerminalPanel-MDTopWMO.js +0 -1
- ksadk/server/static/assets/arc-CFKwSk_B.js +0 -1
- ksadk/server/static/assets/architecture-7EHR7CIX-CynqOWjZ.js +0 -1
- ksadk/server/static/assets/architectureDiagram-3BPJPVTR-Dej8jX8c.js +0 -36
- ksadk/server/static/assets/blockDiagram-GPEHLZMM-1F64jqvy.js +0 -132
- ksadk/server/static/assets/c4Diagram-AAUBKEIU-9q7AUAKb.js +0 -10
- ksadk/server/static/assets/channel-iUGv2N24.js +0 -1
- ksadk/server/static/assets/chunk-2J33WTMH-6qgwJm7Q.js +0 -1
- ksadk/server/static/assets/chunk-55IACEB6-BK8paA20.js +0 -1
- ksadk/server/static/assets/chunk-727SXJPM-B-JEhy7h.js +0 -206
- ksadk/server/static/assets/chunk-AQP2D5EJ-DYBvMHAa.js +0 -231
- ksadk/server/static/assets/chunk-QZHKN3VN-YQIEXeF6.js +0 -1
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-CDAUuoXK.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-CDAUuoXK.js +0 -1
- ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +0 -321
- ksadk/server/static/assets/dagre-BM42HDAG-C7TguAWo.js +0 -4
- ksadk/server/static/assets/dagre-Bx709z4p.js +0 -1
- ksadk/server/static/assets/diagram-2AECGRRQ-Dd17_kws.js +0 -43
- ksadk/server/static/assets/diagram-5GNKFQAL-DVIClIil.js +0 -10
- ksadk/server/static/assets/diagram-KO2AKTUF-Df_3gYQa.js +0 -3
- ksadk/server/static/assets/diagram-LMA3HP47-BhLk6ZtA.js +0 -24
- ksadk/server/static/assets/diagram-OG6HWLK6-D4GNGvuu.js +0 -24
- ksadk/server/static/assets/dist-DyvYLMW9.js +0 -1
- ksadk/server/static/assets/erDiagram-TEJ5UH35-CnfRcY2M.js +0 -85
- ksadk/server/static/assets/eventmodeling-FCH6USID-ChYO-ijM.js +0 -1
- ksadk/server/static/assets/flowDiagram-I6XJVG4X-DGaJjGNJ.js +0 -162
- ksadk/server/static/assets/ganttDiagram-6RSMTGT7-DpCoB2g9.js +0 -292
- ksadk/server/static/assets/gitGraph-WXDBUCRP-BN_0Fk-j.js +0 -1
- ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-9IKVFBVT.js +0 -106
- ksadk/server/static/assets/graphlib-B8gBHxth.js +0 -1
- ksadk/server/static/assets/index-QSwCHuB8.js +0 -177
- ksadk/server/static/assets/index-jOPmTOZH.css +0 -2
- ksadk/server/static/assets/info-J43DQDTF-Cp6o3vId.js +0 -1
- ksadk/server/static/assets/infoDiagram-5YYISTIA-CYIIsb8y.js +0 -2
- ksadk/server/static/assets/katex-DATssjp1.js +0 -265
- ksadk/server/static/assets/mermaid-parser.core-mGAcEwcq.js +0 -161
- ksadk/server/static/assets/packet-YPE3B663-wQzct3cT.js +0 -1
- ksadk/server/static/assets/pie-LRSECV5Y-BgTQiv-9.js +0 -1
- ksadk/server/static/assets/pieDiagram-4H26LBE5-By-ra07M.js +0 -30
- ksadk/server/static/assets/radar-GUYGQ44K-BIq5fXsn.js +0 -1
- ksadk/server/static/assets/requirementDiagram-4Y6WPE33-DpW90iu3.js +0 -84
- ksadk/server/static/assets/stateDiagram-AJRCARHV-DGpd9yFG.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-B3o579IQ.js +0 -1
- ksadk/server/static/assets/treeView-BLDUP644-Dqi-E0EM.js +0 -1
- ksadk/server/static/assets/treemap-LRROVOQU-ClQP9CJ9.js +0 -1
- ksadk/server/static/assets/vennDiagram-CIIHVFJN-l3Z7-wbP.js +0 -34
- ksadk/server/static/assets/wardley-L42UT6IY-8XLvnNIs.js +0 -1
- ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-BR54GPmr.js +0 -78
- ksadk/server/static/assets/xychartDiagram-2RQKCTM6-SkiH8GsK.js +0 -7
- ksadk/tracing/exporters/langfuse_exporter.py +0 -460
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"""Hosted Pipeline —— 把已建模块接成 ksadk_hosted 真实链路(方案 §11.1 / §4.4)。
|
|
2
|
+
|
|
3
|
+
这是把 Prompt Compiler → Contributors → Context Planner → Context Assembler 串成一条
|
|
4
|
+
真实链路的编排器:从 ``PreparedConversationTurn`` 取已编译的 CompiledPrompt、history、
|
|
5
|
+
user_input、working_state,运行 Contributors 产出候选 ContextItem,交给 ContextPlanner 做预算
|
|
6
|
+
决策,再由 ContextAssembler 投影成最终 Chat 输入。返回 ``(ContextPlan, AssembledInput)``。
|
|
7
|
+
|
|
8
|
+
**门控**:AgentVersion ``context.rollout.contextEngine=enabled`` 开启,环境变量
|
|
9
|
+
``KSADK_CONTEXT_ENGINE_V2_ENABLED=false`` 可作为全局紧急关闭。只有
|
|
10
|
+
``prompt_integration_mode=="ksadk_hosted"`` 才由 ``build_run_input`` 调用。本模块纯计算 + 受控
|
|
11
|
+
Contributor 调用,不接触 Session Store、不调模型;replan 由调用方在 compaction/PTL 后重新调用
|
|
12
|
+
(ADR-016:每 Turn 只生成一份 canonical Plan)。
|
|
13
|
+
|
|
14
|
+
assisted/native 路径不调用本模块(方案 §6.2):framework_assisted 由 Adapter 投影,native_runtime
|
|
15
|
+
保留原生 history/compaction,KsADK 不重复注入完整 Transcript、不运行第二套 compaction。
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
from dataclasses import dataclass
|
|
22
|
+
from typing import Any, Mapping
|
|
23
|
+
|
|
24
|
+
from ksadk.context_engine.assembler import AssembledInput, ContextAssembler
|
|
25
|
+
from ksadk.context_engine.contributors import (
|
|
26
|
+
ContextContributionRequest,
|
|
27
|
+
ContextContributor,
|
|
28
|
+
ContributionResult,
|
|
29
|
+
MemoryRecallContributor,
|
|
30
|
+
WorkspaceRulesContributor,
|
|
31
|
+
run_contributors,
|
|
32
|
+
)
|
|
33
|
+
from ksadk.context_engine.models import ContextItem
|
|
34
|
+
from ksadk.context_engine.planner import ContextPlanner, build_budget
|
|
35
|
+
from ksadk.context_engine.policies import ContextPolicy
|
|
36
|
+
from ksadk.context_engine.tokenizer import get_default_token_counter
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def hosted_pipeline_enabled(*, rollout: str | None = None) -> bool:
|
|
40
|
+
"""解析全局 kill switch 与 AgentVersion 级 Context rollout。
|
|
41
|
+
|
|
42
|
+
传入 rollout 时,``enabled`` 开启真实链路,``off``/``shadow`` 不改变 Runner
|
|
43
|
+
输入。环境变量仍是最高优先级的紧急开关:显式 false 一律关闭;旧调用未传
|
|
44
|
+
rollout 时则保持原语义,只有环境变量显式 true 才开启。
|
|
45
|
+
"""
|
|
46
|
+
raw = os.environ.get("KSADK_CONTEXT_ENGINE_V2_ENABLED")
|
|
47
|
+
normalized = str(raw or "").strip().lower()
|
|
48
|
+
if normalized in {"0", "false", "no", "off"}:
|
|
49
|
+
return False
|
|
50
|
+
env_enabled = normalized in {"1", "true", "yes", "on"}
|
|
51
|
+
if rollout is not None:
|
|
52
|
+
return str(rollout).strip().lower() == "enabled" and (raw is None or env_enabled)
|
|
53
|
+
return env_enabled
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _env_flag(name: str, default: bool = True) -> bool:
|
|
57
|
+
raw = os.getenv(name)
|
|
58
|
+
if raw is None:
|
|
59
|
+
return default
|
|
60
|
+
return str(raw).strip().lower() not in {"0", "false", "no", "off"}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass(frozen=True)
|
|
64
|
+
class HostedPipelineResult:
|
|
65
|
+
"""hosted pipeline 的产物。``plan`` 为 plain dict 投影,``assembled`` 为 AssembledInput。"""
|
|
66
|
+
|
|
67
|
+
plan: dict[str, Any]
|
|
68
|
+
assembled: AssembledInput
|
|
69
|
+
contributor_status: dict[str, str]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _history_to_items(history: list[dict[str, str]]) -> list[ContextItem]:
|
|
73
|
+
"""把投影后的 history rounds 转成 ContextItem。
|
|
74
|
+
|
|
75
|
+
user+assistant 绑定为同一原子组(方案 §8.1 group_id),避免长 User 被跳过而
|
|
76
|
+
短 Assistant 留下成为孤儿历史。
|
|
77
|
+
"""
|
|
78
|
+
counter = get_default_token_counter()
|
|
79
|
+
items: list[ContextItem] = []
|
|
80
|
+
round_index = 0
|
|
81
|
+
for index, turn in enumerate(history):
|
|
82
|
+
if not isinstance(turn, Mapping):
|
|
83
|
+
continue
|
|
84
|
+
role = str(turn.get("role") or turn.get("author") or "assistant")
|
|
85
|
+
content = turn.get("content") or turn.get("text") or ""
|
|
86
|
+
if not content:
|
|
87
|
+
continue
|
|
88
|
+
text = content if isinstance(content, str) else str(content)
|
|
89
|
+
# user 开启新 round;assistant 继承上一个 round(与 user 同组)
|
|
90
|
+
if role == "user":
|
|
91
|
+
round_index += 1
|
|
92
|
+
items.append(
|
|
93
|
+
ContextItem(
|
|
94
|
+
item_id=f"hist:{index}",
|
|
95
|
+
kind="history_round",
|
|
96
|
+
content=text,
|
|
97
|
+
source="transcript",
|
|
98
|
+
trust_level="developer",
|
|
99
|
+
priority=0,
|
|
100
|
+
estimated_tokens=counter.count_text(text),
|
|
101
|
+
required=False,
|
|
102
|
+
droppable=True,
|
|
103
|
+
group_id=f"round:{round_index}",
|
|
104
|
+
seq_start=index,
|
|
105
|
+
metadata={
|
|
106
|
+
"role": role if role in ("user", "assistant", "model") else "assistant",
|
|
107
|
+
},
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
return items
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _working_state_to_item(working_state: Mapping[str, Any] | None) -> ContextItem | None:
|
|
114
|
+
"""把 WorkingState 审计 dict 转成 ContextItem(方案 §9.3 重注入)。"""
|
|
115
|
+
if not isinstance(working_state, Mapping) or not working_state:
|
|
116
|
+
return None
|
|
117
|
+
# 复用 runtime_input 的渲染,保证 XML 格式与重注入一致。
|
|
118
|
+
try:
|
|
119
|
+
from ksadk.conversations.runtime_input import _render_working_state_xml
|
|
120
|
+
|
|
121
|
+
xml = _render_working_state_xml(working_state)
|
|
122
|
+
except Exception: # noqa: BLE001
|
|
123
|
+
return None
|
|
124
|
+
if not xml:
|
|
125
|
+
return None
|
|
126
|
+
counter = get_default_token_counter()
|
|
127
|
+
return ContextItem(
|
|
128
|
+
item_id="working_state",
|
|
129
|
+
kind="working_state",
|
|
130
|
+
content=xml,
|
|
131
|
+
source="checkpoint",
|
|
132
|
+
trust_level="developer",
|
|
133
|
+
priority=0,
|
|
134
|
+
estimated_tokens=counter.count_text(xml),
|
|
135
|
+
required=False, # WorkingState 高优先级但非强制 required(可被降级,方案 §8.4 第 7)
|
|
136
|
+
droppable=True,
|
|
137
|
+
stable=False,
|
|
138
|
+
metadata={"content_hash": working_state.get("content_hash")},
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _compiled_prompt_to_item(compiled_prompt: Mapping[str, Any] | None) -> ContextItem | None:
|
|
143
|
+
"""把真实 CompiledPrompt dict(含 prompt_content)转成 required ContextItem。"""
|
|
144
|
+
if not isinstance(compiled_prompt, Mapping):
|
|
145
|
+
return None
|
|
146
|
+
content = compiled_prompt.get("prompt_content")
|
|
147
|
+
if not isinstance(content, str) or not content.strip():
|
|
148
|
+
return None
|
|
149
|
+
counter = get_default_token_counter()
|
|
150
|
+
return ContextItem(
|
|
151
|
+
item_id="compiled_prompt",
|
|
152
|
+
kind="compiled_prompt",
|
|
153
|
+
content=content,
|
|
154
|
+
source="prompt_compiler",
|
|
155
|
+
trust_level="platform", # compiled_prompt 含 platform_safety(若编译含)
|
|
156
|
+
priority=0,
|
|
157
|
+
estimated_tokens=int(
|
|
158
|
+
compiled_prompt.get("prompt_estimated_tokens") or counter.count_text(content)
|
|
159
|
+
),
|
|
160
|
+
required=True,
|
|
161
|
+
droppable=False,
|
|
162
|
+
stable=True,
|
|
163
|
+
content_hash=compiled_prompt.get("prompt_content_hash"),
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _current_input_to_item(user_input: str) -> ContextItem | None:
|
|
168
|
+
text = str(user_input or "").strip()
|
|
169
|
+
if not text:
|
|
170
|
+
return None
|
|
171
|
+
counter = get_default_token_counter()
|
|
172
|
+
return ContextItem(
|
|
173
|
+
item_id="current_input",
|
|
174
|
+
kind="current_input",
|
|
175
|
+
content=text,
|
|
176
|
+
source="user",
|
|
177
|
+
trust_level="user",
|
|
178
|
+
priority=0,
|
|
179
|
+
estimated_tokens=counter.count_text(text),
|
|
180
|
+
required=True,
|
|
181
|
+
droppable=False,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def default_hosted_contributors(
|
|
186
|
+
*,
|
|
187
|
+
policy: ContextPolicy | None = None,
|
|
188
|
+
user_id: str = "",
|
|
189
|
+
agent_id: str = "",
|
|
190
|
+
memory_provider: Any = None,
|
|
191
|
+
memory_recall_enabled: bool | None = None,
|
|
192
|
+
) -> list[ContextContributor]:
|
|
193
|
+
"""构造默认 hosted Contributors(方案 §8.7 首批内置)。
|
|
194
|
+
|
|
195
|
+
- ``MemoryRecallContributor``:仅当 ``KSADK_MEMORY_ENABLED`` 且有可用 Provider 时启用。
|
|
196
|
+
- ``WorkspaceRulesContributor``:受 ``KSADK_PROMPT_AUTO_DISCOVERY`` 门控(默认关)。
|
|
197
|
+
SkillManifest/Attachment Contributor 需要外部 manifests/附件,留调用方按需注入。
|
|
198
|
+
|
|
199
|
+
返回的 Contributor 一律 trust_level 不高于注册配置(external = untrusted),Planner 拥有
|
|
200
|
+
是否进入请求的最终决策。
|
|
201
|
+
"""
|
|
202
|
+
pol = policy or ContextPolicy.from_env()
|
|
203
|
+
contributors: list[ContextContributor] = []
|
|
204
|
+
memory_enabled = pol.memory.enabled
|
|
205
|
+
if memory_recall_enabled is not None:
|
|
206
|
+
memory_enabled = bool(memory_recall_enabled)
|
|
207
|
+
# 环境级 false 保留为生产紧急 kill switch。
|
|
208
|
+
if os.environ.get("KSADK_MEMORY_ENABLED", "").strip().lower() in {
|
|
209
|
+
"0",
|
|
210
|
+
"false",
|
|
211
|
+
"off",
|
|
212
|
+
}:
|
|
213
|
+
memory_enabled = False
|
|
214
|
+
if memory_enabled:
|
|
215
|
+
try:
|
|
216
|
+
from ksadk.memory.coordinator import MemoryCoordinator
|
|
217
|
+
|
|
218
|
+
if memory_provider is None:
|
|
219
|
+
from ksadk.memory.providers.local_sqlite import resolve_default_memory_provider
|
|
220
|
+
|
|
221
|
+
memory_provider = resolve_default_memory_provider()
|
|
222
|
+
coordinator = MemoryCoordinator(
|
|
223
|
+
memory_provider,
|
|
224
|
+
tenant_id="local",
|
|
225
|
+
workspace_id="local",
|
|
226
|
+
)
|
|
227
|
+
contributors.append(
|
|
228
|
+
MemoryRecallContributor(
|
|
229
|
+
coordinator,
|
|
230
|
+
max_tokens=pol.memory.recall_max_tokens,
|
|
231
|
+
top_k=pol.memory.recall_top_k,
|
|
232
|
+
min_score=pol.memory.min_score,
|
|
233
|
+
)
|
|
234
|
+
)
|
|
235
|
+
except Exception: # noqa: BLE001 — Provider 构造失败不应阻断 hosted 链路
|
|
236
|
+
pass
|
|
237
|
+
if pol.prompt.auto_discovery:
|
|
238
|
+
try:
|
|
239
|
+
contributors.append(
|
|
240
|
+
WorkspaceRulesContributor(
|
|
241
|
+
max_tokens=pol.prompt.rule_files_max_tokens,
|
|
242
|
+
)
|
|
243
|
+
)
|
|
244
|
+
except Exception: # noqa: BLE001
|
|
245
|
+
pass
|
|
246
|
+
return contributors
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
async def run_hosted_pipeline(
|
|
250
|
+
*,
|
|
251
|
+
compiled_prompt: Mapping[str, Any] | None,
|
|
252
|
+
user_input: str,
|
|
253
|
+
history: list[dict[str, str]],
|
|
254
|
+
working_state: Mapping[str, Any] | None,
|
|
255
|
+
model_metadata: Mapping[str, Any] | None,
|
|
256
|
+
contributors: list[ContextContributor] | None = None,
|
|
257
|
+
policy: ContextPolicy | None = None,
|
|
258
|
+
integration_mode: str = "ksadk_hosted",
|
|
259
|
+
accounting_accuracy: str = "estimated",
|
|
260
|
+
session_id: str = "",
|
|
261
|
+
invocation_id: str = "",
|
|
262
|
+
user_id: str = "",
|
|
263
|
+
agent_id: str = "",
|
|
264
|
+
agent_max_input_tokens: int | None = None,
|
|
265
|
+
agent_reserve_output_tokens: int | None = None,
|
|
266
|
+
) -> HostedPipelineResult | None:
|
|
267
|
+
"""运行真实 hosted 链路(方案 §11.1 细化时序 1-10)。
|
|
268
|
+
|
|
269
|
+
``agent_max_input_tokens``/``agent_reserve_output_tokens``:AgentVersion 的 ContextSpec
|
|
270
|
+
预算覆盖(方案 §8.2)。非 None 时优先于 model_metadata 的窗口(解决 AgentVersion 预算
|
|
271
|
+
没传到 Planner 的问题)。返回 ``None`` 表示无可组装内容。
|
|
272
|
+
"""
|
|
273
|
+
pol = policy or ContextPolicy.from_env()
|
|
274
|
+
counter = get_default_token_counter()
|
|
275
|
+
|
|
276
|
+
# 1. 基础候选:compiled_prompt(required) + current_input(required) + history rounds + working_state # noqa: E501
|
|
277
|
+
candidates: list[ContextItem] = []
|
|
278
|
+
prompt_item = _compiled_prompt_to_item(compiled_prompt)
|
|
279
|
+
if prompt_item is not None:
|
|
280
|
+
candidates.append(prompt_item)
|
|
281
|
+
input_item = _current_input_to_item(user_input)
|
|
282
|
+
if input_item is not None:
|
|
283
|
+
candidates.append(input_item)
|
|
284
|
+
candidates.extend(_history_to_items(history))
|
|
285
|
+
ws_item = _working_state_to_item(working_state)
|
|
286
|
+
if ws_item is not None:
|
|
287
|
+
candidates.append(ws_item)
|
|
288
|
+
|
|
289
|
+
# 2. 运行 Contributors(Memory Recall 等)产出 untrusted 候选(方案 §8.7)
|
|
290
|
+
contrib_status: dict[str, str] = {}
|
|
291
|
+
if contributors:
|
|
292
|
+
request = ContextContributionRequest(
|
|
293
|
+
user_input=user_input,
|
|
294
|
+
session_id=session_id,
|
|
295
|
+
invocation_id=invocation_id,
|
|
296
|
+
user_id=user_id,
|
|
297
|
+
agent_id=agent_id,
|
|
298
|
+
)
|
|
299
|
+
result: ContributionResult = await run_contributors(
|
|
300
|
+
contributors,
|
|
301
|
+
request,
|
|
302
|
+
default_timeout_ms=pol.contributors.default_timeout_ms,
|
|
303
|
+
default_failure_mode=pol.contributors.default_failure_mode,
|
|
304
|
+
)
|
|
305
|
+
contrib_status = dict(result.status)
|
|
306
|
+
candidates.extend(result.items)
|
|
307
|
+
|
|
308
|
+
if not any(i.kind == "compiled_prompt" for i in candidates) and not input_item:
|
|
309
|
+
return None
|
|
310
|
+
|
|
311
|
+
# 3. 构造预算(方案 §8.2)。优先用 AgentVersion 的 ContextSpec 预算
|
|
312
|
+
# (agent_max_input_tokens),缺失时 fallback 到 model_metadata。
|
|
313
|
+
if agent_max_input_tokens is not None and agent_max_input_tokens > 0:
|
|
314
|
+
# AgentVersion 预算:max_input_tokens 直接作为 context_window,reserve 从 spec 取。
|
|
315
|
+
# 不扣 safety_buffer(AgentVersion 已显式指定预算,8000 默认 buffer 是为百万
|
|
316
|
+
# token 窗口设计的,在小预算下会导致 max_input=0)。
|
|
317
|
+
from dataclasses import replace
|
|
318
|
+
|
|
319
|
+
reserve_out = agent_reserve_output_tokens or 0
|
|
320
|
+
agent_policy = replace(pol.budget, safety_buffer_tokens=0)
|
|
321
|
+
budget = build_budget(
|
|
322
|
+
policy=agent_policy,
|
|
323
|
+
context_window_tokens=agent_max_input_tokens + reserve_out,
|
|
324
|
+
reserved_output_tokens=reserve_out,
|
|
325
|
+
reserved_reasoning_tokens=0,
|
|
326
|
+
)
|
|
327
|
+
else:
|
|
328
|
+
from ksadk.conversations.model_context import (
|
|
329
|
+
get_effective_context_window_tokens,
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
max_input = get_effective_context_window_tokens(model_metadata)
|
|
333
|
+
budget = build_budget(
|
|
334
|
+
policy=pol.budget,
|
|
335
|
+
context_window_tokens=max_input + pol.budget.safety_buffer_tokens,
|
|
336
|
+
reserved_output_tokens=0,
|
|
337
|
+
reserved_reasoning_tokens=0,
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
# 4. Planner 决策(方案 §8.4)
|
|
341
|
+
planner = ContextPlanner(policy=pol.budget)
|
|
342
|
+
plan = planner.plan(
|
|
343
|
+
candidates,
|
|
344
|
+
budget=budget,
|
|
345
|
+
integration_mode=integration_mode,
|
|
346
|
+
accounting_accuracy=accounting_accuracy,
|
|
347
|
+
tokenizer=counter.name,
|
|
348
|
+
stable_prefix_hash=str((compiled_prompt or {}).get("prompt_stable_prefix_hash") or ""),
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
# 5. Assembler 投影成 Chat 输入(方案 §8)
|
|
352
|
+
assembled = ContextAssembler().assemble_chat(plan)
|
|
353
|
+
plan_dict = _plan_to_dict(plan)
|
|
354
|
+
# hosted 模式由 KsADK 拥有最终 Runner payload,因此 assembler 的 token 结果就是
|
|
355
|
+
# projected 口径;actual 仍只接受 Runtime/Provider usage 回填。
|
|
356
|
+
plan_dict["projected_input_tokens"] = assembled.estimated_tokens
|
|
357
|
+
|
|
358
|
+
return HostedPipelineResult(
|
|
359
|
+
plan=plan_dict,
|
|
360
|
+
assembled=assembled,
|
|
361
|
+
contributor_status=contrib_status,
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _plan_to_dict(plan: Any) -> dict[str, Any]:
|
|
366
|
+
"""ContextPlan → plain dict 投影(供 trace / payload 接管 / 后续 usage 回填)。"""
|
|
367
|
+
from dataclasses import asdict
|
|
368
|
+
|
|
369
|
+
d = asdict(plan)
|
|
370
|
+
# 冻结决策审计:selected 只记 id/kind/tokens,不记 content(明文不进 trace,方案 §19)
|
|
371
|
+
d["selected"] = [
|
|
372
|
+
{
|
|
373
|
+
"item_id": i.get("item_id"),
|
|
374
|
+
"kind": i.get("kind"),
|
|
375
|
+
"estimated_tokens": i.get("estimated_tokens"),
|
|
376
|
+
"group_id": i.get("group_id"),
|
|
377
|
+
}
|
|
378
|
+
for i in d.get("selected", [])
|
|
379
|
+
]
|
|
380
|
+
return d
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def assembled_to_payload(assembled: AssembledInput) -> dict[str, Any]:
|
|
384
|
+
"""把 AssembledInput 投影成 runner payload 的 instructions/input/history(方案 §8)。
|
|
385
|
+
|
|
386
|
+
- ``system`` → payload["instructions"]
|
|
387
|
+
- 最后一条 user message → payload["input"]
|
|
388
|
+
- 其余 messages(system 之后、最后 user 之前)→ payload["history"](runner _to_state 消费)
|
|
389
|
+
"""
|
|
390
|
+
messages = list(assembled.messages)
|
|
391
|
+
system = assembled.system
|
|
392
|
+
# 分离:第一条 system,最后一条 user 作为 input,其余作为 history
|
|
393
|
+
history: list[dict[str, Any]] = []
|
|
394
|
+
input_text = ""
|
|
395
|
+
non_system = [m for m in messages if m.get("role") != "system"]
|
|
396
|
+
if non_system:
|
|
397
|
+
last = non_system[-1]
|
|
398
|
+
if last.get("role") == "user":
|
|
399
|
+
input_text = str(last.get("content") or "")
|
|
400
|
+
history = non_system[:-1]
|
|
401
|
+
else:
|
|
402
|
+
history = non_system
|
|
403
|
+
else:
|
|
404
|
+
history = []
|
|
405
|
+
return {
|
|
406
|
+
"instructions": system,
|
|
407
|
+
"input": input_text,
|
|
408
|
+
"history": history,
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
__all__ = [
|
|
413
|
+
"HostedPipelineResult",
|
|
414
|
+
"assembled_to_payload",
|
|
415
|
+
"hosted_pipeline_enabled",
|
|
416
|
+
"run_hosted_pipeline",
|
|
417
|
+
]
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Context Engine 数据模型 —— ContextItem / ContextBudget / ContextPlan / ContextDecision。
|
|
2
|
+
|
|
3
|
+
这些公开类型用于稳定表达请求级上下文的预算、选择、裁剪和投影决策,并由
|
|
4
|
+
``shadow_plan`` 旁路及正式规划链路共同消费。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from typing import Any, Literal
|
|
11
|
+
|
|
12
|
+
from ksadk.context_engine.capabilities import ContextAccuracy, ContextIntegrationMode
|
|
13
|
+
|
|
14
|
+
CONTEXT_POLICY_VERSION = "v1"
|
|
15
|
+
|
|
16
|
+
ContextKind = Literal[
|
|
17
|
+
"compiled_prompt",
|
|
18
|
+
"core_memory",
|
|
19
|
+
"resource_manifest",
|
|
20
|
+
"checkpoint_summary",
|
|
21
|
+
"working_state",
|
|
22
|
+
"recalled_memory",
|
|
23
|
+
"history_round",
|
|
24
|
+
"skill_content",
|
|
25
|
+
"tool_result",
|
|
26
|
+
"attachment_context",
|
|
27
|
+
"current_input",
|
|
28
|
+
]
|
|
29
|
+
"""可进入一次模型调用的最小上下文单元类型(方案 8.1)。"""
|
|
30
|
+
|
|
31
|
+
ContextTrustLevel = Literal["platform", "developer", "resource", "user", "untrusted"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class ContextItem:
|
|
36
|
+
"""可进入一次模型调用的最小上下文单元。
|
|
37
|
+
|
|
38
|
+
``group_id`` 用于原子保留/原子丢弃:一轮 user/assistant 对话、tool call 与对应
|
|
39
|
+
tool result、approval request/response、Responses API function call/output item。
|
|
40
|
+
所有 Memory/Knowledge/Tool/Hook/外部文件内容即使来自受信基础设施,也按 ``untrusted``
|
|
41
|
+
处理,不能覆盖 PromptSection。
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
item_id: str
|
|
45
|
+
kind: ContextKind
|
|
46
|
+
content: Any
|
|
47
|
+
source: str
|
|
48
|
+
trust_level: ContextTrustLevel
|
|
49
|
+
priority: int
|
|
50
|
+
estimated_tokens: int
|
|
51
|
+
required: bool = False
|
|
52
|
+
droppable: bool = True
|
|
53
|
+
truncatable: bool = False
|
|
54
|
+
stable: bool = False
|
|
55
|
+
group_id: str | None = None
|
|
56
|
+
seq_start: int | None = None
|
|
57
|
+
seq_end: int | None = None
|
|
58
|
+
score: float | None = None
|
|
59
|
+
content_hash: str | None = None
|
|
60
|
+
provenance: dict[str, Any] = field(default_factory=dict)
|
|
61
|
+
metadata: dict[str, Any] = field(default_factory=dict)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass(frozen=True)
|
|
65
|
+
class ContextBudget:
|
|
66
|
+
"""一次模型调用的 token 预算合同(方案 8.2)。
|
|
67
|
+
|
|
68
|
+
第一个 PR 只定义结构;50%/85% 双阈值计算与分区比例落盘留后续 PR
|
|
69
|
+
(``soft_limit_tokens`` / ``hard_limit_tokens`` 暂由调用方按需填充)。
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
context_window_tokens: int
|
|
73
|
+
reserved_output_tokens: int
|
|
74
|
+
reserved_reasoning_tokens: int
|
|
75
|
+
safety_buffer_tokens: int
|
|
76
|
+
max_input_tokens: int
|
|
77
|
+
soft_limit_tokens: int
|
|
78
|
+
hard_limit_tokens: int
|
|
79
|
+
section_limits: dict[str, int] = field(default_factory=dict)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass
|
|
83
|
+
class ContextDecision:
|
|
84
|
+
"""Planner 对单个候选项的保留/裁剪决策(方案 8.8)。"""
|
|
85
|
+
|
|
86
|
+
item_id: str
|
|
87
|
+
action: Literal["included", "summarized", "truncated", "dropped"]
|
|
88
|
+
reason: str
|
|
89
|
+
tokens_before: int
|
|
90
|
+
tokens_after: int
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@dataclass
|
|
94
|
+
class ContextPlan:
|
|
95
|
+
"""本次调用的候选项、预算与决策计划(方案 8.8)。
|
|
96
|
+
|
|
97
|
+
``ContextPlan`` 是平台的选择和投影计划。仅在 ``accounting_accuracy=exact`` 且 Projection
|
|
98
|
+
成功时它才代表最终模型输入;native/assisted 模式下必须结合 Runner 回报生成实际使用记录。
|
|
99
|
+
第一个 PR 中 ``selected`` / ``decisions`` 留空,仅 ``tokens_by_kind`` / ``planned_*``
|
|
100
|
+
由 shadow 旁路填充。
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
plan_id: str
|
|
104
|
+
policy_version: str
|
|
105
|
+
tokenizer: str
|
|
106
|
+
integration_mode: ContextIntegrationMode
|
|
107
|
+
accounting_accuracy: ContextAccuracy
|
|
108
|
+
budget: ContextBudget | None
|
|
109
|
+
selected: list[ContextItem]
|
|
110
|
+
decisions: list[ContextDecision]
|
|
111
|
+
tokens_by_kind: dict[str, int]
|
|
112
|
+
planned_input_tokens: int
|
|
113
|
+
projected_input_tokens: int | None
|
|
114
|
+
runtime_reported_input_tokens: int | None
|
|
115
|
+
stable_prefix_hash: str
|
|
116
|
+
projection_id: str | None = None
|
|
117
|
+
contributor_status: dict[str, str] = field(default_factory=dict)
|