智能体通信:一条消息让发送者承担了什么?
Agent communication
区分言语行为类型、内容、本体与会话控制;追踪一次带截止时间的合同网协商,检查验证器能发现和不能发现的协议错误。
agent-communication“40”还不是一条消息
一个采购智能体需要翻译五页文件,五个由不同团队编写的供应商智能体收到请求。其中一个回复字符串“40”。这是报价、具有约束力的要约、带错误码的拒绝,还是“40分钟后再答复”?接收程序在弄清对方执行了哪一类行为、内容使用什么词汇、这条回复属于哪个会话之前,无法行动。
智能体通信语言(agent communication language)正是回答这些问题。它不会让智能体变聪明,而是把每句话的类型写明,使“我提议以40完成此事”和“我告知你价格是40”带来不同义务:提议一旦被接受,供应商就承诺执行;告知则没有这种承诺。
本文使用两套历史设计。KQML来自1990年代初ARPA知识共享计划,把任意内容包在ask-one、tell等施为词(performative)之中。KQML设计 FIPA规范于2002年定为标准,固定了一组消息参数,为每个通信行为给出形式化前提和预期效果,并定义了合同网(Contract Net)等交互协议。消息结构 行为库 合同网 随后我们运行一个原创、完全脚本化的合同网模拟:没有网络,没有语言模型,也不声称任何已部署系统如何运行。
一条消息的四层
KQML区分三件容易混在一起的事:内容,可用任何表示语言书写;施为词,说明内容是断言、查询还是命令,以及希望如何答复;可选的描述项,如内容语言与本体(ontology)。论文强调,KQML实现除了找出内容的起止位置外,不解析内容本身。其例子用ask-one向股票服务器询问价格;ask-all请求全部答案,stream-all请求逐条发送答案。论文把约两打保留施为词归为七类,并引入可以招募(recruit)、代理(broker)或推荐(recommend)其他智能体的协调者(facilitator)智能体。施为词与协调者
FIPA ACL保留同样的分离,但固定了参数名。消息结构规范列出五类共十三个参数:通信行为类型(performative);参与者(sender、receiver、reply-to);内容(content);内容描述(language、encoding、ontology);会话控制(protocol、conversation-id、reply-with、in-reply-to、reply-by)。只有performative是必需的。实现可以添加自定义参数,但名称必须以“X-”开头,FIPA不为其规定语义。无法处理某个参数的接收者可以回复not-understood。参数表
互操作最常在会话控制上出问题。protocol非空的消息属于一个会话:发起者必须分配conversation-id,协议内的回复应带相同值,reply-by表示发送者希望收到下一条消息的最晚时间,而不是整个协议的结束时间。会话标识必须全局唯一;规范建议把发送者的唯一名称与本地唯一计数拼接。多个对话同时进行时,reply-with与in-reply-to把回答与它所回答的那条消息对应起来;reply-by以发送者本地时钟表示。会话控制
意义来自通信行为库。每个行为有可行性前提FP,即发送者执行该行为时必须成立的条件;还有理性效果RE,即发送者意图达到、但无法保证的结果。以B表示相信,Bif表示“相信是否”,Uif表示“对是否不确定”,inform定义为:
第一个合取项是真诚性:i必须相信φ。第二个是相关性:若i已经认为j对此有定论,或认为j对此不确定,就不应再用inform;行为库把这些情形交给其他行为。第5.4节写道,若i认为j相信非φ,i应使用disconfirm;若j不确定,i应使用confirm,其FP为Biφ ∧ BiUjφ。收到inform后,j有理由相信i相信φ并希望j也相信;j是否真正接受φ,取决于它对i的信任。inform与confirm
因此理性效果是意图,不是后置条件。行为库用一个规划例子说明:询问别人是否在下雨,是获取该信息的合理方式,但提问者不能假定对方一定回答,因为对方是自主的。通信语义约束真诚、理性的发送者可以做什么,并不会迫使接收者服从。形式模型引言
行为库定义了二十二个行为,从accept-proposal到subscribe。实现了某个行为的智能体必须遵守其定义,但FIPA合规只要求实现not-understood。我们还注意到所读版本内部的不一致:request行为汇总表中FP的第三个合取项写作¬BiIjDone(a),第5.4.2节则写作Bi¬PGjDone(a)。本文不裁决此处差异;实现request语义的人应核对预期版本。request行为
交互协议把行为组织成会话。在FIPA合同网中,发起者向m个参与者发送征求提案cfp。每个参与者可以propose或refuse。截止时间(由reply-by携带)过后,发起者评估已到达的提案,向选中者发送accept-proposal,向其余者发送reject-proposal;迟到的提案以“迟到”为理由被拒绝。提案具有约束力:被接受后,参与者就承担执行任务的承诺,完成后用inform-done、inform-result报告,失败则发送failure。协议流程
截止时间之所以存在,是因为没有它,发起者无法知道何时已收齐回复,可能被无限期地挂起。not-understood可以出现在任何环节;在一对多协议中,应按参与者分别评估,而不是自动终止所有子会话。发起者也可以通过独立的取消元协议(cancel)终止交互,并沿用同一conversation-id。图与正文使用同一套计数:n个回复中j个是提案、i=n−j个是拒绝;j个提案中k个被拒绝、l=j−k个被接受。异常与取消
数消息能把协议成本具体化。设m为cfp数量,r为实际收到的回复(propose、refuse或not-understood),q为得到接受或拒绝答复的提案数(包括迟到的),w为被接受参与者发回的完成报告数:
我们的发起者只考虑截止时间T之前到达的提案:
最低价准则是我们的脚本选择;规范允许发起者优化价格、完成时间或任务的公平分配,也可以选择一个、多个或不选任何参与者。选择准则
追踪一次合同网并测试验证器
程序把每条消息表示为带有FIPA风格字段的字典。买方发出五条cfp,reply-by为10。参与者p1在时刻3提议40;p2在时刻2拒绝;p3提议35,但在时刻12才到达;p4在时刻4回复not-understood,代表它不支持该本体;p5始终不回复。验证器只检查能从轨迹中观察到的规则:有无施为词、发送者角色能否发送该行为、conversation-id是否匹配、in-reply-to是否指向确实发给该智能体的消息、该行为是否是对原消息的合法回复。
"""Original deterministic Contract Net simulation with FIPA-style message fields.
No network, no language model: every participant is a scripted rule."""
import json
PROTOCOL = 'fipa-contract-net'
ROLE_SENDS = {
'initiator': {'cfp', 'accept-proposal', 'reject-proposal', 'cancel', 'not-understood'},
'participant': {'propose', 'refuse', 'inform', 'failure', 'not-understood'},
}
ALLOWED_REPLIES = {
'cfp': {'propose', 'refuse', 'not-understood'},
'propose': {'accept-proposal', 'reject-proposal', 'not-understood'},
'accept-proposal': {'inform', 'failure', 'not-understood'},
'reject-proposal': set(),
}
def message(performative, sender, receiver, time, conversation_id='cn-1', **extra):
msg = dict(performative=performative, sender=sender, receiver=receiver, time=time,
protocol=PROTOCOL, conversation_id=conversation_id)
msg.update(extra)
return msg
def violations(trace, roles, conversation_id='cn-1'):
"""Return (index, reason) pairs for messages breaking the protocol rules used here."""
found, sent = [], {}
for index, msg in enumerate(trace):
act = msg.get('performative')
if not act:
found.append((index, 'missing performative'))
continue
role = roles.get(msg.get('sender'))
if act not in ROLE_SENDS.get(role, set()):
found.append((index, f'{role} may not send {act}'))
if msg.get('protocol') == PROTOCOL and msg.get('conversation_id') != conversation_id:
found.append((index, 'wrong or missing conversation-id'))
target = msg.get('in_reply_to')
if target is not None:
earlier = sent.get(target)
if earlier is None or earlier['receiver'] != msg['sender']:
found.append((index, 'in-reply-to names no message sent to this agent'))
elif act not in ALLOWED_REPLIES.get(earlier['performative'], set()):
found.append((index, f'{act} is not a reply to {earlier["performative"]}'))
if 'reply_with' in msg:
sent[msg['reply_with']] = msg
return found
def contract_net(bids, deadline=10, horizon=1000):
"""bids: name -> (kind, arrival_time, price). kind is propose/refuse/confused/silent."""
trace = [message('cfp', 'buyer', name, 0, reply_with=f'cfp-{name}', reply_by=deadline,
ontology='translation', content='translate 5 pages') for name in bids]
replies = []
for name, (kind, arrival, price) in bids.items():
if kind == 'silent':
continue
act = {'propose': 'propose', 'refuse': 'refuse', 'confused': 'not-understood'}[kind]
extra = {'content': price} if kind == 'propose' else {}
replies.append(message(act, name, 'buyer', arrival, in_reply_to=f'cfp-{name}',
reply_with=f'{act}-{name}', **extra))
replies.sort(key=lambda m: (m['time'], m['sender']))
trace.extend(replies)
close = deadline if deadline is not None else max([m['time'] for m in replies] + [horizon])
if deadline is None and any(kind == 'silent' for kind, _, _ in bids.values()):
return dict(trace=trace, winner=None, blocked=True, close_time=horizon)
on_time = [m for m in replies if m['performative'] == 'propose' and m['time'] <= close]
late = [m for m in replies if m['performative'] == 'propose' and m['time'] > close]
winner = min(on_time, key=lambda m: (m['content'], m['sender'])) if on_time else None
for m in on_time:
act = 'accept-proposal' if m is winner else 'reject-proposal'
trace.append(message(act, 'buyer', m['sender'], close, in_reply_to=m['reply_with'],
reply_with=f'{act}-{m["sender"]}', content=m['content']))
for m in late:
trace.append(message('reject-proposal', 'buyer', m['sender'], max(close, m['time']),
in_reply_to=m['reply_with'], reply_with=f'late-{m["sender"]}',
content='late'))
if winner:
trace.append(message('inform', winner['sender'], 'buyer', close + 5,
in_reply_to=f'accept-proposal-{winner["sender"]}', content='done'))
return dict(trace=trace, winner=winner['sender'] if winner else None,
price=winner['content'] if winner else None, blocked=False, close_time=close)
def inform_feasible(sender_believes_phi, view_of_receiver):
"""Operational inform precondition: B_i phi and not B_i(Bif_j phi or Uif_j phi)."""
return sender_believes_phi and view_of_receiver == 'unknown'
def suggested_act(sender_believes_phi, view_of_receiver):
if not sender_believes_phi:
return 'none'
return {'unknown': 'inform', 'uncertain': 'confirm', 'believes_not': 'disconfirm',
'believes': 'none'}[view_of_receiver]
BIDS = {'p1': ('propose', 3, 40), 'p2': ('refuse', 2, None), 'p3': ('propose', 12, 35),
'p4': ('confused', 4, None), 'p5': ('silent', None, None)}
ROLES = {'buyer': 'initiator', **{name: 'participant' for name in BIDS}}
if __name__ == '__main__':
run = contract_net(BIDS)
counts = {}
for m in run['trace']:
counts[m['performative']] = counts.get(m['performative'], 0) + 1
ignore_deadline = min((p, n) for n, (k, _, p) in BIDS.items() if k == 'propose')
bad = [
{k: v for k, v in run['trace'][5].items() if k != 'performative'},
message('accept-proposal', 'p1', 'buyer', 3),
message('propose', 'p1', 'buyer', 3, conversation_id='cn-9', in_reply_to='cfp-p1'),
message('propose', 'p2', 'buyer', 3, in_reply_to='cfp-p9'),
message('inform', 'p1', 'buyer', 3, in_reply_to='cfp-p1'),
]
detected = [violations(run['trace'][:5] + [b], ROLES)[-1:] for b in bad]
views = ['unknown', 'uncertain', 'believes_not', 'believes']
print(json.dumps(dict(
messages=len(run['trace']), by_performative=dict(sorted(counts.items())),
winner=run['winner'], price=run['price'], close_time=run['close_time'],
lowest_price_ignoring_deadline=dict(price=ignore_deadline[0], agent=ignore_deadline[1]),
clean_trace_violations=len(violations(run['trace'], ROLES)),
injected_errors_detected=sum(bool(d) for d in detected),
injected_error_reasons=[d[0][1] if d else None for d in detected],
no_deadline=dict((k, v) for k, v in contract_net(BIDS, deadline=None).items() if k != 'trace'),
inform_feasible={v: inform_feasible(True, v) for v in views},
suggested_act={v: suggested_act(True, v) for v in views},
sender_without_belief=suggested_act(False, 'unknown'),
), indent=2))
查看记录的输出
{
"messages": 12,
"by_performative": {
"accept-proposal": 1,
"cfp": 5,
"inform": 1,
"not-understood": 1,
"propose": 2,
"refuse": 1,
"reject-proposal": 1
},
"winner": "p1",
"price": 40,
"close_time": 10,
"lowest_price_ignoring_deadline": {
"price": 35,
"agent": "p3"
},
"clean_trace_violations": 0,
"injected_errors_detected": 5,
"injected_error_reasons": [
"missing performative",
"participant may not send accept-proposal",
"wrong or missing conversation-id",
"in-reply-to names no message sent to this agent",
"inform is not a reply to cfp"
],
"no_deadline": {
"winner": null,
"blocked": true,
"close_time": 1000
},
"inform_feasible": {
"unknown": true,
"uncertain": false,
"believes_not": false,
"believes": false
},
"suggested_act": {
"unknown": "inform",
"uncertain": "confirm",
"believes_not": "disconfirm",
"believes": "none"
},
"sender_without_belief": "none"
}轨迹共有十二条消息:五条cfp,四条已收到的回复(两条propose、一条refuse、一条not-understood),两条接受或拒绝答复,以及一条inform。这与m=5、r=4、q=2、w=1代入计数公式的结果一致。买方以40接受p1。p3的35更便宜,但在时刻12到达,晚于截止时刻10,因此收到内容为“late”的reject-proposal。忽略截止时间的买方会选p3;协议用较高价格换来了可预期的结束时间。
去掉截止时间后,结果发生质变。由于p5沉默,等待全部回复的发起者没有结束规则,到模拟上限1000个时间单位时仍被阻塞。这正是合同网规范用reply-by防范的故障。
验证器对生成的轨迹报告零个违规,并检出全部五个注入错误:缺少施为词、参与者发送accept-proposal、conversation-id错误、in-reply-to指向从未发给该智能体的消息、以及用inform回复cfp。前提表复现了inform的操作化规则:发送者真诚时,只有当它对接收者的状态没有任何信念时,inform才可行;接收者不确定时应使用confirm,被认为相信非φ时应使用disconfirm;不相信φ的发送者没有可用的真诚断言行为。
程序对每条消息只处理一次,所以验证时间与轨迹长度成线性关系,拍卖步骤最多排序m条回复。这些成本不涉及真实网络延迟、重试或消息丢失,它们都没有建模。
验证器检查形式,不检查真诚
程序中的每项检查都是语法或结构层面的。它能看出p1回复cfp时发送了propose,却无法判断p1是否真的相信自己能以40完成。inform的前提涉及发送者的信念,外部观察者无法检视黑盒智能体的信念。我们的inform_feasible函数之所以可行,只是因为我们直接把信念交给它。实际系统必须用可观察的东西替代心理状态语义:签名承诺、记录在案的义务、失败惩罚或声誉。
时间模型同样被理想化。reply-by按发送者时钟表示,平台间的时钟偏差可能让“按时”的消息在接收者看来已经迟到。真实传输会重复、乱序或丢失消息;至少一次投递要求以conversation-id和reply-with为键进行幂等处理。我们的模拟把每条非沉默消息恰好投递一次,并按时间戳排序。
共享本体是最难的一层。p4的not-understood只表示失败,并不修复失败。KQML和FIPA都把内容语言与本体留给另外的约定,因此两个都“使用FIPA ACL”的系统仍可能读不懂对方的内容。
最后,我们阅读的是2002年的FIPA标准和1994年的KQML论文。它们说明这些语言如何设计,不说明后来被采用的广度;本文不对当前平台支持情况作任何断言。
计数、分类与选择
-
FIPA ACL消息中只有performative是必需的。如果智能体参与协议时经常省略conversation-id,会出什么问题?
答案:规范要求,凡设置了protocol参数的消息都必须带非空conversation-id,且由发起者分配。缺少它时,同时进行多个合同网的智能体无法可靠地判断哪个提案回答哪次征求。省略“可由上下文推断”的参数是允许的,但不保证互操作。
-
发起者向六个参与者发送cfp。两个拒绝,一个沉默,三个提议,但其中一个提案在reply-by之后到达。唯一被接受的参与者后来报告failure。共交换多少条消息?
答案:m=6条cfp,r=5条已收到回复(两条refuse、三条propose),q=3条接受或拒绝答复(一条接受、一条按时拒绝、一条迟到拒绝),w=1条failure。N=6+5+3+1=15。沉默的参与者只贡献它收到的那条cfp。
-
智能体i相信φ,并认为j对φ不确定。i应该发送inform吗?如果i并不相信φ却被问到,又该如何?
答案:inform的FP不成立:i认为j对φ是否成立不确定,违反相关性条件;行为库把这种情形交给confirm,其FP为Biφ ∧ BiUjφ。若i不相信φ,inform和confirm的真诚性合取项都不成立。若i相信¬φ,inform-if允许它告知j¬φ;对φ没有知识的智能体会发送refuse。
-
你要连接两个由不同团队开发、会调用工具的软件智能体。一方建议使用自由文本聊天通道;另一方建议使用带conversation-id和reply-by的类型化施为词,但内容仍为自由格式。采购流程应选哪一种?还有什么没解决?
答案:选择类型化施为词和会话控制:它们让义务(propose与inform不同)、超时和回复匹配都能由机器检查,正如验证器所示。内容含义仍未解决:还需要约定价格与任务的模式或本体,并为承诺提供执行机制,因为协议无法验证真诚。
先读规范,再读轨迹
阅读KQML有助于理解为什么要把施为词层与内容、传输分开,以及为什么要引入协调者来定位智能体。KQML论文 FIPA消息结构固定了参数名和会话规则;参数 行为库提供形式语义,也暴露了自身的内部不一致;行为库 合同网是截止时间、约束性提案和异常处理的紧凑例子。合同网
评估现代智能体协议时,可以按同样顺序提问:执行的是哪种行为,它让发送者承担什么,回复如何与请求匹配,会话何时结束,谁能验证承诺。只回答前四个问题而不回答第五个的协议,只是消息格式,还算不上合同。
先判断,再看解释
合同网中某参与者在reply-by截止之后才提交了更低的报价,发起者按FIPA规范应如何处理?
学习目标
- 区分施为词、内容、内容语言/本体与会话控制参数,并解释FIPA通信行为的可行性前提与理性效果。
- 追踪带截止时间的合同网,计数消息,并说明协议验证器能检查与不能检查的内容。
先修与延伸
查看知识关联图 →参考文献
- KQML as an Agent Communication Language — scoped author preprint
Tim Finin; Richard Fritzson; Don McKay; Robin McEntire · 1994 - FIPA ACL Message Structure Specification SC00061G — scoped archived standard
Foundation for Intelligent Physical Agents (FIPA TC Communication) · 2002 - FIPA Communicative Act Library Specification SC00037J — scoped archived standard
Foundation for Intelligent Physical Agents (FIPA TC Communication) · 2002 - FIPA Contract Net Interaction Protocol Specification SC00029H — scoped archived standard
Foundation for Intelligent Physical Agents (FIPA TC Communication) · 2002
版本1 · 编写状态: 已完成记录中的技术复核
查看技术检查记录(AI)
Claude · 2026-12-02 · Independent AI check (Claude subagent, not the author); this is an automated AI technical check, not a human or expert review. Ran example.py with python3 and diffed it against example.stdout.txt (identical); confirmed the python block in en.mdx and zh.mdx is byte-identical to example.py; checked that display equations, source IDs, reference links and section anchors match across languages; recounted the trace (5 cfp + 4 replies + 2 accept/reject + 1 inform = 12) and exercise 2 (6+5+3+1=15). Re-read, via pdftotext, the UMBC KQML preprint (pp.1 and 4-5, performatives, ask-one/ask-all/stream-all, Figure 8, ARPA Knowledge Sharing Effort) and the three FIPA standards through the same Wayback snapshots the article links (fipa.org itself was not used): SC00061G sections 2-2.5.5, SC00037J sections 2.1, 3.5, 3.8, 3.9, 3.19, 5.1 and 5.4.1-5.4.4, and SC00029H sections 1-1.2 with the Figure 1 text labels. Not checked: KQML section 4 onward or the typeset CIKM version, other FIPA acts, the SL sections, and the Contract Net figure as an image.
- 重新核对FIPA行为库:request的FP在3.19为¬B<sub>i</sub>I<sub>j</sub>Done(a)、在5.4.2为B<sub>i</sub>¬PG<sub>j</sub>Done(a),差异真实存在;inform、confirm的FP与5.4.1“相信对方相信非φ则用disconfirm”的说法均与原文一致;合规只要求not-understood(2.1节)属实。
- 重读合同网规范第1.1节:图1标注j=n−i、k≤j、l=j−k与正文i=n−j表达同一计数关系,撰稿所称“不一致”并不存在,已改正;截止时间、迟到拒绝、约束性提案、not-understood按参与者评估和cancel元协议的表述均有原文支持。
- 核对ACL消息结构规范:13个参数五类、仅performative必需、X-前缀、protocol非空时的conversation-id规则、reply-by按发送者时钟、省略参数不保证互操作,均与原文一致;三个FIPA来源的URL与来源说明都写明是Wayback快照。
- 逐节比较中英文:论点、数字、练习与答案一致;本文范围停留在消息语义与会话控制,合同网只作为协议示例,未展开任务分配内容。
核对的来源位置:
- KQML as an Agent Communication Language — scoped author preprint · pdftotext of 8-page UMBC preprint: page 1 abstract/intro; section 3 pp.4–5 (extraction lines 225–330) read in full: content opaque to KQML, performative role, ask-one/ask-all/stream-all, Figure 8 two dozen performatives in seven categories, advertise/recruit. Facilitator figures 3–6 (recruit, broker, recommend) seen only via keyword lines. Not read: section 4 onward, published CIKM typeset version.
- FIPA ACL Message Structure Specification SC00061G — scoped archived standard · Wayback 20250104010524 PDF, pages 1–6 (doc lines 64–224) read in full: Table 1 thirteen parameters, mandatory performative, X- prefix, not-understood, protocol rules, conversation-id uniqueness, reply-with/in-reply-to, reply-by on sender clock. Not read: references (p.7) and change-log annex detail.
- FIPA Communicative Act Library Specification SC00037J — scoped archived standard · Wayback 20241005070724 PDF (45 pages): contents list of 22 acts; sec 2 (p.2) compliance only requires not-understood; 3.1 (p.3); 3.8 inform and 3.9 inform-if (pp.10–11); 3.19 request FP with ¬Bi Ij Done(a) (p.25); 5.1 (pp.30–31, Harry/Sally example paraphrased only); 5.4.1–5.4.3 (pp.35–36) inform/request with Bi¬PGj Done(a)/confirm FP. Not read: other acts, SL 5.2–5.3, 5.5–5.6.
- FIPA Contract Net Interaction Protocol Specification SC00029H — scoped archived standard · Wayback 20241205154809 PDF (9 pages): pages 1–3 lines 47–112 read in full; Figure 1 only as extracted text labels; start of Figure 2 cancel meta-protocol. Quote 'may potentially be left waiting indefinitely' (8 words) from 1.1. Not read: references, annex.
相关主题