Community程式設計與開發github.com

bdi-mental-states

此技能應在用於以BDI概念(信念、願望、意圖、RDF到信念的轉換、理性主體軌跡、認知主體、BDI本體論及神經符號AI整合)建模主體心智狀態時使用。

bdi-mental-states 是什麼?

此技能提供了一個基於形式化BDI(信念-願望-意圖)本體論模式,將外部RDF上下文轉換為主體心智狀態(信念、願望、意圖)的框架。它使AI主體能夠透過認知架構推理上下文,支援深思熟慮的推理、可解釋性以及多主體系統中的語意互通性。該技能定義了核心概念,包括心智現實架構(將持久的心智狀態與暫時的心理過程分開)、認知鏈模式(將信念、願望和意圖連接成有向鏈)、世界狀態基礎(將心智狀態錨定在可查詢的參考上)以及T2B2T(三元組到信念到三元組)雙向管線。透過SPARQL範例與本體約束的整合,此技能特別適用於需要可追溯推理鏈、跨平台心智狀態協調以及神經符號AI整合的系統,例如數位助理、自主代理或決策支援系統。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/tree/main/skills/bdi-mental-states

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

BDI 心智狀態建模

使用形式化 BDI 本體模式,將外部 RDF 上下文轉換為代理的心智狀態(信念、願望、意圖)。此技能使代理能夠透過認知架構來推理上下文,支援深思熟慮的推理、可解釋性以及多代理系統中的語意互通性。

何時啟用

在以下情況啟用此技能:

  • 將外部 RDF 上下文處理為關於世界狀態的代理信念
  • 使用感知、深思和行動循環來建模理性代理
  • 透過可追溯的推理鏈來實現可解釋性
  • 實作 BDI 框架(SEMAS、JADE、JADEX)
  • 使用形式化認知結構來增強大型語言模型(邏輯增強生成)
  • 跨多代理平台協調心智狀態
  • 追蹤信念、願望和意圖的時間演化
  • 將動機狀態連結到行動計劃

不要將此技能用於由其他技能負責的相關工作:

  • 一般的上下文視窗解釋或注意力機制:請使用 context-fundamentals。
  • 沒有形式化 BDI 狀態的持久使用者、實體或對話記憶:請使用 memory-systems。
  • 監督者、群體或交接拓撲決策:請使用 multi-agent-patterns。
  • 一般的代理評估標準或品質門檻:請使用 evaluation。

核心概念

心智現實架構

將心智狀態分為兩個本體類別,因為 BDI 推理需要區分什麼是持久的、什麼是發生的:

心智狀態 (Endurants) — 將其建模為在時間區間內持續存在的持久認知屬性:

  • Belief:表示代理認為世界為真的事物。將每個信念都基於一個世界狀態參考。
  • Desire:表示代理希望實現的事物。將每個願望連結回其動機的信念。
  • Intention:表示代理承諾實現的事物。一個意圖必須實現一個願望並指定一個計劃。

心理過程 (Perdurants) — 將其建模為創建或修改心智狀態的事件,因為追蹤因果轉換可以實現可解釋性:

  • BeliefProcess:觸發感知形成的信念形成/更新。始終連接到生成的世界狀態。
  • DesireProcess:從現有信念生成願望。保留動機鏈。
  • IntentionProcess:將選定的願望承諾為可行動的意圖。

認知鏈模式

使用雙向屬性(motivates/isMotivatedBy、fulfils/isFulfilledBy)將信念、願望和意圖連接成有向鏈,因為這既可以實現正向推理(代理應該做什麼?),也可以實現反向追溯(代理為什麼這麼做?):

:Belief_store_open a bdi:Belief ;
    rdfs:comment "Store is open" ;
    bdi:motivates :Desire_buy_groceries .

:Desire_buy_groceries a bdi:Desire ;
    rdfs:comment "I desire to buy groceries" ;
    bdi:isMotivatedBy :Belief_store_open .

:Intention_go_shopping a bdi:Intention ;
    rdfs:comment "I will buy groceries" ;
    bdi:fulfils :Desire_buy_groceries ;
    bdi:isSupportedBy :Belief_store_open ;
    bdi:specifies :Plan_shopping .

世界狀態基礎

始終將心智狀態基於世界狀態參考,而不是自由文字描述,因為未經基礎的信念會破壞語意查詢和跨代理互通性:

