AI Wiki中文/EN

协作智能体:通过公告、投标和合同分担工作

Cooperative agents

用合同网协议在目标一致的智能体之间分配任务,手算边际成本投标,并看到单任务转包为何会停滞,而捆绑合同能达到最优。

本页目录直觉理解数学与方法代码实现局限与误解实验与练习研究脉络

三辆货车、六件包裹、一张共同的账单

一家小公司有三辆送货车,分别停在同一条路上的不同仓库。今天要送六件包裹,所有行车费用都由公司承担。每位司机知道自己的车在哪里、已经要送哪些包裹,但没人有调度员的总览屏幕。包裹该怎么分?

这是一个协作智能体(cooperative agents)问题:多个决策者掌握不同的局部信息,却只有一个共同目标,这里是总行车距离。没有人能从隐瞒信息或替自己抢包裹中得到好处;难点纯粹在于协调。Shoham与Leyton-Brown把这类分布式问题求解与策略性情形分开:全局目标可以理解为大家共同的目标,也可以理解为构建了所有智能体的那位设计者的目标。协作式分布问题求解

一个经典答案是让智能体协商。Reid Smith的合同网协议(contract net protocol)于1980年12月发表在《IEEE计算机汇刊》(IEEE Transactions on Computers)上,它把任务分配变成类似市场的消息交换:有任务的一方发布公告,能完成的智能体投标,公告方授予合同。合同网协议 本文以这个协议为核心机制,在一个小例子上计算它的行为,并展示贪心签约在哪里留下了可节省的成本。自利投标者参与的拍卖、协商策略以及习得的协作(例如集中训练、分散执行)都是独立主题。

从共同目标到协商协议

设N为智能体集合,T为任务集合。分配σ给每个智能体i一个集合T_i(σ),c_i(S)是智能体i完成集合S的成本。在协作情形下,目标是总成本,而对再多一项任务t的自然投标就是边际成本:

C(σ)=∑i∈Nci(Ti(σ)),bi(t)=ci(Ti∪{t})−ci(Ti)C(\sigma)=\sum_{i\in N} c_i\big(T_i(\sigma)\big),\qquad b_i(t)=c_i\big(T_i\cup\{t\}\big)-c_i(T_i)

Shoham与Leyton-Brown描述的正是这种边际成本版本:每个智能体按把该任务加入现有集合所增加的成本投标,出价最低者获得任务,然后重复。他们还给出三点结论,决定了下文的一切。总存在某个合同序列能达到最优分配。如果只允许把一项任务从一个智能体移给另一个的简单合同,达到最优一般可能需要中途签订“亏钱”合同;按协作情形理解,就是不降低总成本的步骤。更丰富的合同——一捆任务(“簇合同”)、两个智能体之间的交换(“交换合同”)或多个智能体同时转移——可以避免这类步骤。这个过程还可以具有随时(anytime)性质:即使在达到最优前被中断,也可能已经比初始分配有明显改进。边际成本签约与合同类型

Smith的论文解释了为什么要把决策分散出去。在分布式问题求解中,没有哪个知识源掌握足以解决整个问题的信息,既没有全局控制也没有全局数据存储。有任务的节点必须找到合适的空闲节点——这就是Smith所说的“连接问题”,它有两个方面:平衡负载(资源分配)和选对任务与知识源(聚焦)。分布式问题求解与连接问题 他所说的协商有四个特征:它是局部过程;信息双向流动;各方从自己的角度评估信息;协议通过相互选择达成。

协议的消息承载着这种协商:

消息发送方Smith规范中的主要内容
任务公告管理者任务摘要、资格规范、投标规范、截止时间
投标潜在承包者节点摘要:按要求格式给出的、与任务相关的投标者能力
授予管理者开始工作所需的任务规范
报告/信息/终止任一方中间或最终结果、合同执行中的消息、取消合同及其分包

