foxclaw 0.1.0 → 0.1.2
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.
- package/README.md +54 -29
- package/bin/foxclaw.cjs +51 -0
- package/index.js +11 -10
- package/package.json +46 -38
- package/python/.dockerignore +35 -0
- package/python/.env.example +165 -0
- package/python/.gitattributes +46 -0
- package/python/.github/workflows/ci.yml +122 -0
- package/python/.github/workflows/release.yml +183 -0
- package/python/Dockerfile +64 -0
- package/python/LICENSE +21 -0
- package/python/MANIFEST.in +14 -0
- package/python/README.md +192 -0
- package/python/README_CN.md +324 -0
- package/python/bench/bm25_audit.py +199 -0
- package/python/bench/bm25_regression.py +178 -0
- package/python/bench/bm25_stress.py +159 -0
- package/python/bench/cd_audit.py +238 -0
- package/python/bench/chaos.py +142 -0
- package/python/bench/concurrency.py +103 -0
- package/python/bench/e2e_real_models.py +95 -0
- package/python/bench/llm_retry_test.py +248 -0
- package/python/bench/load_test.py +196 -0
- package/python/bench/vector_ivf_upgrade.py +134 -0
- package/python/docs/CHANNELS.md +195 -0
- package/python/docs/GOVERNANCE.md +164 -0
- package/python/docs/RELEASE.md +109 -0
- package/python/docs/RUN.md +75 -0
- package/python/docs/RUN_CN.md +121 -0
- package/python/docs//351/205/215/347/275/256/346/214/207/345/215/227.md +152 -0
- package/python/evals/__init__.py +0 -0
- package/python/evals/governance/README.md +61 -0
- package/python/evals/governance/__init__.py +0 -0
- package/python/evals/governance/cases.py +152 -0
- package/python/evals/governance/compare_embeddings.py +94 -0
- package/python/evals/governance/convergence.svg +11 -0
- package/python/evals/governance/report.json +371 -0
- package/python/evals/governance/run_evals.py +400 -0
- package/python/examples/governance_middleware_demo.py +77 -0
- package/python/examples/langgraph_governance_demo.py +108 -0
- package/python/examples/sample_itinerary.csv +6 -0
- package/python/examples/sample_knowledge.csv +9 -0
- package/python/examples/sample_transactions.csv +14 -0
- package/python/foxclaw/__init__.py +526 -0
- package/python/foxclaw/agents/__init__.py +12 -0
- package/python/foxclaw/agents/agents.py +35 -0
- package/python/foxclaw/agents/base.py +865 -0
- package/python/foxclaw/agents/impl/__init__.py +1 -0
- package/python/foxclaw/agents/impl/_helpers.py +78 -0
- package/python/foxclaw/agents/impl/finance.py +248 -0
- package/python/foxclaw/agents/impl/office.py +367 -0
- package/python/foxclaw/agents/impl/supervisor.py +659 -0
- package/python/foxclaw/agents/mixins/_context.py +151 -0
- package/python/foxclaw/agents/mixins/augment.py +149 -0
- package/python/foxclaw/agents/mixins/llm.py +66 -0
- package/python/foxclaw/agents/mixins/memory.py +35 -0
- package/python/foxclaw/agents/mixins/preference.py +81 -0
- package/python/foxclaw/agents/mixins/prompt.py +77 -0
- package/python/foxclaw/agents/mixins/skillbox.py +58 -0
- package/python/foxclaw/agents/mixins/tool_exec.py +443 -0
- package/python/foxclaw/api/__init__.py +283 -0
- package/python/foxclaw/api/app.py +123 -0
- package/python/foxclaw/api/middleware.py +317 -0
- package/python/foxclaw/api/routes/ahs.py +417 -0
- package/python/foxclaw/api/routes/attachments.py +117 -0
- package/python/foxclaw/api/routes/browser.py +39 -0
- package/python/foxclaw/api/routes/domain.py +314 -0
- package/python/foxclaw/api/routes/knowledge.py +163 -0
- package/python/foxclaw/api/routes/llm_admin.py +461 -0
- package/python/foxclaw/api/routes/memory.py +89 -0
- package/python/foxclaw/api/routes/orchestration.py +41 -0
- package/python/foxclaw/api/routes/recovery.py +43 -0
- package/python/foxclaw/api/routes/review.py +275 -0
- package/python/foxclaw/api/routes/search.py +37 -0
- package/python/foxclaw/api/routes/system.py +327 -0
- package/python/foxclaw/api/routes/task.py +281 -0
- package/python/foxclaw/api/routes/ws.py +68 -0
- package/python/foxclaw/api/spine.py +55 -0
- package/python/foxclaw/browser/__init__.py +13 -0
- package/python/foxclaw/browser/action/__init__.py +1 -0
- package/python/foxclaw/browser/action/action_executor.py +54 -0
- package/python/foxclaw/browser/action/action_types.py +45 -0
- package/python/foxclaw/browser/action/action_verifier.py +68 -0
- package/python/foxclaw/browser/action/url_policy.py +147 -0
- package/python/foxclaw/browser/adapter/__init__.py +1 -0
- package/python/foxclaw/browser/adapter/base_adapter.py +23 -0
- package/python/foxclaw/browser/adapter/web_adapter.py +46 -0
- package/python/foxclaw/browser/driver/__init__.py +1 -0
- package/python/foxclaw/browser/driver/base_driver.py +61 -0
- package/python/foxclaw/browser/driver/playwright_driver.py +166 -0
- package/python/foxclaw/browser/perception/__init__.py +1 -0
- package/python/foxclaw/browser/perception/dom_extractor.py +43 -0
- package/python/foxclaw/browser/perception/element_indexer.py +57 -0
- package/python/foxclaw/browser/perception/semantic_reducer.py +33 -0
- package/python/foxclaw/browser/perception/snapshot.py +29 -0
- package/python/foxclaw/browser/service.py +148 -0
- package/python/foxclaw/browser/session/__init__.py +1 -0
- package/python/foxclaw/browser/session/session_manager.py +57 -0
- package/python/foxclaw/capability/__init__.py +12 -0
- package/python/foxclaw/capability/embedding_service.py +67 -0
- package/python/foxclaw/channels/__init__.py +140 -0
- package/python/foxclaw/channels/discord.py +184 -0
- package/python/foxclaw/channels/dispatcher.py +204 -0
- package/python/foxclaw/channels/feishu.py +225 -0
- package/python/foxclaw/channels/openclaw_bridge.py +156 -0
- package/python/foxclaw/channels/signing.py +187 -0
- package/python/foxclaw/channels/telegram.py +121 -0
- package/python/foxclaw/channels/weixin.py +225 -0
- package/python/foxclaw/cli.py +154 -0
- package/python/foxclaw/cognitive/__init__.py +4 -0
- package/python/foxclaw/cognitive/reasoner.py +82 -0
- package/python/foxclaw/cognitive/state.py +147 -0
- package/python/foxclaw/core/__init__.py +9 -0
- package/python/foxclaw/core/audit_chain.py +133 -0
- package/python/foxclaw/core/audit_sink.py +100 -0
- package/python/foxclaw/core/compaction.py +283 -0
- package/python/foxclaw/core/config.py +65 -0
- package/python/foxclaw/core/confirm_nonce.py +157 -0
- package/python/foxclaw/core/dispatch.py +27 -0
- package/python/foxclaw/core/envfile.py +48 -0
- package/python/foxclaw/core/failure_policy.py +151 -0
- package/python/foxclaw/core/gateway.py +85 -0
- package/python/foxclaw/core/governance_audit.py +175 -0
- package/python/foxclaw/core/idempotency.py +289 -0
- package/python/foxclaw/core/injection_guard.py +221 -0
- package/python/foxclaw/core/memory_adapter.py +516 -0
- package/python/foxclaw/core/metrics.py +89 -0
- package/python/foxclaw/core/model_router.py +1097 -0
- package/python/foxclaw/core/paths.py +103 -0
- package/python/foxclaw/core/recovery.py +362 -0
- package/python/foxclaw/core/scheduler.py +144 -0
- package/python/foxclaw/core/secrets.py +134 -0
- package/python/foxclaw/core/sessions.py +157 -0
- package/python/foxclaw/core/settings.py +430 -0
- package/python/foxclaw/core/shared_write.py +198 -0
- package/python/foxclaw/core/steering_queue.py +153 -0
- package/python/foxclaw/core/system_bus.py +84 -0
- package/python/foxclaw/core/thought_chain.py +318 -0
- package/python/foxclaw/core/token_meter.py +235 -0
- package/python/foxclaw/core/tools.py +172 -0
- package/python/foxclaw/core/tracing.py +390 -0
- package/python/foxclaw/core/truth_pipeline.py +114 -0
- package/python/foxclaw/core/vec_recall_adapter.py +503 -0
- package/python/foxclaw/core/verify.py +181 -0
- package/python/foxclaw/core/web_search.py +242 -0
- package/python/foxclaw/finance/__init__.py +15 -0
- package/python/foxclaw/finance/evidence.py +153 -0
- package/python/foxclaw/finance/fx.py +100 -0
- package/python/foxclaw/finance/graph.py +188 -0
- package/python/foxclaw/finance/models.py +150 -0
- package/python/foxclaw/finance/nlparse.py +575 -0
- package/python/foxclaw/finance/policy.py +329 -0
- package/python/foxclaw/finance/reasoner.py +129 -0
- package/python/foxclaw/finance/reasoning.py +340 -0
- package/python/foxclaw/finance/reconcile.py +180 -0
- package/python/foxclaw/finance/runtime.py +527 -0
- package/python/foxclaw/governance/__init__.py +24 -0
- package/python/foxclaw/governance/middleware.py +184 -0
- package/python/foxclaw/harness/__init__.py +17 -0
- package/python/foxclaw/harness/_base.py +72 -0
- package/python/foxclaw/harness/_policy.py +359 -0
- package/python/foxclaw/harness/drift.py +89 -0
- package/python/foxclaw/harness/event_bus.py +31 -0
- package/python/foxclaw/harness/harness.py +446 -0
- package/python/foxclaw/harness/loop_detection.py +152 -0
- package/python/foxclaw/itinerary/__init__.py +10 -0
- package/python/foxclaw/itinerary/amap_client.py +117 -0
- package/python/foxclaw/itinerary/models.py +80 -0
- package/python/foxclaw/itinerary/reasoner.py +101 -0
- package/python/foxclaw/itinerary/reasoning.py +174 -0
- package/python/foxclaw/itinerary/runtime.py +148 -0
- package/python/foxclaw/kernel/__init__.py +13 -0
- package/python/foxclaw/kernel/capabilities.py +73 -0
- package/python/foxclaw/kernel/policy_gate.py +114 -0
- package/python/foxclaw/kernel/process_manager.py +205 -0
- package/python/foxclaw/kernel/scheduler.py +131 -0
- package/python/foxclaw/kernel/sentinel.py +453 -0
- package/python/foxclaw/kernel/sentinel_client.py +246 -0
- package/python/foxclaw/kernel/spine.py +97 -0
- package/python/foxclaw/knowledge/__init__.py +376 -0
- package/python/foxclaw/knowledge/truth_crystallizer.py +92 -0
- package/python/foxclaw/learning/__init__.py +12 -0
- package/python/foxclaw/learning/knowledge_graph.py +149 -0
- package/python/foxclaw/learning/models.py +93 -0
- package/python/foxclaw/learning/reasoner.py +70 -0
- package/python/foxclaw/learning/runtime.py +363 -0
- package/python/foxclaw/learning/spaced_repetition.py +96 -0
- package/python/foxclaw/mcp_server.py +189 -0
- package/python/foxclaw/orchestration/__init__.py +184 -0
- package/python/foxclaw/pipeline/__init__.py +23 -0
- package/python/foxclaw/pipeline/cognitive_pipeline.py +481 -0
- package/python/foxclaw/pipeline/supervisor_stages.py +230 -0
- package/python/foxclaw/planning/__init__.py +17 -0
- package/python/foxclaw/planning/llm_planner.py +232 -0
- package/python/foxclaw/planning/planner.py +99 -0
- package/python/foxclaw/search/__init__.py +24 -0
- package/python/foxclaw/search/agent_port.py +194 -0
- package/python/foxclaw/search/evidence.py +113 -0
- package/python/foxclaw/search/external_search.py +50 -0
- package/python/foxclaw/search/hkc_read_port.py +60 -0
- package/python/foxclaw/search/internal_search.py +73 -0
- package/python/foxclaw/search/models.py +129 -0
- package/python/foxclaw/search/planner.py +44 -0
- package/python/foxclaw/search/retriever.py +39 -0
- package/python/foxclaw/search/runtime.py +134 -0
- package/python/foxclaw/search/strategy.py +44 -0
- package/python/foxclaw/skills/__init__.py +613 -0
- package/python/foxclaw/skills/hooks_spec.py +73 -0
- package/python/foxclaw/skills/lifecycle.py +278 -0
- package/python/foxclaw/skills/markdown_skill.py +174 -0
- package/python/foxclaw/skills/markdown_store.py +39 -0
- package/python/foxclaw/skills/mcp_client.py +190 -0
- package/python/foxclaw/skills/mcp_store.py +43 -0
- package/python/foxclaw/skills/permission.py +180 -0
- package/python/foxclaw/skills/pipeline.py +386 -0
- package/python/foxclaw/skills/policy.py +80 -0
- package/python/foxclaw/skills/review.py +72 -0
- package/python/foxclaw/skills/store.py +57 -0
- package/python/frontend/assets/core_bg.jpg +0 -0
- package/python/frontend/deck/auth.js +32 -0
- package/python/frontend/deck/chat_model_picker.js +537 -0
- package/python/frontend/deck/domain.js +296 -0
- package/python/frontend/deck/main.js +1950 -0
- package/python/frontend/deck/markdown.js +48 -0
- package/python/frontend/deck/settings.js +324 -0
- package/python/frontend/deck/state.js +6 -0
- package/python/frontend/deck/util.js +6 -0
- package/python/frontend/deck/visuals.js +212 -0
- package/python/frontend/deck.css +855 -0
- package/python/frontend/deck.html +686 -0
- package/python/frontend/deck_v2.html +341 -0
- package/python/frontend/planet/index.html +266 -0
- package/python/frontend/planet/planet.css +579 -0
- package/python/frontend/planet/planet.js +1637 -0
- package/python/frontend/planet/vendor/three.core.min.js +6 -0
- package/python/frontend/planet/vendor/three.module.min.js +6 -0
- package/python/frontend/v3/assets/index-BD7VPbMV.js +33 -0
- package/python/frontend/v3/assets/index-CAvnYWGH.css +1 -0
- package/python/frontend/v3/index.html +15 -0
- package/python/frontend/widget_runtime.js +295 -0
- package/python/frontend/widgets.js +696 -0
- package/python/frontend_src/index.html +14 -0
- package/python/frontend_src/package-lock.json +1376 -0
- package/python/frontend_src/package.json +19 -0
- package/python/frontend_src/src/App.vue +62 -0
- package/python/frontend_src/src/api.js +89 -0
- package/python/frontend_src/src/components/ChatDock.vue +377 -0
- package/python/frontend_src/src/components/ComposerMenu.vue +75 -0
- package/python/frontend_src/src/components/DocViewer.vue +171 -0
- package/python/frontend_src/src/components/Inspector.vue +241 -0
- package/python/frontend_src/src/components/LeftRail.vue +394 -0
- package/python/frontend_src/src/components/MenuPopover.vue +130 -0
- package/python/frontend_src/src/components/MessageStream.vue +401 -0
- package/python/frontend_src/src/components/ModelPicker.vue +355 -0
- package/python/frontend_src/src/components/QuickIngest.vue +118 -0
- package/python/frontend_src/src/components/Stage.vue +226 -0
- package/python/frontend_src/src/components/ToolMenu.vue +144 -0
- package/python/frontend_src/src/components/TopBar.vue +90 -0
- package/python/frontend_src/src/components/panels/ActivityPanel.vue +84 -0
- package/python/frontend_src/src/components/panels/AgentsPanel.vue +86 -0
- package/python/frontend_src/src/components/panels/KnowledgePanel.vue +441 -0
- package/python/frontend_src/src/components/panels/MemoryPanel.vue +118 -0
- package/python/frontend_src/src/components/panels/PanelBox.vue +51 -0
- package/python/frontend_src/src/components/panels/ReviewPanel.vue +308 -0
- package/python/frontend_src/src/components/panels/SettingsPanel.vue +254 -0
- package/python/frontend_src/src/components/panels/TasksPanel.vue +74 -0
- package/python/frontend_src/src/components/panels/ToolsPanel.vue +640 -0
- package/python/frontend_src/src/components/panels/UsagePanel.vue +105 -0
- package/python/frontend_src/src/lib/fmt.js +48 -0
- package/python/frontend_src/src/lib/md.js +204 -0
- package/python/frontend_src/src/main.js +7 -0
- package/python/frontend_src/src/stores/app.js +106 -0
- package/python/frontend_src/src/stores/chat.js +484 -0
- package/python/frontend_src/src/stores/model.js +104 -0
- package/python/frontend_src/src/stores/panels.js +330 -0
- package/python/frontend_src/src/styles/base.css +138 -0
- package/python/frontend_src/src/styles/panel.css +117 -0
- package/python/frontend_src/src/styles/tokens.css +78 -0
- package/python/frontend_src/vite.config.js +46 -0
- package/python/pyproject.toml +265 -0
- package/python/skills/README.md +123 -0
- package/python/skills/execution-contract/SKILL.md +30 -0
- package/python/skills/general-assistant/SKILL.md +34 -0
- package/python/skills/planner/SKILL.md +33 -0
- package/python/skills/schedule-itinerary/SKILL.md +35 -0
- package/python/skills/skill-composition/SKILL.md +31 -0
- package/python/skills/skill-guard/SKILL.md +67 -0
- package/python/skills/skill-memory/SKILL.md +50 -0
- package/python/skills/skill-router/SKILL.md +35 -0
- package/python/tests/conftest.py +76 -0
- package/python/tests/run_all.py +263 -0
- package/python/tests/test_agent_lifecycle.py +360 -0
- package/python/tests/test_ahs_p2.py +414 -0
- package/python/tests/test_anthropic_tools.py +206 -0
- package/python/tests/test_api.py +87 -0
- package/python/tests/test_api_auth.py +83 -0
- package/python/tests/test_api_host_guard.py +69 -0
- package/python/tests/test_attachments.py +167 -0
- package/python/tests/test_audit_chain.py +121 -0
- package/python/tests/test_audit_sink.py +136 -0
- package/python/tests/test_browser.py +153 -0
- package/python/tests/test_browser_request_guard.py +184 -0
- package/python/tests/test_capabilities.py +158 -0
- package/python/tests/test_channel_signing.py +192 -0
- package/python/tests/test_channel_trust.py +109 -0
- package/python/tests/test_channels.py +184 -0
- package/python/tests/test_cli.py +46 -0
- package/python/tests/test_compaction_toolpair.py +119 -0
- package/python/tests/test_config_layering.py +65 -0
- package/python/tests/test_confirm_nonce.py +197 -0
- package/python/tests/test_context_compaction_wiring.py +130 -0
- package/python/tests/test_dispatch.py +95 -0
- package/python/tests/test_domain_evals.py +403 -0
- package/python/tests/test_domain_import.py +78 -0
- package/python/tests/test_domain_reasoners.py +148 -0
- package/python/tests/test_e2e.py +178 -0
- package/python/tests/test_emb_cache.py +107 -0
- package/python/tests/test_embedding_singleton.py +89 -0
- package/python/tests/test_envfile.py +83 -0
- package/python/tests/test_evals_smoke.py +114 -0
- package/python/tests/test_event_spine.py +182 -0
- package/python/tests/test_evidence_semantic.py +101 -0
- package/python/tests/test_evidence_sse.py +97 -0
- package/python/tests/test_file_ingest.py +146 -0
- package/python/tests/test_finance.py +153 -0
- package/python/tests/test_finance_ledger.py +252 -0
- package/python/tests/test_finance_persist.py +178 -0
- package/python/tests/test_gateway.py +144 -0
- package/python/tests/test_governance.py +468 -0
- package/python/tests/test_governance_audit.py +359 -0
- package/python/tests/test_governance_middleware.py +143 -0
- package/python/tests/test_hkc.py +286 -0
- package/python/tests/test_hkc_index_build_manager.py +339 -0
- package/python/tests/test_hkc_manifest_reuse.py +317 -0
- package/python/tests/test_hkc_search_event_sync.py +533 -0
- package/python/tests/test_import_path_guard.py +161 -0
- package/python/tests/test_injection_guard.py +211 -0
- package/python/tests/test_integration.py +141 -0
- package/python/tests/test_itinerary.py +103 -0
- package/python/tests/test_kee_semantic.py +89 -0
- package/python/tests/test_kernel.py +222 -0
- package/python/tests/test_learning.py +110 -0
- package/python/tests/test_llm_admin.py +160 -0
- package/python/tests/test_llm_planner.py +366 -0
- package/python/tests/test_markdown_skills.py +73 -0
- package/python/tests/test_markdown_skills_openclaw.py +71 -0
- package/python/tests/test_mcp_connectors.py +109 -0
- package/python/tests/test_mcp_guardian_discovery.py +91 -0
- package/python/tests/test_mcp_no_memory.py +43 -0
- package/python/tests/test_mcp_policy_gate.py +77 -0
- package/python/tests/test_mcp_server.py +95 -0
- package/python/tests/test_memory_recall.py +95 -0
- package/python/tests/test_metrics.py +66 -0
- package/python/tests/test_multi_chain.py +102 -0
- package/python/tests/test_multimodal.py +135 -0
- package/python/tests/test_negotiation.py +146 -0
- package/python/tests/test_orchestration.py +119 -0
- package/python/tests/test_orchestration_decoupled.py +109 -0
- package/python/tests/test_p3_p5_hardening.py +338 -0
- package/python/tests/test_parallel_dispatch.py +215 -0
- package/python/tests/test_pipeline.py +533 -0
- package/python/tests/test_plan_visible.py +86 -0
- package/python/tests/test_planner.py +95 -0
- package/python/tests/test_policy_gate.py +109 -0
- package/python/tests/test_reasoner.py +185 -0
- package/python/tests/test_release_check.py +263 -0
- package/python/tests/test_resume_checkpoint.py +156 -0
- package/python/tests/test_routing.py +95 -0
- package/python/tests/test_scheduler.py +141 -0
- package/python/tests/test_search.py +204 -0
- package/python/tests/test_secrets.py +159 -0
- package/python/tests/test_semantic.py +78 -0
- package/python/tests/test_sessions.py +91 -0
- package/python/tests/test_settings.py +281 -0
- package/python/tests/test_shadow_learning.py +330 -0
- package/python/tests/test_shared_write.py +207 -0
- package/python/tests/test_skill_taint_gate.py +154 -0
- package/python/tests/test_skills.py +133 -0
- package/python/tests/test_stats_and_events.py +165 -0
- package/python/tests/test_streaming.py +60 -0
- package/python/tests/test_supervisor_pipeline.py +177 -0
- package/python/tests/test_supervisor_triage.py +108 -0
- package/python/tests/test_taint.py +117 -0
- package/python/tests/test_task_stream.py +85 -0
- package/python/tests/test_thinking_sse.py +67 -0
- package/python/tests/test_thinking_stream.py +76 -0
- package/python/tests/test_tool_center.py +129 -0
- package/python/tests/test_tool_parallel.py +113 -0
- package/python/tests/test_tool_params.py +103 -0
- package/python/tests/test_tool_use.py +242 -0
- package/python/tests/test_toplevel_concurrency.py +117 -0
- package/python/tests/test_tracing.py +290 -0
- package/python/tests/test_truth_crystallizer.py +127 -0
- package/python/tests/test_truth_flow.py +93 -0
- package/python/tests/test_url_policy.py +53 -0
- package/python/tests/test_verify_evidence.py +225 -0
- package/python/tests/test_version_sync.py +71 -0
- package/python/tests/test_web_trigger.py +99 -0
- package/python/tools/check_faiss_type.py +31 -0
- package/python/tools/check_log.ps1 +46 -0
- package/python/tools/ivf_status.py +72 -0
- package/python/tools/mypy_baseline.txt +5 -0
- package/python/tools/mypy_ratchet.py +97 -0
- package/python/tools/pack.py +178 -0
- package/python/tools/release_check.py +349 -0
- package/python/tools/restart_foxclaw.ps1 +74 -0
- package/python/tools/shared_write_audit.py +204 -0
- package/python/tools/size_baseline.txt +28 -0
- package/python/tools/size_check.py +102 -0
- package/python/tools/verify_env.bat +2 -0
- package/python/tools/verify_env.py +25 -0
- package/python/vendor/HMR_LICENSE +37 -0
- package/python/vendor/HMR_README.md +65 -0
- package/python/vendor/hkc/LICENSE +37 -0
- package/python/vendor/hkc/hkc_ace/__init__.py +0 -0
- package/python/vendor/hkc/hkc_ace/ace.py +457 -0
- package/python/vendor/hkc/hkc_ace/skill_taxonomy.json +465 -0
- package/python/vendor/hkc/hkc_api/__init__.py +0 -0
- package/python/vendor/hkc/hkc_api/container.py +416 -0
- package/python/vendor/hkc/hkc_api/ingest_jobs.py +103 -0
- package/python/vendor/hkc/hkc_api/main.py +157 -0
- package/python/vendor/hkc/hkc_api/routes/__init__.py +0 -0
- package/python/vendor/hkc/hkc_api/routes/ability.py +151 -0
- package/python/vendor/hkc/hkc_api/routes/config.py +51 -0
- package/python/vendor/hkc/hkc_api/routes/knowledge.py +630 -0
- package/python/vendor/hkc/hkc_api/routes/search.py +88 -0
- package/python/vendor/hkc/hkc_api/schemas.py +153 -0
- package/python/vendor/hkc/hkc_api/synthesis.py +179 -0
- package/python/vendor/hkc/hkc_core/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/graph/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/graph/base.py +188 -0
- package/python/vendor/hkc/hkc_core/graph/sqlite_store.py +789 -0
- package/python/vendor/hkc/hkc_core/models/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/models/enums.py +65 -0
- package/python/vendor/hkc/hkc_core/models/ku.py +307 -0
- package/python/vendor/hkc/hkc_core/utils/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/utils/id_gen.py +113 -0
- package/python/vendor/hkc/hkc_crystallizer/__init__.py +44 -0
- package/python/vendor/hkc/hkc_crystallizer/adapters.py +94 -0
- package/python/vendor/hkc/hkc_crystallizer/candidate.py +145 -0
- package/python/vendor/hkc/hkc_crystallizer/crystallizer.py +179 -0
- package/python/vendor/hkc/hkc_crystallizer/ingress.py +90 -0
- package/python/vendor/hkc/hkc_kde/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kde/chunker.py +197 -0
- package/python/vendor/hkc/hkc_kde/extractor.py +623 -0
- package/python/vendor/hkc/hkc_kde/kde.py +298 -0
- package/python/vendor/hkc/hkc_kde/loaders/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kde/loaders/ebook_loader.py +153 -0
- package/python/vendor/hkc/hkc_kde/loaders/office_loader.py +194 -0
- package/python/vendor/hkc/hkc_kde/loaders/pdf_loader.py +162 -0
- package/python/vendor/hkc/hkc_kde/loaders/text_loader.py +157 -0
- package/python/vendor/hkc/hkc_kde/loaders/web_loader.py +91 -0
- package/python/vendor/hkc/hkc_kde/models.py +74 -0
- package/python/vendor/hkc/hkc_kde/packager.py +329 -0
- package/python/vendor/hkc/hkc_kde/relation_disc.py +151 -0
- package/python/vendor/hkc/hkc_kee/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kee/dedup.py +227 -0
- package/python/vendor/hkc/hkc_kee/fingerprint.py +106 -0
- package/python/vendor/hkc/hkc_kee/kee.py +541 -0
- package/python/vendor/hkc/hkc_kep/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kep/event_bus.py +205 -0
- package/python/vendor/hkc/hkc_sdk/__init__.py +63 -0
- package/python/vendor/hkc/hkc_sdk/base.py +151 -0
- package/python/vendor/hkc/hkc_sdk/direct_client.py +153 -0
- package/python/vendor/hkc/hkc_sdk/exceptions.py +39 -0
- package/python/vendor/hkc/hkc_sdk/http_client.py +166 -0
- package/python/vendor/hkc/hkc_sdk/models.py +171 -0
- package/python/vendor/hkc/hkc_search/__init__.py +0 -0
- package/python/vendor/hkc/hkc_search/bm25.py +325 -0
- package/python/vendor/hkc/hkc_search/embedding_backends.py +374 -0
- package/python/vendor/hkc/hkc_search/graph_search.py +132 -0
- package/python/vendor/hkc/hkc_search/hybrid.py +331 -0
- package/python/vendor/hkc/hkc_search/index_build_manager.py +378 -0
- package/python/vendor/hkc/hkc_search/vector_search.py +484 -0
- package/python/vendor/hmr/__init__.py +0 -0
- package/python/vendor/hmr/core/__init__.py +0 -0
- package/python/vendor/hmr/core/hmr.py +684 -0
- package/python/vendor/hmr/core/models.py +310 -0
- package/python/vendor/hmr/engines/__init__.py +0 -0
- package/python/vendor/hmr/engines/evolution.py +710 -0
- package/python/vendor/hmr/engines/jit_compiler.py +472 -0
- package/python/vendor/hmr/engines/lifecycle.py +264 -0
- package/python/vendor/hmr/engines/policy.py +625 -0
- package/python/vendor/hmr/engines/recall.py +260 -0
- package/python/vendor/hmr/engines/runtime_state.py +158 -0
- package/python/vendor/hmr/engines/scheduler.py +323 -0
- package/python/vendor/hmr/engines/semantic.py +150 -0
- package/python/vendor/hmr/engines/temporal.py +261 -0
- package/python/vendor/hmr/engines/thought_chain.py +635 -0
- package/python/vendor/hmr/graph/__init__.py +0 -0
- package/python/vendor/hmr/graph/cwg.py +338 -0
- package/python/vendor/hmr/graph/memory_graph.py +530 -0
- package/python/vendor/hmr/storage/__init__.py +0 -0
- package/python/vendor/hmr/storage/memory_fs.py +300 -0
- package/python/vendor/hmr/storage/vector_store.py +520 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""具体 Agent 实现子包(步骤 3 拆分)。"""
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""共享辅助函数与多步链式常量(步骤 3 从 agents.py 拆出,纯搬移)。"""
|
|
2
|
+
|
|
3
|
+
from ...core.dispatch import dispatch_failed as _dispatch_failed # noqa: F401 (re-export)
|
|
4
|
+
|
|
5
|
+
# ── 多步链式上下文 ────────────────────────────────────────────
|
|
6
|
+
# 注入的前序步数与单步字符必须封顶:长链会把提示词越滚越大(且越往后越贵/越容易超窗)。
|
|
7
|
+
PRIOR_MAX_STEPS = 3 # 只带最近 N 步(更早的通常已被后续步骤消化)
|
|
8
|
+
PRIOR_MAX_CHARS = 300 # 单步输出截断
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _with_prior(subtask: str, prior: list) -> str:
|
|
12
|
+
"""把前序步骤结果并进下一步的任务文本,让多步真正成链。
|
|
13
|
+
|
|
14
|
+
为什么并进 task 文本而不是只塞 context:各领域 Agent 的 `_execute` 是各自实现的,
|
|
15
|
+
未必会去读 context;而 task 文本必定进提示词 —— 这样对**所有** Agent 都生效,
|
|
16
|
+
且无需改动任何一个 Agent。context 里也照样放一份结构化的(两手准备)。
|
|
17
|
+
"""
|
|
18
|
+
if not prior:
|
|
19
|
+
return subtask
|
|
20
|
+
lines = "\n".join(
|
|
21
|
+
f"第{p['step']}步({p['agent']}):{str(p.get('output',''))[:PRIOR_MAX_CHARS]}"
|
|
22
|
+
for p in prior[-PRIOR_MAX_STEPS:]
|
|
23
|
+
)
|
|
24
|
+
return f"{subtask}\n\n[前序步骤结果 —— 若与本步相关,请据此作答]\n{lines}"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _fmt_mem(m: dict, max_chars: int | None = None) -> str:
|
|
28
|
+
"""把一条召回记忆格式化为带结构信息的文本(标题/相关度/共享标记)。
|
|
29
|
+
|
|
30
|
+
替代此前各领域 Agent 只取 content 的注入——那会丢弃 title/score/shared 等
|
|
31
|
+
结构信息,让 LLM 无法区分"高相关共享决策"与"低相关私有闲聊"。字段可能缺失
|
|
32
|
+
(不同召回路径返回的 dict 字段不一),全部安全降级:title 空 / score 非数字 /
|
|
33
|
+
无 shared 时退化为纯 content,行为与改前一致。max_chars=None 不截断。
|
|
34
|
+
"""
|
|
35
|
+
title = (m.get("title") or "").strip()
|
|
36
|
+
content = (m.get("content") or "").strip()
|
|
37
|
+
if max_chars is not None:
|
|
38
|
+
content = content[:max_chars]
|
|
39
|
+
parts = [title] if title else []
|
|
40
|
+
score = m.get("score")
|
|
41
|
+
if score is not None:
|
|
42
|
+
try:
|
|
43
|
+
parts.append(f"相关度{float(score):.2f}")
|
|
44
|
+
except (TypeError, ValueError):
|
|
45
|
+
pass
|
|
46
|
+
if m.get("shared"):
|
|
47
|
+
parts.append("[共享]")
|
|
48
|
+
head = " ".join(parts)
|
|
49
|
+
return f"{head}:{content}" if head else content
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# ── P0-1 反思重规划:执行结果判定 ────────────────────────────
|
|
53
|
+
# 实现已下沉到 core.dispatch(见文件头 import):pipeline 的 replan stage 也要用它,
|
|
54
|
+
# 而 pipeline 不能反向 import agents —— 两处都只依赖 core,依赖方向单一。
|
|
55
|
+
# `_dispatch_failed` 在此保留为 re-export,历史导入路径(agents.agents / impl.supervisor)不变。
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _extract_step_results(dr) -> list:
|
|
59
|
+
"""从 dispatch_result 提取各步结果(供 LLM 反思:含成功/失败状态与输出)。"""
|
|
60
|
+
if not isinstance(dr, dict):
|
|
61
|
+
return []
|
|
62
|
+
result = dr.get("result") or {}
|
|
63
|
+
if not isinstance(result, dict):
|
|
64
|
+
return []
|
|
65
|
+
steps = result.get("parallel_steps") or result.get("multi_steps") or []
|
|
66
|
+
out = []
|
|
67
|
+
for s in steps:
|
|
68
|
+
if not isinstance(s, dict):
|
|
69
|
+
continue
|
|
70
|
+
out.append({
|
|
71
|
+
"subtask": s.get("subtask") or s.get("step"),
|
|
72
|
+
"agent": s.get("agent"),
|
|
73
|
+
"output": s.get("output", ""),
|
|
74
|
+
"blocked": bool(s.get("blocked")),
|
|
75
|
+
"failed": bool(s.get("failed")),
|
|
76
|
+
})
|
|
77
|
+
return out
|
|
78
|
+
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"""FinanceAgent —— 财务(理财、收支、预算)。"""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
from ..base import CognitiveAgent
|
|
6
|
+
from ._helpers import _fmt_mem
|
|
7
|
+
|
|
8
|
+
# 分析/建议类意图:即使这句话里带了金额,也要走 LLM 给结论,而不是只回一张记账回执
|
|
9
|
+
_ADVICE_WORDS = ("分析", "建议", "怎么", "如何", "多少", "预算", "超支", "优化", "规划",
|
|
10
|
+
"趋势", "为什么", "要不要", "合算", "划算", "省", "控制", "总结",
|
|
11
|
+
"报告", "够不够", "对比", "排名", "异常", "提醒", "合理", "占比",
|
|
12
|
+
"占收入", "比例")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _wants_advice(task: str) -> bool:
|
|
16
|
+
t = task or ""
|
|
17
|
+
return any(w in t for w in _ADVICE_WORDS)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _should_autorecord(task: str) -> bool:
|
|
21
|
+
"""记账闸门:有金额 + 像报备,且不是「在讨论钱」而不是「花了钱」。
|
|
22
|
+
|
|
23
|
+
最容易记错的三类:
|
|
24
|
+
- 「衣服预算 800」→ 带金额但是设预算,记成支出就把预算本身花了
|
|
25
|
+
- 「每月房租 3000 占收入 10000 合理吗」→ 讨论额度与比例,不是报账
|
|
26
|
+
- 「本月花了多少」→ 带"花"和数字但没有金额,解析器本来就返回空
|
|
27
|
+
|
|
28
|
+
判据:带分析意图时,只有**完成态**动词(买了/花了/交了)才证明钱真出去了;
|
|
29
|
+
否则一律交给分析路径,宁可不记也不要记错。
|
|
30
|
+
"""
|
|
31
|
+
from ...finance.nlparse import has_expense_signal, has_settled_spend
|
|
32
|
+
t = task or ""
|
|
33
|
+
if not has_expense_signal(t):
|
|
34
|
+
return False
|
|
35
|
+
settled = has_settled_spend(t)
|
|
36
|
+
if "预算" in t and not settled:
|
|
37
|
+
return False
|
|
38
|
+
if _wants_advice(t) and not settled:
|
|
39
|
+
return False
|
|
40
|
+
if settled:
|
|
41
|
+
return True
|
|
42
|
+
# 没有完成态动词时,只有「金额 + 明确消费类目」这种报备才记(洗车 100)
|
|
43
|
+
return not _wants_advice(t)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class FinanceAgent(CognitiveAgent):
|
|
47
|
+
AGENT_ID = "finance"
|
|
48
|
+
AGENT_NAME = "财务 Agent"
|
|
49
|
+
ALLOWED_TOOL_CATEGORIES = {"read", "write", "finance"}
|
|
50
|
+
|
|
51
|
+
def attach_runtime(self, runtime):
|
|
52
|
+
"""挂载财务内核(FinanceRuntime):记忆+推理+Policy 守门人。"""
|
|
53
|
+
self.fin = runtime
|
|
54
|
+
|
|
55
|
+
# ── 编排协作(P3:财务领域态势 + 预算守门人,从编排层下沉至此)──────
|
|
56
|
+
def situation(self) -> dict:
|
|
57
|
+
rt = getattr(self, "fin", None)
|
|
58
|
+
if rt is None:
|
|
59
|
+
return {"domain": "finance", "status": {}, "alerts": []}
|
|
60
|
+
try:
|
|
61
|
+
over = [b for b in rt.reasoning.budget_status(rt.transactions, rt.budgets)
|
|
62
|
+
if b["is_over"]]
|
|
63
|
+
except Exception:
|
|
64
|
+
over = []
|
|
65
|
+
status = {"transactions": len(rt.transactions),
|
|
66
|
+
"over_budget_categories": [b["category"] for b in over]}
|
|
67
|
+
alerts = [{"domain": "finance", "severity": "warn",
|
|
68
|
+
"msg": f"{b['category']} 超支 {b['spent']:.0f}/{b['monthly_limit']:.0f}"}
|
|
69
|
+
for b in over]
|
|
70
|
+
return {"domain": "finance", "status": status, "alerts": alerts}
|
|
71
|
+
|
|
72
|
+
def handle_cross_request(self, req) -> None:
|
|
73
|
+
"""差旅/采购预算申请 → 财务守门人**认知化**裁决(v2 ③:观察→假设→证据→裁决,
|
|
74
|
+
规则实现、裁决逐字不变、显式证据链)。"""
|
|
75
|
+
if req.request_type != "budget_request":
|
|
76
|
+
return super().handle_cross_request(req)
|
|
77
|
+
rt = getattr(self, "fin", None)
|
|
78
|
+
amount = req.payload.get("amount", 0)
|
|
79
|
+
category = req.payload.get("category", "travel")
|
|
80
|
+
if rt is None:
|
|
81
|
+
req.status = "approved"; req.verdict = "财务内核未挂载,默认放行"; return
|
|
82
|
+
from ...finance import Transaction
|
|
83
|
+
from ...finance.reasoner import FinanceGatekeeperReasoner
|
|
84
|
+
txn = Transaction(amount=-abs(amount), category=category,
|
|
85
|
+
entity=req.payload.get("entity", "差旅"),
|
|
86
|
+
account=req.payload.get("account", "default"))
|
|
87
|
+
bal = rt.account_balances.get(txn.account)
|
|
88
|
+
# Step3:模糊情形的 LLM 裁决(默认关;FOXCLAW_FINANCE_LLM_ARBITER=1 才启用)。
|
|
89
|
+
# 安全不变量:LLM 只在规则已批准的模糊带被咨询、只能 approve→confirm、出错→confirm、永不 reject。
|
|
90
|
+
import os as _os
|
|
91
|
+
_llm_on = _os.environ.get("FOXCLAW_FINANCE_LLM_ARBITER", "") == "1"
|
|
92
|
+
rv = FinanceGatekeeperReasoner(
|
|
93
|
+
rt.policy, runtime=rt,
|
|
94
|
+
llm=getattr(self, "router", None), llm_enabled=_llm_on).reason((txn, bal))
|
|
95
|
+
req.status = {"approve": "approved", "confirm": "needs_confirmation",
|
|
96
|
+
"reject": "rejected"}[rv.decision]
|
|
97
|
+
req.verdict = rv.rationale
|
|
98
|
+
# 附证据链(可审计;新增字段,鸭子类型透传,不改既有行为)
|
|
99
|
+
try:
|
|
100
|
+
req.evidence = [e.to_dict() for e in rv.evidence]
|
|
101
|
+
req.reason_source = rv.source
|
|
102
|
+
except Exception:
|
|
103
|
+
pass
|
|
104
|
+
|
|
105
|
+
def _auto_record(self, task: str) -> str:
|
|
106
|
+
"""把「零星花钱报备」变成账本里的一笔,返回可读回执(不该记时返回空串)。
|
|
107
|
+
|
|
108
|
+
走内核的确定性解析:金额/币种/时间一旦由 LLM 转述就可能失真,
|
|
109
|
+
而这些数字会直接进预算与风控,错了不报错、只会安静地错。
|
|
110
|
+
"""
|
|
111
|
+
fin = getattr(self, "fin", None)
|
|
112
|
+
if fin is None or not _should_autorecord(task):
|
|
113
|
+
return ""
|
|
114
|
+
try:
|
|
115
|
+
rec = fin.record_text(task)
|
|
116
|
+
except Exception:
|
|
117
|
+
return "" # 记账失败不阻断对话,退回普通财务回答
|
|
118
|
+
if not rec.get("recorded"):
|
|
119
|
+
return ""
|
|
120
|
+
ack = rec.get("ack") or ""
|
|
121
|
+
self._think(content=f"记账 {len(rec['recorded'])} 笔:{ack[:120]}",
|
|
122
|
+
node_type="decision", conf=0.95)
|
|
123
|
+
try:
|
|
124
|
+
self._store_memory(
|
|
125
|
+
content=f"用户报备开销:{task[:80]}\n记账结果:{ack[:200]}",
|
|
126
|
+
mem_type="execution",
|
|
127
|
+
title=f"记账_{datetime.now().strftime('%Y%m%d')}",
|
|
128
|
+
tags=["finance", "ledger"],
|
|
129
|
+
)
|
|
130
|
+
except Exception:
|
|
131
|
+
pass # 记忆写入失败不影响账已经记上这件事
|
|
132
|
+
return ack
|
|
133
|
+
|
|
134
|
+
def analyze_finances(self, period: str = None, current_balance: float = None) -> dict:
|
|
135
|
+
"""调用财务内核做综合分析,并把关键洞察写入 ThoughtChain。"""
|
|
136
|
+
fin = getattr(self, "fin", None)
|
|
137
|
+
if fin is None:
|
|
138
|
+
return {"error": "财务内核未挂载"}
|
|
139
|
+
report = fin.analyze(period=period, current_balance=current_balance)
|
|
140
|
+
# 把守门人裁决写进推理链(受 Harness 监督)
|
|
141
|
+
verdicts = report.get("gatekeeper_verdicts", [])
|
|
142
|
+
self._think(
|
|
143
|
+
content=f"财务分析完成:{report['transaction_count']} 笔交易,"
|
|
144
|
+
f"{len(report.get('anomalies',[]))} 异常,{len(verdicts)} 条守门人裁决",
|
|
145
|
+
node_type="reflection", conf=0.9,
|
|
146
|
+
)
|
|
147
|
+
return report
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def _role_prompt(self) -> str:
|
|
151
|
+
return """你是 Foxclaw 的财务 Agent,专注于个人财务管理。
|
|
152
|
+
|
|
153
|
+
你的核心职责:
|
|
154
|
+
1. 追踪收入和支出记录
|
|
155
|
+
2. 分析消费模式,给出理财建议
|
|
156
|
+
3. 制定储蓄和投资计划
|
|
157
|
+
4. 提供财务报告和趋势分析
|
|
158
|
+
|
|
159
|
+
工作原则:
|
|
160
|
+
- 所有财务建议都基于用户的历史记录和明确说明的情况
|
|
161
|
+
- 保守稳健,不推荐高风险操作
|
|
162
|
+
- 尊重用户的财务隐私
|
|
163
|
+
- 记住用户的财务目标和偏好,越用越了解
|
|
164
|
+
|
|
165
|
+
注意:你只能访问财务相关的工具和数据,不能操作删除功能。"""
|
|
166
|
+
|
|
167
|
+
_task_entities = lambda self, task: ["财务", "收支", "储蓄"]
|
|
168
|
+
_recall_query = lambda self, task: f"财务 {task}"
|
|
169
|
+
|
|
170
|
+
async def _execute(self, task, context, session_id, memories):
|
|
171
|
+
# 第一线:零星花钱报备(「今天买了一件衣服花了 105 块」)。
|
|
172
|
+
# 解析→记账→回执全走确定性规则,不让 LLM 碰金额;回执本身就是答案,
|
|
173
|
+
# 没有分析意图时不必再等一次 LLM 往返。
|
|
174
|
+
ledger_ack = self._auto_record(task)
|
|
175
|
+
if ledger_ack and not _wants_advice(task):
|
|
176
|
+
return ledger_ack, {}
|
|
177
|
+
|
|
178
|
+
self._think(
|
|
179
|
+
content=f"财务分析:{task}",
|
|
180
|
+
node_type="reasoning",
|
|
181
|
+
conf=0.93,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
# 构建财务上下文
|
|
185
|
+
finance_context = ""
|
|
186
|
+
if memories:
|
|
187
|
+
finance_context = "历史财务记录:\n" + "\n".join([
|
|
188
|
+
_fmt_mem(m, 100) for m in memories[:5]
|
|
189
|
+
])
|
|
190
|
+
|
|
191
|
+
# 接入财务内核:若已挂载且有交易数据,做真实结构化分析,作为 LLM 的依据
|
|
192
|
+
kernel_insight = ""
|
|
193
|
+
fin = getattr(self, "fin", None)
|
|
194
|
+
if fin is not None and getattr(fin, "transactions", None):
|
|
195
|
+
try:
|
|
196
|
+
report = fin.analyze()
|
|
197
|
+
ec = report.get("evidence_chains", [])
|
|
198
|
+
anomalies = report.get("anomalies", [])
|
|
199
|
+
parts = []
|
|
200
|
+
for chain in ec:
|
|
201
|
+
parts.append(
|
|
202
|
+
f"· {chain['decision_type']}: 风险{chain['risk_score']}"
|
|
203
|
+
f"({chain['risk_level']}) — {chain.get('rationale','')};"
|
|
204
|
+
f"建议: {chain.get('recommended_action','')}")
|
|
205
|
+
if anomalies:
|
|
206
|
+
parts.append(f"· 检测到 {len(anomalies)} 笔异常支出")
|
|
207
|
+
if parts:
|
|
208
|
+
# 注:标签用产品级措辞(不带"内核"等内部实现词),避免 LLM 回复把内部
|
|
209
|
+
# 架构词汇透给终端用户(深层实现对用户保密;多 Agent 作卖点可讲)。
|
|
210
|
+
kernel_insight = ("\n\n【财务分析结果(基于真实交易,请据此回答)】\n"
|
|
211
|
+
+ "\n".join(parts))
|
|
212
|
+
# 把证据链摘要沉淀到 ThoughtChain(可审计)
|
|
213
|
+
self._think(
|
|
214
|
+
content=f"财务内核证据链:{len(ec)} 条决策,{len(anomalies)} 异常",
|
|
215
|
+
node_type="reflection", conf=0.9,
|
|
216
|
+
)
|
|
217
|
+
except Exception:
|
|
218
|
+
pass # 内核分析失败不阻断,降级为纯 LLM 回答
|
|
219
|
+
|
|
220
|
+
if ledger_ack:
|
|
221
|
+
# 已落账的明细必须交给 LLM:否则它会重复"确认记账",甚至自己再报一遍数字
|
|
222
|
+
kernel_insight = ("\n\n【刚刚已记账(已落账,请据此回答,不要重复报账)】\n"
|
|
223
|
+
+ ledger_ack + kernel_insight)
|
|
224
|
+
|
|
225
|
+
response = await self._call_llm_web(task, [{
|
|
226
|
+
"role": "user",
|
|
227
|
+
"content": f"""财务任务:{task}
|
|
228
|
+
|
|
229
|
+
{finance_context}{kernel_insight}
|
|
230
|
+
|
|
231
|
+
请提供专业的财务分析和建议。如果需要记录具体数字,请以结构化格式返回。"""
|
|
232
|
+
}])
|
|
233
|
+
|
|
234
|
+
self._think(
|
|
235
|
+
content=f"财务分析完成:{response[:150]}",
|
|
236
|
+
node_type="decision",
|
|
237
|
+
conf=0.90,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
# 记忆财务决策
|
|
241
|
+
self._store_memory(
|
|
242
|
+
content=f"财务分析:{task[:80]}\n结论:{response[:200]}",
|
|
243
|
+
mem_type="decision",
|
|
244
|
+
title=f"财务_{datetime.now().strftime('%Y%m%d')}",
|
|
245
|
+
tags=["finance", "analysis"],
|
|
246
|
+
)
|
|
247
|
+
return response, {}
|
|
248
|
+
|