:Agent_A a bdi:Agent ;
    bdi:perceives :WorldState_WS1 ;
    bdi:hasMentalState :Belief_B1 .

:WorldState_WS1 a bdi:WorldState ;
    rdfs:comment "Meeting scheduled at 10am in Room 5" ;
    bdi:atTime :TimeInstant_10am .

:Belief_B1 a bdi:Belief ;
    bdi:refersTo :WorldState_WS1 .

目標導向規劃

透過 bdi:specifies 將意圖連接到計劃,並使用 bdi:precedes 將計劃分解為有序任務序列,因為這種分離允許在不同意圖之間重用計劃,同時保持執行順序明確:

:Intention_I1 bdi:specifies :Plan_P1 .

:Plan_P1 a bdi:Plan ;
    bdi:addresses :Goal_G1 ;
    bdi:beginsWith :Task_T1 ;
    bdi:endsWith :Task_T3 .

:Task_T1 bdi:precedes :Task_T2 .
:Task_T2 bdi:precedes :Task_T3 .

T2B2T 範式

將三元組到信念再到三元組實作為雙向管線,因為代理必須同時消費外部 RDF 上下文並產生新的 RDF 斷言。將每個 T2B2T 實作結構化為兩個明確的階段:

第一階段:三元組到信念 — 將傳入的 RDF 三元組轉換為信念實例。使用 bdi:triggers 將外部世界狀態連接到 BeliefProcess,並使用 bdi:generates 產生結果信念。這可以保留從來源資料到內部認知的來源:

:WorldState_notification a bdi:WorldState ;
    rdfs:comment "Push notification: Payment request $250" ;
    bdi:triggers :BeliefProcess_BP1 .

:BeliefProcess_BP1 a bdi:BeliefProcess ;
    bdi:generates :Belief_payment_request .

第二階段:信念到三元組 — 在 BDI 深思選擇一個意圖並執行一個計劃後,使用 bdi:bringsAbout 將結果投射回 RDF。這可以閉合循環,使下游系統能夠將代理輸出作為標準連結資料消費:

:Intention_pay a bdi:Intention ;
    bdi:specifies :Plan_payment .

:PlanExecution_PE1 a bdi:PlanExecution ;
    bdi:satisfies :Plan_payment ;
    bdi:bringsAbout :WorldState_payment_complete .

按層級選擇表示法

根據正在建模的 C4 抽象層級選擇表示法,因為在錯誤的層級混合表示法會混淆而不是澄清認知架構:

C4 層級表示法心智狀態表示
L1 上下文ArchiMate代理邊界、外部感知來源
L2 容器ArchiMateBDI 推理引擎、信念儲存、計劃執行器
L3 元件UML心智狀態管理器、處理器
L4 程式碼UML/RDF信念/願望/意圖類別、本體實例

理由與可解釋性

使用 bdi:isJustifiedBy 將 bdi:Justification 實例附加到每個心智實體,因為未經證實的心智狀態會使代理推理不透明且無法追溯。每個理由應該捕捉產生該心智狀態的證據或規則:

:Belief_B1 a bdi:Belief ;
    bdi:isJustifiedBy :Justification_J1 .

:Justification_J1 a bdi:Justification ;
    rdfs:comment "Official announcement received via email" .

:Intention_I1 a bdi:Intention ;
    bdi:isJustifiedBy :Justification_J2 .

:Justification_J2 a bdi:Justification ;
    rdfs:comment "Location precondition satisfied" .

時間維度

使用 bdi:hasValidity 和 TimeInterval 實例為每個心智狀態指派有效區間,因為沒有時間邊界的信念在歷時推理過程中無法被垃圾回收或衝突檢查:

:Belief_B1 a bdi:Belief ;
    bdi:hasValidity :TimeInterval_TI1 .

:TimeInterval_TI1 a bdi:TimeInterval ;
    bdi:hasStartTime :TimeInstant_9am ;
    bdi:hasEndTime :TimeInstant_11am .

使用 SPARQL 時間過濾器查詢特定時刻活躍的心智狀態。當多個關於同一世界狀態的信念在時間上重疊時,使用此模式解決衝突:

SELECT ?mentalState WHERE {
    ?mentalState bdi:hasValidity ?interval .
    ?interval bdi:hasStartTime ?start ;
              bdi:hasEndTime ?end .
    FILTER(?start <= "2025-01-04T10:00:00"^^xsd:dateTime &&
           ?end >= "2025-01-04T10:00:00"^^xsd:dateTime)
}