角色并非预先固定。任何节点都可以对一项任务担任管理者,同时对另一项任务担任承包者;承包者还可以拆分任务、把部分再转包出去,于是控制层级随问题伸缩。公告可以广播给所有节点、一个子集或单个节点(“定向寻址”),资格规范列出节点投标前必须满足的条件,从而剪除明显不可接受的投标、减少消息流量。消息类型与角色

Smith明确指出许多选择只是暂定的工程权衡。在他的CNET实现中,投标具有约束力,只有空闲节点才投标,每次机会只投一个标,因此一个节点可能收到多个授予并须排队处理;允许节点拒绝授予则要多付确认消息的代价。管理者一旦收到满意的投标就可以立即授予,不必等到截止时间。如果没有收到投标,管理者无法判断是所有节点都忙、任务排位太低,还是根本没有节点有能力完成;“即时响应投标”让节点回答BUSY、INELIGIBLE或LOW RANKING,以消除这种歧义。协商权衡与即时响应投标

对一项有|N|个潜在承包者的任务,一次广播公告、每个节点各一份投标、一次授予,消息数为

Mtask=1+∣N∣+1M_{\mathrm{task}}=1+|N|+1

前提是一次广播只算一条消息。定向寻址和资格规则能减少中间项;即时响应投标会增加它,但换来诊断信息。

协作假设是承重的。Shoham与Leyton-Brown强调,在这种情形下智能体不会为了私利偏离规定的投标规则,因此这些类拍卖程序对对抗性情形不作任何保证。协作假设 如果司机按件计酬,又能夸大成本来推掉工作,同样的消息就需要机制设计才能保持诚实。

现代语言模型智能体用自然语言消息而不是带槽位的结构化消息重新讨论协作。CAMEL的角色扮演框架让一个模型扮演发出指令的AI用户,另一个扮演作答的AI助手;消息历史M_t每轮增加一对“指令—解答”。开头固定的“起始提示”(inception prompts)规定角色、格式和任务结束标记,还可以加一个在多个提案中做选择的评审者。作者报告,在他们的人工评估中,经汇总的角色扮演解答比单次生成的gpt-3.5-turbo解答更受青睐(453份回答中76.3%对10.4%,平局13.3%),GPT-4评估也得到类似结论;这些是作者在其任务上报告的结果,不是本文的测量。他们还记录了槽位协议中不存在的失败方式:角色互换、重复指令、空头承诺和没完没了的客套循环。角色扮演及其失败方式

直线上的合同网,并与最优解对照

程序把三个仓库和六项任务放在一条路的整数位置上。一辆车完成一组任务的成本是一次往返,覆盖仓库和所有分配的点,即覆盖跨度的两倍。合同网按编号顺序公告任务,把每项任务授予边际成本最低的投标者,平局给编号较小者。随后两个修复阶段在某个移动能严格降低总成本时继续转包:一个只允许单任务转移,另一个还允许同一智能体持有的两项任务作为一捆一起转移,这是一种简单的簇合同。对全部3⁶=729种分配做穷举得到最优解。一切都是原创合成实例,智能体是脚本化的。

"""Original contract-net toy: three cooperative scripted agents share six delivery tasks.
Agents and tasks lie on a line; no market data, learning model, network or LLM is used."""
import itertools
import random
import statistics

AGENTS, TASKS = 3, 6


def tour_cost(base, points):
    """Leave base, visit every point on a line and return: twice the covered span."""
    if not points:
        return 0
    return 2 * (max(base, *points) - min(base, *points))


def total_cost(bases, tasks, owner):
    return sum(tour_cost(bases[i], [tasks[t] for t in range(len(tasks)) if owner[t] == i]) for i in range(len(bases)))


def contract_net(bases, tasks):
    """Announce tasks in index order; every agent bids its marginal cost; lowest bid wins."""
    owner, messages = [None] * len(tasks), 0
    for t in range(len(tasks)):
        bids = []
        for i in range(len(bases)):
            mine = [tasks[s] for s in range(len(tasks)) if owner[s] == i]
            bids.append((tour_cost(bases[i], mine + [tasks[t]]) - tour_cost(bases[i], mine), i))
        owner[t] = min(bids)[1]
        messages += 1 + len(bases) + 1  # one broadcast announcement, all bids, one award
    return owner, messages


