Community编程与开发github.com

BDI 心理状态建模

该技能用于通过正式 BDI 本体模式将外部 RDF 上下文转换为智能体心理状态(信念、欲望、意图),支持理性推理、可解释性和多智能体系统中的语义互操作性。

BDI 心理状态建模 是什么?

该技能基于 BDI(信念-欲望-意图)架构,提供了一种形式化方法,用于构建和推理智能体的认知心理状态。它通过 RDF 三元组与信念之间的双向转换(T2B2T 范式),实现对外部语义上下文的感知、推理和行动。技能支持持久性心理状态(信念、欲望、意图)和临时性心理过程(信念过程、欲望过程、意图过程)的建模,并强调状态的可溯源性和可解释性,通过证明实例(Justification)和时间有效性区间(TimeInterval)确保推理链的透明。适用于需要理性代理、可解释 AI 和多智能体协作的场景,如 SEMAS 和 JADE 等框架。核心创新在于将本体论约束与 LLM 生成相结合(逻辑增强生成 LAG),并通过双向属性链(motivates/isMotivatedBy)实现前向推理和反向追踪。

兼容平台~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)
  • 使用形式化认知结构增强 LLM(逻辑增强生成)
  • 跨多智能体平台协调心理状态
  • 追踪信念、欲望和意图的时间演化
  • 将动机状态链接到行动计划

如果以下内容属于其他技能的职责范围,请勿激活此技能:

  • 通用上下文窗口解释或注意力机制:context-fundamentals
  • 没有正式 BDI 状态的持久用户、实体或会话记忆:memory-systems
  • 监管者、群体或交接拓扑决策:multi-agent-patterns
  • 通用智能体评估准则或质量门控:evaluation

核心概念

心理现实架构

将心理状态分为两个本体论类别,因为 BDI 推理需要区分什么是持久的和什么是发生的:

心理状态(大象限) -- 将这些建模为在时间间隔内持续的认知属性:

  • Belief:表示智能体认为世界为真的事物。将每个信念都植根于世界状态引用。
  • Desire:表示智能体希望实现的事物。将每个欲望链接回激发它的信念。
  • Intention:表示智能体承诺要实现的事物。意图必须满足一个欲望并指定一个计划。

心理过程(乍现体) -- 将这些建模为创建或修改心理状态的事件,因为追踪因果转变可以实现可解释性:

  • BeliefProcess:触发由感知产生的信念形成/更新。始终连接到生成的世界状态。
  • DesireProcess:从现有信念生成欲望。保留动机链。
  • IntentionProcess:将选定的欲望作为可行动的意图进行承诺。

认知链模式

将信念、欲望和意图通过双向属性(motivates/isMotivatedBy, fulfils/isFulfilledBy)连接成有向链,因为这既能支持前向推理(智能体应该做什么?),也能支持反向追溯(智能体为什么这样做?):

:Belief_store_open a bdi:Belief ;
    rdfs:comment "商店正在营业" ;
    bdi:motivates :Desire_buy_groceries .

:Desire_buy_groceries a bdi:Desire ;
    rdfs:comment "我想买杂货" ;
    bdi:isMotivatedBy :Belief_store_open .

:Intention_go_shopping a bdi:Intention ;
    rdfs:comment "我会去买杂货" ;
    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 "会议安排在上午10点,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 范式

实现三元组到信念再到三元组(Triples-to-Beliefs-to-Triples)的双向管道,因为智能体必须同时消耗外部 RDF 上下文并产生新的 RDF 断言。将每个 T2B2T 实现结构化为两个显式阶段:

阶段 1:三元组到信念 -- 将传入的 RDF 三元组转换为信念实例。使用 bdi:triggers 将外部世界状态连接到 BeliefProcess,并使用 bdi:generates 产生最终的信念。这保留了从源数据到内部认知的溯源关系:

:WorldState_notification a bdi:WorldState ;
    rdfs:comment "推送通知:付款请求 $250" ;
    bdi:triggers :BeliefProcess_BP1 .

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

阶段 2:信念到三元组 -- 在 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 "通过电子邮件收到的官方公告" .

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

:Justification_J2 a bdi:Justification ;
    rdfs:comment "位置前置条件满足" .

时间维度

使用 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 "上午10点 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 "发票 INV-42 明天到期" ;
    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.

相关技能