組合式心智實體

使用 bdi:hasPart 關係將複雜信念分解為組成部分,因為整體式的信念在部分更新時需要完全替換。結構化組合信念,使每個子信念可以獨立地更新、查詢或失效:

:Belief_meeting a bdi:Belief ;
    rdfs:comment "Meeting at 10am in Room 5" ;
    bdi:hasPart :Belief_meeting_time , :Belief_meeting_location .

# 僅更新位置元件,不觸及時間
:BeliefProcess_update a bdi:BeliefProcess ;
    bdi:modifies :Belief_meeting_location .

實用指導

六個步驟建立 BDI 模型

在將外部語意上下文轉換為 BDI 表示時,請使用此工作流程:

  1. 定義世界狀態基礎:識別代理可以感知的外部事實或事件。在創建信念之前,先將其建模為世界狀態。
  2. 創建信念實例:將每個相關的世界狀態轉換為具有來源、時間有效性和理由參考的信念。
  3. 從信念推導願望:僅當信念創建了與目標相關的動機時才添加願望。將每個願望連結到其動機的信念。
  4. 深思熟慮地承諾意圖:僅當代理承諾執行計劃時,才將願望提升為意圖。記錄選定的計劃和前提條件。
  5. 將行動結果投射回三元組:執行後,將結果世界狀態作為 RDF 發出,以便下游系統可以消費新狀態。
  6. 使用能力問題驗證:在信任模型之前,查詢來源、動機、計劃順序和活躍有效區間。

保持本體精簡

從 Agent、WorldState、Belief、Desire、Intention、Plan、Task、Justification 和 TimeInterval 開始。僅在能力問題證明核心模型無法回答所需查詢時,才添加專門的類別。一個精簡的本體更容易序列化到提示詞中、更容易驗證,並且不太可能產生脆弱的推理鏈。

僅在心智狀態語意重要時使用 BDI

當系統需要可解釋的主體性時,BDI 建模是合理的:為什麼代理相信某事、該信念創建了什麼願望、選擇了哪個意圖以及執行了什麼計劃。如果系統只需要跨會話記住事實,請使用 memory-systems。如果只需要跨代理分割工作,請使用 multi-agent-patterns。

詳細主題

整合模式

邏輯增強生成 (LAG)

使用 LAG 以本體結構約束 LLM 輸出,因為無約束的生成會產生違反 BDI 類別限制的三元組。將本體序列化到提示上下文中,然後在接受生成的語句之前,根據它進行驗證:

def augment_llm_with_bdi_ontology(prompt, ontology_graph):
    ontology_context = serialize_ontology(ontology_graph, format='turtle')
    augmented_prompt = f"{ontology_context}\n\n{prompt}"

    response = llm.generate(augmented_prompt)
    triples = extract_rdf_triples(response)

    is_consistent = validate_triples(triples, ontology_graph)
    return triples if is_consistent else retry_with_feedback()

SEMAS 規則轉換

在部署到基於規則的代理平台時,將 BDI 本體模式轉換為可執行的生產規則。將每個認知鏈結點(信念到願望、願望到意圖)映射到一個 HEAD/CONDITIONALS/TAIL 規則,因為這在實現運行時執行的同時,保留了深思熟慮的語意:

% 信念觸發願望形成
[HEAD: belief(agent_a, store_open)] /
[CONDITIONALS: time(weekday_afternoon)] »
[TAIL: generate_desire(agent_a, buy_groceries)].

% 願望觸發意圖承諾
[HEAD: desire(agent_a, buy_groceries)] /
[CONDITIONALS: belief(agent_a, has_shopping_list)] »
[TAIL: commit_intention(agent_a, buy_groceries)].

指南

  1. 將世界狀態建模為獨立於代理觀點的配置,為心智狀態提供參考基礎。
  2. 區分持久項(持久的心智狀態)和過程項(暫時的心理過程),與 DOLCE 本體保持一致。
  3. 將目標視為描述而非心智狀態,保持認知層和規劃層之間的分離。
  4. 使用 hasPart 關係實現部分整體結構,從而實現選擇性的信念更新。
  5. 透過 atTime 或 hasValidity 將每個心智實體與時間結構關聯起來。
  6. 使用雙向屬性對(motivates/isMotivatedBy、generates/isGeneratedBy)以實現靈活的查詢。
  7. 將心智實體連結到 Justification 實例,以實現可解釋性和信任。
  8. 透過以下方式實作 T2B2T:(1) 將 RDF 翻譯為信念,(2) 執行 BDI 推理,(3) 將心智狀態投射回 RDF。
  9. 定義心理過程的存在限制(例如,BeliefProcess ⊑ ∃generates.Belief)。
  10. 重用既有的 ODP(EventCore、Situation、TimeIndexedSituation、BasicPlan、Provenance)以實現互通性。