def improve(bases, tasks, owner, max_bundle):
    """Re-contract while moving one bundle of up to max_bundle tasks, all held by one agent,
    to another agent strictly lowers total cost. Returns the allocation and contracts signed."""
    owner, contracts = owner[:], 0
    while True:
        current, best = total_cost(bases, tasks, owner), None
        for size in range(1, max_bundle + 1):
            for bundle in itertools.combinations(range(len(tasks)), size):
                if best is None and len({owner[t] for t in bundle}) == 1:
                    for i in range(len(bases)):
                        trial = [i if t in bundle else owner[t] for t in range(len(tasks))]
                        if i != owner[bundle[0]] and total_cost(bases, tasks, trial) < current:
                            best = trial
                            break
        if best is None:
            return owner, contracts
        owner, contracts = best, contracts + 1


def optimum(bases, tasks):
    return min(total_cost(bases, tasks, list(o)) for o in itertools.product(range(len(bases)), repeat=len(tasks)))


def instance(seed):
    rng = random.Random(seed)
    return [rng.randint(0, 20) for _ in range(AGENTS)], [rng.randint(0, 20) for _ in range(TASKS)]


if __name__ == '__main__':
    bases, tasks = [8, 1, 16], [15, 11, 13, 1, 4, 5]
    owner, messages = contract_net(bases, tasks)
    print('worked instance bases', bases, 'tasks', tasks)
    print('contract net owner', owner, 'cost', total_cost(bases, tasks, owner), 'messages', messages)
    print('optimum cost', optimum(bases, tasks))
    for size in (1, 2):
        better, contracts = improve(bases, tasks, owner, size)
        print(f'bundle size <= {size}: owner {better}, cost {total_cost(bases, tasks, better)}, contracts {contracts}')
    print('move task 1 alone', total_cost(bases, tasks, [2, 2, 0, 1, 1, 1]),
          'move task 2 alone', total_cost(bases, tasks, [2, 0, 2, 1, 1, 1]),
          'then task 1', total_cost(bases, tasks, [2, 2, 2, 1, 1, 1]))
    stats = {'contract_net': [], 'single_transfers': [], 'bundles_up_to_two': []}
    optimal = {key: 0 for key in stats}
    extra = {'single_transfers': [], 'bundles_up_to_two': []}
    for seed in range(300):
        bases, tasks = instance(seed)
        best = optimum(bases, tasks)
        greedy, _ = contract_net(bases, tasks)
        results = {'contract_net': (greedy, 0)}
        results['single_transfers'] = improve(bases, tasks, greedy, 1)
        results['bundles_up_to_two'] = improve(bases, tasks, greedy, 2)
        for key, (owner, contracts) in results.items():
            cost = total_cost(bases, tasks, owner)
            stats[key].append(cost - best)
            optimal[key] += cost == best
            if key in extra:
                extra[key].append(contracts)
    for key in stats:
        print(f'{key}: optimal {optimal[key]}/300, mean excess {statistics.mean(stats[key]):.3f}, '
              f'max excess {max(stats[key])}')
    for key in extra:
        print(f'{key}: mean extra contracts {statistics.mean(extra[key]):.3f}, max {max(extra[key])}')
    print('messages per task with 3 agents', 1 + AGENTS + 1)
记录的输出
worked instance bases [8, 1, 16] tasks [15, 11, 13, 1, 4, 5]
contract net owner [2, 0, 0, 1, 1, 1] cost 20 messages 30
optimum cost 18
bundle size <= 1: owner [2, 0, 0, 1, 1, 1], cost 20, contracts 0
bundle size <= 2: owner [2, 2, 2, 1, 1, 1], cost 18, contracts 1
move task 1 alone 28 move task 2 alone 20 then task 1 18
contract_net: optimal 278/300, mean excess 0.213, max excess 6
single_transfers: optimal 285/300, mean excess 0.140, max excess 6
bundles_up_to_two: optimal 295/300, mean excess 0.047, max excess 4
single_transfers: mean extra contracts 0.027, max 2
bundles_up_to_two: mean extra contracts 0.060, max 2
messages per task with 3 agents 5

