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,367 @@
|
|
|
1
|
+
"""OfficeAgent —— 办公学习(学习/知识/文档/写作 + 日程/行程)。
|
|
2
|
+
|
|
3
|
+
Agent 拓扑收缩(5 → 3)后,原 `AdminAgent`(行政:日程/行程/会议)整块并入本 Agent:
|
|
4
|
+
· 行程内核 ItineraryRuntime 改由 `attach_itinerary` 挂载(与学习内核并列);
|
|
5
|
+
· `plan_itinerary / handle_cross_request / concede` 随之下沉到这里 —— 领域逻辑仍归
|
|
6
|
+
"离内核最近的那个 Agent",编排层不直接读 itinerary/learning 内核;
|
|
7
|
+
· `situation()` 改成一次自报**多个**领域(learning + itinerary),驾驶舱按 domains 聚合。
|
|
8
|
+
|
|
9
|
+
原行政 Agent 的角色行为(日程安排话术、时间偏好、冲突前置检查)已下放为指令技能
|
|
10
|
+
`skills/schedule-itinerary/SKILL.md`,由本 Agent 在命中触发词时自动注入 —— 不再需要一个
|
|
11
|
+
独立的行政 Agent 常驻。
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
|
|
17
|
+
from ..base import CognitiveAgent
|
|
18
|
+
from ._helpers import _fmt_mem
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class OfficeAgent(CognitiveAgent):
|
|
22
|
+
AGENT_ID = "office"
|
|
23
|
+
AGENT_NAME = "办公学习 Agent"
|
|
24
|
+
ALLOWED_TOOL_CATEGORIES = {"read", "write", "network", "calendar"}
|
|
25
|
+
|
|
26
|
+
# 日程类任务的触发词:命中则按"行政"话术走(不索要 knowledge JSON)。
|
|
27
|
+
# 与 skills/schedule-itinerary/SKILL.md 的 triggers 保持一致。
|
|
28
|
+
SCHEDULE_HINTS = ("日程", "行程", "会议", "出差", "预约", "日历", "路线", "几点", "提醒")
|
|
29
|
+
|
|
30
|
+
def attach_runtime(self, runtime):
|
|
31
|
+
"""挂载学习内核(LearningRuntime):间隔重复 + 知识图谱。"""
|
|
32
|
+
self.learn_rt = runtime
|
|
33
|
+
|
|
34
|
+
def attach_itinerary(self, runtime):
|
|
35
|
+
"""挂载行程内核(ItineraryRuntime):路线优化 + 可达性 + 守门人。
|
|
36
|
+
|
|
37
|
+
(原 AdminAgent.attach_runtime 的职责,随行政并入办公)
|
|
38
|
+
"""
|
|
39
|
+
self.itin = runtime
|
|
40
|
+
|
|
41
|
+
# ── 编排协作(P3:领域态势从编排层下沉至此)──────
|
|
42
|
+
def situation(self) -> dict:
|
|
43
|
+
"""一次自报两个领域:学习 + 行程。编排层按 `domains` 聚合(缺一个不影响另一个)。"""
|
|
44
|
+
return {"domains": {"learning": self._learning_status(),
|
|
45
|
+
"itinerary": self._itinerary_status()},
|
|
46
|
+
"alerts": self._learning_alerts() + self._itinerary_alerts()}
|
|
47
|
+
|
|
48
|
+
def _learning_status(self) -> dict:
|
|
49
|
+
rt = getattr(self, "learn_rt", None)
|
|
50
|
+
if rt is None:
|
|
51
|
+
return {}
|
|
52
|
+
try:
|
|
53
|
+
states = list(rt.review_states.values())
|
|
54
|
+
due = rt.sr.due_items(states)
|
|
55
|
+
risky = rt.sr.forgetting_risk(states)
|
|
56
|
+
except Exception:
|
|
57
|
+
due = risky = []
|
|
58
|
+
return {"total_items": len(rt.items), "due_today": len(due), "at_risk": len(risky)}
|
|
59
|
+
|
|
60
|
+
def _learning_alerts(self) -> list:
|
|
61
|
+
st = self._learning_status()
|
|
62
|
+
return ([{"domain": "learning", "severity": "info",
|
|
63
|
+
"msg": f"{st['at_risk']} 个知识点高遗忘风险待复习"}] if st.get("at_risk") else [])
|
|
64
|
+
|
|
65
|
+
def _itinerary_status(self) -> dict:
|
|
66
|
+
rt = getattr(self, "itin", None)
|
|
67
|
+
if rt is None:
|
|
68
|
+
return {}
|
|
69
|
+
try:
|
|
70
|
+
conflicts = rt.reasoning.detect_conflicts(rt.waypoints)
|
|
71
|
+
except Exception:
|
|
72
|
+
conflicts = []
|
|
73
|
+
return {"waypoints": len(rt.waypoints), "conflicts": len(conflicts)}
|
|
74
|
+
|
|
75
|
+
def _itinerary_alerts(self) -> list:
|
|
76
|
+
rt = getattr(self, "itin", None)
|
|
77
|
+
if rt is None:
|
|
78
|
+
return []
|
|
79
|
+
try:
|
|
80
|
+
conflicts = rt.reasoning.detect_conflicts(rt.waypoints)
|
|
81
|
+
except Exception:
|
|
82
|
+
conflicts = []
|
|
83
|
+
return [{"domain": "itinerary", "severity": "critical", "msg": c["reason"]}
|
|
84
|
+
for c in conflicts]
|
|
85
|
+
|
|
86
|
+
# ── 行程/日程(原 AdminAgent)────────────────────────────────
|
|
87
|
+
# 差旅预算让步:每轮降一档;低于原始的 60% 就不再让(那已不是同一趟出差了,
|
|
88
|
+
# 硬压下去只会规划出一个没法执行的行程 —— 宁可认输转由人决定)。
|
|
89
|
+
CONCEDE_STEP = 0.75 # 每轮降到上一轮的 75%(改高铁/换酒店/减一天的量化近似)
|
|
90
|
+
CONCEDE_FLOOR = 0.60 # 相对**原始**申请额的下限
|
|
91
|
+
|
|
92
|
+
def concede(self, req, verdict: str):
|
|
93
|
+
"""【协商闭环·发起方】差旅预算被财务守门人拒 → 降标准重报。
|
|
94
|
+
|
|
95
|
+
只处理自己发起的 budget_request;其余回退默认(不让步)。
|
|
96
|
+
每轮必须**真降**,且有下限 —— 否则会无限贴着守门人的红线来回试探。
|
|
97
|
+
"""
|
|
98
|
+
if req.request_type != "budget_request":
|
|
99
|
+
return super().concede(req, verdict)
|
|
100
|
+
try:
|
|
101
|
+
amount = float(req.payload.get("amount") or 0)
|
|
102
|
+
except (TypeError, ValueError):
|
|
103
|
+
return None
|
|
104
|
+
if amount <= 0:
|
|
105
|
+
return None
|
|
106
|
+
original = float(req.payload.get("_original_amount") or amount)
|
|
107
|
+
# 降一档,但**夹到下限**而不是跌破就放弃 —— 否则步长过冲时会在下限之上提前认输
|
|
108
|
+
# (8000→6000→(4500 破线)放弃),白白浪费 4800 这个本来能过的方案。
|
|
109
|
+
new_amount = max(round(amount * self.CONCEDE_STEP), round(original * self.CONCEDE_FLOOR))
|
|
110
|
+
if new_amount <= 0 or new_amount >= amount:
|
|
111
|
+
return None # 已到下限,再降就破线 → 认输(维持 rejected,不硬闯)
|
|
112
|
+
p = dict(req.payload)
|
|
113
|
+
p["amount"] = new_amount
|
|
114
|
+
p["_original_amount"] = original
|
|
115
|
+
p["_concession"] = f"降标准:{amount:.0f} → {new_amount:.0f}"
|
|
116
|
+
return p
|
|
117
|
+
|
|
118
|
+
def handle_cross_request(self, req) -> None:
|
|
119
|
+
"""日程占用申请 → 行程守门人检查冲突。"""
|
|
120
|
+
if req.request_type != "schedule_request":
|
|
121
|
+
return super().handle_cross_request(req)
|
|
122
|
+
rt = getattr(self, "itin", None)
|
|
123
|
+
if rt is None:
|
|
124
|
+
req.status = "approved"; req.verdict = "行程内核未挂载,默认放行"; return
|
|
125
|
+
new_time = req.payload.get("start_time")
|
|
126
|
+
conflict = False
|
|
127
|
+
if new_time:
|
|
128
|
+
from datetime import datetime as _dt
|
|
129
|
+
nt = _dt.fromisoformat(new_time)
|
|
130
|
+
for wp in rt.waypoints:
|
|
131
|
+
if wp.dt and abs((wp.dt - nt).total_seconds()) < 3600:
|
|
132
|
+
conflict = True
|
|
133
|
+
break
|
|
134
|
+
if conflict:
|
|
135
|
+
req.status = "needs_confirmation"
|
|
136
|
+
req.verdict = "该时段附近已有行程,可能冲突,需确认"
|
|
137
|
+
else:
|
|
138
|
+
req.status = "approved"
|
|
139
|
+
req.verdict = "时段空闲,日程可安排"
|
|
140
|
+
|
|
141
|
+
def plan_itinerary(self, mode: str = "driving") -> dict:
|
|
142
|
+
"""调用行程内核做规划,关键洞察写入 ThoughtChain。"""
|
|
143
|
+
rt = getattr(self, "itin", None)
|
|
144
|
+
if rt is None:
|
|
145
|
+
return {"error": "行程内核未挂载"}
|
|
146
|
+
report = rt.plan(mode=mode)
|
|
147
|
+
opt = report.get("optimized_route") or {}
|
|
148
|
+
self._think(
|
|
149
|
+
content=f"行程规划:{report['waypoint_count']} 个点,"
|
|
150
|
+
f"最优路线 {opt.get('total_km','?')} km / {opt.get('total_min','?')} 分钟,"
|
|
151
|
+
f"{len(report['conflicts'])} 个冲突,"
|
|
152
|
+
f"高德={'已接入' if report['amap_enabled'] else '估算模式'}",
|
|
153
|
+
node_type="reflection", conf=0.9,
|
|
154
|
+
)
|
|
155
|
+
return report
|
|
156
|
+
|
|
157
|
+
# ── 学习/知识(原 OfficeAgent)────────────────────────────────
|
|
158
|
+
@staticmethod
|
|
159
|
+
def _strip_knowledge_json(text: str) -> str:
|
|
160
|
+
"""从回复中剥离 {"new_knowledge": [...]} 结构化块,只保留自然语言。"""
|
|
161
|
+
if not text or "new_knowledge" not in text:
|
|
162
|
+
return text
|
|
163
|
+
import re
|
|
164
|
+
# 去掉 {"new_knowledge": [ ... ]} 整块(含可能的 markdown 代码围栏)
|
|
165
|
+
cleaned = re.sub(r'`{0,3}\s*\{\s*"new_knowledge".*?\}\s*\]\s*\}\s*`{0,3}',
|
|
166
|
+
'', text, flags=re.DOTALL)
|
|
167
|
+
return cleaned.strip()
|
|
168
|
+
|
|
169
|
+
def analyze_learning(self) -> dict:
|
|
170
|
+
"""调用学习内核做综合分析,关键洞察写入 ThoughtChain。"""
|
|
171
|
+
rt = getattr(self, "learn_rt", None)
|
|
172
|
+
if rt is None:
|
|
173
|
+
return {"error": "学习内核未挂载"}
|
|
174
|
+
report = rt.analyze()
|
|
175
|
+
# 给前端「知识库」轮播提供知识条目明细:analyze 本身只有统计、无明细,
|
|
176
|
+
# 否则前端读 analysis.items 拿不到 → 一直显示"知识库为空"(即便已录入)。
|
|
177
|
+
try:
|
|
178
|
+
with rt._lock:
|
|
179
|
+
_vals = list(rt.items.values())
|
|
180
|
+
report["items"] = [
|
|
181
|
+
{"title": (it.content or "")[:40], "content": it.content,
|
|
182
|
+
"topic": it.topic, "tag": it.topic, "source": it.source,
|
|
183
|
+
"tags": it.tags, "id": it.id, "notes": getattr(it, "notes", [])}
|
|
184
|
+
for it in reversed(_vals)
|
|
185
|
+
][:30]
|
|
186
|
+
except Exception:
|
|
187
|
+
report.setdefault("items", [])
|
|
188
|
+
self._think(
|
|
189
|
+
content=f"学习分析:{report['total_items']} 个知识点,"
|
|
190
|
+
f"平均掌握度 {report['avg_mastery']},"
|
|
191
|
+
f"{report['due_today']} 个待复习,"
|
|
192
|
+
f"图谱 {report['graph']['clusters']} 个知识簇",
|
|
193
|
+
node_type="reflection", conf=0.9,
|
|
194
|
+
)
|
|
195
|
+
return report
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def _role_prompt(self) -> str:
|
|
199
|
+
return """你是 Foxclaw 的办公学习 Agent,专注于办公、学习与日程安排。
|
|
200
|
+
|
|
201
|
+
你的核心职责:
|
|
202
|
+
1. 帮助用户学习新知识和技能
|
|
203
|
+
2. 管理知识储备,建立个人知识库
|
|
204
|
+
3. 处理文档、报告和写作任务
|
|
205
|
+
4. 跟踪学习进度和知识演化
|
|
206
|
+
5. 安排日程、会议与出行行程,检查时间冲突
|
|
207
|
+
|
|
208
|
+
Hermes 自学原则(像赫尔墨斯那样):
|
|
209
|
+
- 不是学习更多技能,而是通过每次交互变得更"智能"
|
|
210
|
+
- 记住用户的学习风格和偏好
|
|
211
|
+
- 识别知识缺口,主动补充
|
|
212
|
+
- 建立知识间的连接,而不只是存储孤立事实
|
|
213
|
+
- 每次对话都让知识库更丰富、更有组织
|
|
214
|
+
|
|
215
|
+
日程/行程原则:
|
|
216
|
+
- 主动记住用户的时间偏好(如不喜欢早 8 点前的会议)
|
|
217
|
+
- 排期前先查已有行程,提前发现冲突
|
|
218
|
+
- 差旅预算议题与财务协商时,一轮一降、有下限,不硬闯
|
|
219
|
+
|
|
220
|
+
你的知识是活的,会生长的。"""
|
|
221
|
+
|
|
222
|
+
_task_entities = lambda self, task: ["学习", "知识", "文档", "日程", "行程", "会议"]
|
|
223
|
+
_recall_topk = 8 # 办公学习 Agent 广泛召回
|
|
224
|
+
|
|
225
|
+
def _recall_query(self, task: str) -> str:
|
|
226
|
+
"""学习 + 日程两类记忆都要召回(合并后单一 Agent 覆盖两个域)。"""
|
|
227
|
+
return f"学习 知识 日程 行程 {task}"
|
|
228
|
+
|
|
229
|
+
def _is_schedule_task(self, task: str) -> bool:
|
|
230
|
+
return any(k in (task or "") for k in self.SCHEDULE_HINTS)
|
|
231
|
+
|
|
232
|
+
async def _execute(self, task, context, session_id, memories):
|
|
233
|
+
schedule = self._is_schedule_task(task)
|
|
234
|
+
self._think(
|
|
235
|
+
content=(f"{'日程/行程' if schedule else '知识'}任务:{task},"
|
|
236
|
+
f"已有相关记忆:{len(memories)} 条"),
|
|
237
|
+
node_type="reasoning",
|
|
238
|
+
conf=0.92,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
knowledge_context = ""
|
|
242
|
+
if memories:
|
|
243
|
+
knowledge_context = "相关知识储备:\n" + "\n".join([
|
|
244
|
+
f"- {_fmt_mem(m, 80)}" for m in memories[:6]
|
|
245
|
+
])
|
|
246
|
+
|
|
247
|
+
# 接入学习内核:若已挂载且有知识点,做真实分析(待复习/掌握度)作为依据
|
|
248
|
+
kernel_insight = ""
|
|
249
|
+
learn_rt = getattr(self, "learn_rt", None)
|
|
250
|
+
if learn_rt is not None and getattr(learn_rt, "items", None):
|
|
251
|
+
try:
|
|
252
|
+
report = learn_rt.analyze()
|
|
253
|
+
due = report.get("due_today", 0)
|
|
254
|
+
mastery = report.get("avg_mastery", 0)
|
|
255
|
+
kernel_insight += (
|
|
256
|
+
f"\n\n【学习状态(基于真实知识库)】\n"
|
|
257
|
+
f"· 知识点总数: {report.get('total_items', 0)}\n"
|
|
258
|
+
f"· 平均掌握度: {mastery}\n"
|
|
259
|
+
f"· 今日待复习: {due} 个")
|
|
260
|
+
self._think(
|
|
261
|
+
content=f"学习内核:{report.get('total_items',0)} 知识点,{due} 待复习",
|
|
262
|
+
node_type="reflection", conf=0.9,
|
|
263
|
+
)
|
|
264
|
+
except Exception:
|
|
265
|
+
pass # 内核失败不阻断,降级纯 LLM
|
|
266
|
+
|
|
267
|
+
# 接入行程内核:若已挂载且有路点,做真实规划(路线/冲突)作为 LLM 依据
|
|
268
|
+
itin = getattr(self, "itin", None)
|
|
269
|
+
if itin is not None and getattr(itin, "waypoints", None):
|
|
270
|
+
try:
|
|
271
|
+
report = itin.plan()
|
|
272
|
+
opt = report.get("optimized_route") or {}
|
|
273
|
+
conflicts = report.get("conflicts", [])
|
|
274
|
+
parts = []
|
|
275
|
+
if opt:
|
|
276
|
+
parts.append(f"· 最优路线: {opt.get('total_km','?')}km / "
|
|
277
|
+
f"{opt.get('total_min','?')}分钟")
|
|
278
|
+
if conflicts:
|
|
279
|
+
parts.append(f"· 检测到 {len(conflicts)} 个日程冲突")
|
|
280
|
+
if parts:
|
|
281
|
+
kernel_insight += ("\n\n【行程分析结果(基于真实路点,请据此回答)】\n"
|
|
282
|
+
+ "\n".join(parts))
|
|
283
|
+
self._think(
|
|
284
|
+
content=f"行程内核:路线已优化,{len(conflicts)} 个冲突",
|
|
285
|
+
node_type="reflection", conf=0.9,
|
|
286
|
+
)
|
|
287
|
+
except Exception:
|
|
288
|
+
pass # 内核失败不阻断,降级纯 LLM
|
|
289
|
+
|
|
290
|
+
if schedule:
|
|
291
|
+
prompt = f"""行程/日程任务:{task}
|
|
292
|
+
|
|
293
|
+
{knowledge_context}{kernel_insight}
|
|
294
|
+
|
|
295
|
+
请处理这个日程/行政任务,给出具体安排建议;有冲突就明说,别假装排开了。"""
|
|
296
|
+
else:
|
|
297
|
+
prompt = f"""学习/办公任务:{task}
|
|
298
|
+
|
|
299
|
+
{knowledge_context}{kernel_insight}
|
|
300
|
+
|
|
301
|
+
请:
|
|
302
|
+
1. 帮助完成这个学习/办公任务
|
|
303
|
+
2. 识别涉及的关键知识点
|
|
304
|
+
3. 指出哪些是新知识(需要记录)
|
|
305
|
+
|
|
306
|
+
回答后,以 JSON 格式附上需要记录的新知识:
|
|
307
|
+
{{"new_knowledge": [{{"title": "知识标题", "content": "知识内容", "tags": ["标签"]}}]}}"""
|
|
308
|
+
|
|
309
|
+
response = await self._call_llm_web(task, [{"role": "user", "content": prompt}])
|
|
310
|
+
|
|
311
|
+
new_knowledge_count = 0
|
|
312
|
+
if not schedule:
|
|
313
|
+
# 提取并存储新知识(括号平衡解析:正确处理内容含 []{} 的情况)
|
|
314
|
+
try:
|
|
315
|
+
start = response.find('{"new_knowledge"')
|
|
316
|
+
if start < 0:
|
|
317
|
+
start = response.find('{ "new_knowledge"')
|
|
318
|
+
if start >= 0:
|
|
319
|
+
# 从 start 起做花括号配对,找到完整 JSON 对象的结束位置
|
|
320
|
+
depth, end, in_str, esc = 0, -1, False, False
|
|
321
|
+
for i in range(start, len(response)):
|
|
322
|
+
c = response[i]
|
|
323
|
+
if esc:
|
|
324
|
+
esc = False; continue
|
|
325
|
+
if c == '\\':
|
|
326
|
+
esc = True; continue
|
|
327
|
+
if c == '"':
|
|
328
|
+
in_str = not in_str
|
|
329
|
+
elif not in_str:
|
|
330
|
+
if c == '{':
|
|
331
|
+
depth += 1
|
|
332
|
+
elif c == '}':
|
|
333
|
+
depth -= 1
|
|
334
|
+
if depth == 0:
|
|
335
|
+
end = i + 1; break
|
|
336
|
+
if end > start:
|
|
337
|
+
knowledge_data = json.loads(response[start:end])
|
|
338
|
+
for k in knowledge_data.get("new_knowledge", []):
|
|
339
|
+
if not isinstance(k, dict) or not k.get("content"):
|
|
340
|
+
continue
|
|
341
|
+
self._store_memory(
|
|
342
|
+
content=k["content"],
|
|
343
|
+
mem_type="concept",
|
|
344
|
+
title=k.get("title", "未命名知识"),
|
|
345
|
+
tags=k.get("tags", ["office", "learning"]),
|
|
346
|
+
)
|
|
347
|
+
new_knowledge_count += 1
|
|
348
|
+
except Exception:
|
|
349
|
+
pass # 解析失败不影响主流程
|
|
350
|
+
|
|
351
|
+
# 从返回文本中剥离 new_knowledge JSON 块(不展示给用户)
|
|
352
|
+
response = self._strip_knowledge_json(response)
|
|
353
|
+
|
|
354
|
+
self._think(
|
|
355
|
+
content=(f"日程安排完成:{response[:120]}" if schedule
|
|
356
|
+
else f"学习完成,新增知识 {new_knowledge_count} 条"),
|
|
357
|
+
node_type="reflection",
|
|
358
|
+
conf=0.90,
|
|
359
|
+
)
|
|
360
|
+
if schedule:
|
|
361
|
+
self._store_memory(
|
|
362
|
+
content=f"日程任务:{task[:80]}\n安排:{response[:200]}",
|
|
363
|
+
mem_type="execution",
|
|
364
|
+
title=f"日程_{datetime.now().strftime('%Y%m%d')}",
|
|
365
|
+
tags=["office", "schedule"],
|
|
366
|
+
)
|
|
367
|
+
return response, ({} if schedule else {"new_knowledge_stored": new_knowledge_count})
|