能力問題

根據以下 SPARQL 查詢驗證實作:

# CQ1: 哪些信念促成了特定願望的形成?
SELECT ?belief WHERE {
    :Desire_D1 bdi:isMotivatedBy ?belief .
}

# CQ2: 特定意圖實現了哪個願望?
SELECT ?desire WHERE {
    :Intention_I1 bdi:fulfils ?desire .
}

# CQ3: 哪個心理過程產生了一個信念?
SELECT ?process WHERE {
    ?process bdi:generates :Belief_B1 .
}

# CQ4: 計劃中任務的有序序列是什麼?
SELECT ?task ?nextTask WHERE {
    :Plan_P1 bdi:hasComponent ?task .
    OPTIONAL { ?task bdi:precedes ?nextTask }
} ORDER BY ?task

範例

範例 1:RDF 通知到 BDI 鏈

輸入世界狀態:

:WorldState_invoice_due a bdi:WorldState ;
    rdfs:comment "Invoice INV-42 is due tomorrow" ;
    bdi:atTime :Time_2026_05_15 .

BDI 投射:

:Belief_invoice_due a bdi:Belief ;
    bdi:refersTo :WorldState_invoice_due ;
    bdi:isJustifiedBy :Justification_billing_system ;
    bdi:motivates :Desire_avoid_late_fee .

:Desire_avoid_late_fee a bdi:Desire ;
    bdi:isMotivatedBy :Belief_invoice_due .

:Intention_pay_invoice a bdi:Intention ;
    bdi:fulfils :Desire_avoid_late_fee ;
    bdi:specifies :Plan_pay_invoice .

範例 2:邊界決策

如果任務是「記住 Alice 偏好簡潔摘要」,請使用 memory-systems。如果任務是「表示為何...

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

advanced-evaluation

This skill should be used for advanced LLM evaluation: LLM-as-judge systems, direct scoring, pairwise comparison, rubric calibration, evaluator bias mitigation, confidence scoring, and automated quality assessment.

book-sft-pipeline

This skill should be used for book-to-SFT pipelines: ePub extraction, literary segmentation, author-voice dataset construction, style-transfer training, LoRA workflows, and model evaluation for voice replication.

compaction-control-profiling

This skill should be used when deciding, for a specific model and workload, whether the harness or the model should control compaction, and when qualifying or calibrating that choice with measurements: context-budget sweeps that compare harness-driven and model-driven compaction on one harness, the context-pressure regime where delegation pays, a per-model compaction behavior profile (interface uptake, compression factor per call, reopen rate of archived content, context fill at first compaction, response to pressure warnings), context anxiety and timing-instruction calibration, reversible collapse-and-archive interfaces, and re-qualification after a model or prompt change. Route the editable-file protocol, harness invariants, and edit-position cache cost of self-editing agents to self-managed-context, summary content to context-compression, harness thresholds and cache layout to context-optimization, and general evaluation design to evaluation.

comprehensive-research-agent

Ensure thorough validation, error recovery, and transparent reasoning in research tasks with multiple tool calls

context-compression

This skill should be used when long-running agent sessions need context compression, structured summarization, compaction, token-per-task optimization, or durable handoff summaries that preserve decisions, files, risks, and next actions.

context-degradation

This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion, attention-pattern issues, and agent performance degradation caused by accumulated or conflicting context.

context-fundamentals

This skill should be used to explain or reason about the foundational concepts of context engineering: what context is, the anatomy of a context window, how attention mechanics work, the U-shaped attention curve, why context quality matters more than quantity, and the mental models needed to interpret every other context-engineering decision. Use this for conceptual explanation, onboarding, and background reading. Route operational work to the specialized skills: debugging attention failures goes to context-degradation, token-efficiency work goes to context-optimization, conversation summarization goes to context-compression, and project-shape decisions go to project-development.

context-optimization

This skill should be used for improving context efficiency: context budgeting, observation masking, prefix or KV-cache strategy, partitioning, token-cost reduction, retrieval scoping, and extending effective context capacity without lowering answer quality.