手算一遍示例。仓库位于8、1、16;任务位于15、11、13、1、4、5。位于15的任务0以边际成本2交给位于16的车。位于11的任务1,对位于8的车增加6,对位于1的车增加20,对位于16的车增加8(其跨度从15–16扩大到11–16),所以位于8的车中标。位于13的任务2让位于8的车再增加4(跨度从8–11扩大到8–13),与位于16的车相同,平局给编号较小者。后三项任务交给位于1的车。总成本:10+8+2=20,用了6×5=30条消息。

最优值是18:位于16的车应包揽11、13、15三处的任务,位于8的车留在仓库。单任务转移到不了那里。只把任务1移给位于16的车,成本升到28,因为位于8的车仍要开到13。只移任务2,成本恰好仍是20——这是平台而不是改进,所以只接受严格改进的规则会停下。只有走完这一步横移之后,再移任务1才能到18。把任务1和任务2捆在一起转移的合同一步就把成本从20降到18。这正是教材所说的具体实例:单任务签约可能需要不改进的步骤,而更丰富的合同可以避免。

在300个随机实例上,纯合同网在278个实例中达到最优,比最优值平均多0.213个距离单位,最差多6。单任务转包把最优实例数提高到285(平均超出0.140),平均多签0.027份合同。允许两项任务成捆转移后,最优实例为295个,平均超出0.047,最差超出4,平均多签0.060份合同。仍有五个实例需要更大的捆或多个智能体同时转移。

贪心阶段对每项任务评估|N|份投标,这里每份耗时O(|T|),所以总计O(|T|²|N|)。一次扫描大小至多为k的成捆转移要检查O(|T|^k |N|)个候选;穷举最优需要|N|^|T|次评估,只因实例极小才可行。

协作签约在哪里失效

结果取决于公告顺序和平局打破方式。换一种公告顺序,就会改变哪个智能体先“锚定”某一区域,而协议本身并不保证好的顺序。真实部署还要面对截止时间、容量限制、并非直线的行车时间,以及在执行过程中不断出现的新任务。

实验假设成本信息完全准确、消息可靠且即时送达。在Smith的协议中,迟到的投标可能导致次优选择而不是错误,但丢失的授予或崩溃的承包者需要谨慎使用报告与终止机制。忙碌节点的约束性投标也可能让同时收到多个授予的节点过载。

协作是关于激励的假设,而不是协议的性质。如果智能体代表不同的所有者,边际成本投标可能被抬高,分配可能被操纵。语言模型“协作”智能体还多了一层问题:它们可能误解角色、自我重复或客套地循环,而由另一个模型做的评估可能带有那个模型的偏差。只要中央规划器可行,协作设计仍应与之比较。

练习

  1. 为什么Smith把签约描述为解决“连接问题”?它有哪两个方面?

    答案:有任务的节点必须找到合适的节点来执行,空闲节点也必须找到合适的任务;这种匹配就是连接问题。它的两个方面是资源分配,即在节点间平衡计算负载;以及聚焦,即选择合适的任务和知识源,避免把精力浪费在没有前途的工作上。

  2. 一个仓库位于0,其车已负责点2和6。它对位于9的任务和位于4的任务分别投多少边际成本?

    答案:当前成本为2×(6−0)=12。加入9后为2×(9−0)=18,投标为6。加入4时跨度0–6不变,投标为0。边际成本投标会奖励那些落在已有路线内部的任务。

  3. 在示例中,单独转移任务2后总成本仍为20。为什么只接受严格改进的规则会停在那里?给出两种跳出办法。

    答案:这一移动没有降低总成本,因而被拒绝,而其他单任务转移也都无益;当前分配是单任务转移意义下的局部最优。一种办法是接受不变差的移动,这样可以先移任务2、再移任务1,总成本达到18。另一种是用捆绑合同把任务1和任务2一起转移,一步完成改进。

  4. 同一公司的两个部门用合同网分担计算作业,但每个部门承接的作业会记到自己的预算上。情况有什么变化?复用协议前你会检查什么?

    答案:利益此时不再一致:某个部门可能报高价以逃避工作,或报低价以争取预算,所以边际成本投标不再可信。复用前应检查投标能否核实,支付规则能否让如实投标成为好策略(这是机制设计问题),以及使用经审计成本的中央调度器是否更简单。

