agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
65 lines • 2.73 kB
JavaScript
;
/**
* Debate — two agents alternate proposing + critiquing, a judge decides.
*
* Paper: "Improving Factuality and Reasoning in Language Models through
* Multiagent Debate" — Du et al., 2023
* (https://arxiv.org/abs/2305.14325).
*
* Pattern: Factory → produces a `Runner` built from
* `Sequence(Proposer → Critic → Judge)` by default, or an
* iterated `Loop(Sequence(…))` when `rounds > 1`.
* Role: patterns/ layer.
* Emits: Everything Sequence + Loop + LLMCall emit.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.debate = void 0;
const LLMCall_js_1 = require("../core/LLMCall.js");
const Loop_js_1 = require("../core-flow/Loop.js");
const Sequence_js_1 = require("../core-flow/Sequence.js");
/**
* Build a Debate Runner. One debate "round" = Proposer → Critic. After
* N rounds, the Judge sees the final exchange and renders the verdict.
* The Judge's output is the Runner's return value.
*/
function debate(opts) {
const rounds = opts.rounds ?? 1;
if (rounds < 1) {
throw new Error('Debate: rounds must be >= 1');
}
const makeCall = (systemPrompt) => LLMCall_js_1.LLMCall.create({
provider: opts.provider,
model: opts.model,
...(opts.temperature !== undefined && { temperature: opts.temperature }),
...(opts.maxTokens !== undefined && { maxTokens: opts.maxTokens }),
})
.system(systemPrompt)
.build();
// A debate round: Proposer → pipeVia(transcript-to-critic) → Critic.
// The round's output is the critic's response; the next layer (Loop
// or the outer Sequence) decides how to frame it for the next
// consumer (another round or the Judge).
const buildRound = () => Sequence_js_1.Sequence.create({ id: 'debate-round' })
.step('proposer', makeCall(opts.proposerPrompt))
.pipeVia((proposalMsg) => ({
message: `A proposer argued:\n\n${proposalMsg}\n\nCritique this argument.`,
}))
.step('critic', makeCall(opts.criticPrompt))
.build();
// A full debate is: N rounds (via Loop) → Judge.
const roundsRunner = rounds === 1
? buildRound()
: Loop_js_1.Loop.create({ id: 'debate-rounds' }).repeat(buildRound()).times(rounds).build();
return Sequence_js_1.Sequence.create({
name: opts.name ?? 'Debate',
id: opts.id ?? 'debate',
})
.step('rounds', roundsRunner)
.pipeVia((transcript) => ({
message: `Full debate transcript:\n\n${transcript}\n\nGive your verdict.`,
}))
.step('judge', makeCall(opts.judgePrompt))
.build();
}
exports.debate = debate;
//# sourceMappingURL=Debate.js.map