evaluation

This skill should be used when building agent evaluation systems: deterministic checks, regression suites, multi-dimensional rubrics, quality gates, production monitoring, baseline comparison, and outcome measurement for agent pipelines.

filesystem-context

This skill should be used when agent work needs file-backed context: durable scratchpads, tool-output offloading, just-in-time discovery, cross-agent handoff files, filesystem memory, or cleanup policies for context stored outside the prompt.

harness-engineering

This skill should be used when designing autonomous agent harnesses: research loops, evaluation scaffolds, locked and editable surfaces, durable logs, novelty gates, pruning, rollback, PR preparation, and human approval boundaries.

hosted-agents

This skill should be used when designing hosted or background agent infrastructure: sandboxed execution, remote coding environments, warm pools, session persistence, multiplayer collaboration, self-spawning agents, or Modal-style sandboxes.

instruction-surface-security

Hardens agent runtimes against persistent prompt injection or unauthorized changes to instructions and permissions. Use to audit what agents auto-load, design reviewed activation for project rules, skills, memory, or tool configuration, and test whether trust boundaries hold after reload, restart, or delegation.

latent-briefing

This skill should be used when the user asks to "share memory between agents", "KV cache compaction for multi-agent", "orchestrator worker context", "latent briefing", "reduce worker tokens", "cross-agent memory without summarization", or discusses Attention Matching compaction, recursive language models with workers, or token explosion in hierarchical agents.

long-horizon-prompting

This skill should be used when writing, enhancing, or evaluating the launch prompt for a long-running autonomous agent or a parallel multi-agent orchestration attacking a hard problem: pseudo-formal task briefs that define terms and an exact success predicate linguistically, enumerate non-counting outcomes, set persistence rules with explicit stop and return conditions and effort floors, manage a diverse portfolio of parallel approaches with an approach registry and blocked-route bookkeeping, and gate the return on adversarial audit. Route agent topology and coordination protocols to multi-agent-patterns, runtime control surfaces and loop governance to harness-engineering, evaluator and quality-gate construction to evaluation, judge design to advanced-evaluation, and compaction or memory mechanics to context-compression and memory-systems.

memory-systems

This skill should be used for persistent semantic memory in agent systems: cross-session knowledge retention, entity tracking, temporal validity, graph or vector retrieval, memory consolidation, and memory benchmark selection. Route file-backed scratchpads to filesystem-context, handoff summaries to context-compression, and token-efficiency tactics to context-optimization.

multi-agent-patterns

This skill should be used when designing multi-agent systems that need context isolation, supervisor or swarm coordination, explicit handoffs, parallel execution, or a decision on whether multiple agents are justified.

project-development

This skill should be used for project-level decisions about LLM-powered systems: whether an LLM is the right primitive for the task at hand, the shape of a multi-stage batch or agent pipeline, token and cost estimation, choosing between single-agent and multi-agent at the project level, structured output design for downstream parsing, and structuring agent-assisted iteration. Use this when the unit of work is a whole project or a multi-stage pipeline. Route individual tool design to tool-design and individual skill-loading or context-budget tactics to context-optimization.

self-improvement-loops

This skill should be used when the harness, scaffold, workflow, or optimizer itself is the optimization target: recursive self-improvement (RSI) loops, meta-harnesses, self-improving harnesses that mine their own failures and propose bounded edits, evolutionary or population-based search over agent scaffolds, acceptance gates for self-modifying systems, and agentic context evolution where the mechanism that produces context is versioned and evolved. Route governance of a single autonomous loop (locked surfaces, durable logs, rollback, novelty gates, approval boundaries) to harness-engineering, measurement and quality-gate design to evaluation, judge design to advanced-evaluation, and remote sandbox infrastructure to hosted-agents.

self-managed-context

This skill should be used when a model gets read-write control over its own live context window instead of a harness-scheduled compaction policy: the context exposed as an editable file the model rewrites with code tools, model-driven eviction and in-place updates, the harness invariants that keep self-editing safe (pinned prefix, edit gate, edit receipts, budget readouts, rollback on overflow), the prefix-cache cost of mid-context edits, and steering or training the model's own context-editing strategy. Route note content and fixed-threshold summarization to context-compression, cache-stable layout under harness control to context-optimization, file offloading to filesystem-context, and loop governance to self-improvement-loops.

相關技能