阅读来源

Smith 1980年的论文短而具体;其中的分布式感知例子和对协商权衡的坦率讨论,至今对设计软件智能体之间委派机制的人仍有价值。The Contract Net Protocol Shoham与Leyton-Brown的2.3节把合同网与拍卖式优化联系起来,并解释了为何协作假设使他们可以暂时搁置博弈论。Multiagent Systems,2.3节 CAMEL是2023年语言模型智能体协作的一个例子,记录了具体的失败方式。CAMEL

开放问题包括:如何选择足够丰富又不至于让搜索爆炸的捆绑大小,如何在智能体中途失败时保持签约的稳健,以及如何用独立评审把协作LLM智能体与强单智能体基线进行比较。

先判断,再看解释

仓库在0,车已负责点2和6(成本12)。它对位于9的新任务的边际成本投标是多少?

选择一个答案

学习目标

  • 描述合同网的公告、投标、授予与报告,并手算共同目标下的边际成本投标与消息数。
  • 解释单任务转包为何会停在局部最优,比较捆绑合同与穷举最优,并说明协作假设何时失效。

先修与延伸

查看知识关联图 →

参考文献

  1. The Contract Net Protocol: High-Level Communication and Control in a Distributed Problem Solver — scoped course-hosted copy
    Reid G. Smith · 1980
  2. Multiagent Systems: Algorithmic, Game-Theoretic, and Logical Foundations — scoped free PDF, revision 1.1
    Yoav Shoham; Kevin Leyton-Brown · 2009
  3. CAMEL: Communicative Agents for “Mind” Exploration of Large Language Model Society — scoped arXiv v2
    Guohao Li; Hasan Abed Al Kader Hammoud; Hani Itani; Dmitrii Khizbullin; Bernard Ghanem · 2023

版本1 · 编写状态: 已完成记录中的技术复核

查看技术检查记录(AI)

Claude · 2026-12-02 · Independent AI check (Claude subagent, not the author; not a human or expert review). Ran example.py with python3 (0.4 s) and diffed it against example.stdout.txt (identical); confirmed byte-identical code blocks and identical display equations in both languages. Re-derived the whole worked instance by hand (bids 2; 6/20/8; tie 4/4 to the lower index; 2/14, 6/8, 2/6 for the last three tasks; total 20; single moves 28 and 20; optimum 18; 30 messages), the message formula and the exercise answers. Re-read the sources myself via pdftotext: Smith 1980 pp. 1104–1108 (course-hosted PDF), Shoham–Leyton-Brown §2.3.1 pp. 28–30, and CAMEL v2 pp. 8–9 (Section 5.1, Table 1). Compared zh and en section by section and checked data.json IDs. Did not read Smith pp. 1109–1113 or compare with IEEE Xplore, and did not render the MDX.

  • 代码输出一致,示例手算全部复核无误。
  • Smith论文中的连接问题、协商四要素、消息与权衡、即时响应投标均有原文支持。
  • CAMEL数字(453份回答,76.3%/10.4%/13.3%)与表1一致,并明确作为作者报告的结果呈现。
  • 教材关于随时性质和“亏钱”合同的表述原文较弱,文章已相应软化。

核对的来源位置:

  • The Contract Net Protocol: High-Level Communication and Control in a Distributed Problem Solver — scoped course-hosted copy · UCF course copy via pdftotext, journal pages 1104–1108: abstract and index terms; I Introduction (distributed problem solving: no global control or data; high-level protocol); II Connection and contract negotiation (connection problem = resource allocation + focus; four negotiation components; manager/contractor roles; subcontracting hierarchy; DCS comparison); III Example (DSS signal task, Figs. 1–3); IV.A.1–6 (announcement slots and addressing modes; common internode language; announcement processing; bidding by idle nodes; bid processing with immediate award; expiry options; award, report, information, termination; negotiation trade-offs: binding bids, multiple awards queued, refusal cost); IV.B.1 start (immediate response bids BUSY/INELIGIBLE/LOW RANKING). NOT read: pp.1109–1113, appendices A–E, results; not checked against IEEE Xplore. Checker re-downloaded the same 10-page PDF and re-read pp. 1104–1108 via pdftotext (raw and layout) on 2026-12-02, confirming: no global control or data; connection problem with resource allocation and focus; four negotiation components incl. mutual selection; general/limited broadcast and point-to-point (focused addressing); eligibility specification reduces traffic; late bids at worst give a suboptimal contractor choice; immediate award on a satisfactory bid; report/information/termination messages (termination also ends subcontracts); tentative negotiation trade-offs (binding bids, queued multiple awards, refusal costs acknowledgements, one bid per opportunity, only idle nodes bid); BUSY/INELIGIBLE/LOW RANKING immediate-response bids.
  • Multiagent Systems: Algorithmic, Game-Theoretic, and Logical Foundations — scoped free PDF, revision 1.1 · Free PDF rev. 1.1 via pdftotext (533 PDF pages): contents; Introduction pp. xiii–xvi (e-commerce agent example; loose definition 'diverging information or diverging interests, or both'; chapter overview and blocks); ch.1 p.1 (cooperative distributed problem solving, central-designer remark, sensor networks); §2.3.1 pp.28–30 (contract nets as framework; marginal-cost bids; existence of optimal contract sequence; money-losing single-task contracts; cluster/swap/multiagent contracts; anytime; bidding/clearing/information rules; no claim for adversarial settings); §7.1.3 pp.202–204 (Chicken teaching example, descriptive vs prescriptive, self-play, no procedure optimal vs all opponents); §7.2 pp.206–210 (fictitious play rule, prior sensitivity, Matching Pennies table, Thms 7.2.2–7.2.5, anti-coordination miscorrelation, Shapley game non-convergence). NOT read: other chapters, ABT details, proofs. Note: another 015k writer registered this same PDF as mas-ch3-normal-form-scoped-015k for chapter 3; scopes differ. Checker re-read §2.3.1 pp. 28–30 via pdftotext on 2026-12-02. The book says the process 'can have' an anytime property and 'can achieve significant improvements' if interrupted; the article's earlier stronger wording ('no worse than the start') and its gloss of money-losing contracts as steps that 'temporarily raise cost' were softened to match.
  • CAMEL: Communicative Agents for “Mind” Exploration of Large Language Model Society — scoped arXiv v2 · arXiv v2 PDF via pdftotext: p.1 (abstract, v2 date 2 Nov 2023, NeurIPS 2023 footer), p.2 (challenges: role flipping, assistant repeating instructions, flake replies, infinite loop; contributions), p.5 (AI user/assistant roles, Eq. 1–4 message set M_t, critic-in-the-loop, inception prompting P_T/P_A/P_U), p.7 (flake responses, 'Next request', <CAMEL_TASK_DONE> end token and the thank-you loop), p.9 (Table 1: AI Society human eval 13.3% draw / 10.4% gpt-3.5 / 76.3% CAMEL from 453 responses; GPT-4 eval 4.0/23.0/73.0; Code GPT-4 eval 0/24/76), p.28 (Appendix G challenge examples). NOT read: other appendices, Misalignment dataset, HumanEval results, code. Checker re-read pp. 8–9 (Section 5.1, Table 1) via pdftotext on 2026-12-02: 100 sampled AI Society tasks, CAMEL conversation summarized by GPT-4 vs gpt-3.5-turbo single shot, 453 human responses, 76.3/10.4/13.3; the article presents these only as the authors' reported results.

相关主题

没有匹配结果,试试英文名或缩写。

已显示 0 条结果

将整个查询放入双引号,可按短语匹配。