GenAgentEnsemble.Strategies.Consensus (gen_agent_ensemble v0.2.0)

Copy Markdown View Source

N peer agents deliberate on a prompt until they converge on a structured verdict, or the round cap is reached.

Each round fans the prompt out to every agent in parallel. Each agent's response is parsed by a user-supplied :verdict_parser into a categorical verdict atom plus rationale. If a threshold number of agents agree on the same verdict, the session converges. Otherwise, each agent is re-prompted with the other agents' responses as context and asked to revise or confirm its position.

Unparseable responses become abstains -- they don't count toward the threshold but don't block convergence either. The abstaining agent still participates in subsequent rounds.

Unlike GenAgentEnsemble.Strategies.Debate, Consensus's output is a programmable decision: the strategy holds a parsed verdict atom and the reply synthesizes it alongside per-agent rationales. This turns LLM deliberation into :approve | :revise | :reject that callers can branch on without re-parsing prose.

Options

  • :agents (required) -- list of {name, module, opts} specs, 2 or more. Names must be distinct.
  • :verdict_parser (required) -- (String.t() -> {:ok, atom, String.t()} | :error). Called on each agent's response text. The atom is the verdict category; the string is the rationale with verdict markers stripped.
  • :threshold (optional) -- convergence rule. Defaults to :majority.
    • :unanimous -- all parseable verdicts agree AND no abstains.
    • :majority -- more than N/2 agents agree on the same verdict.
    • {:at_least, n} -- at least n agents agree on the same verdict.
  • :rounds (optional) -- hard cap on rounds. Defaults to 3. Exceeding the cap returns a divergence report.
  • :reply (optional) -- response shape:
    • :synthesis (default) -- converged case: verdict + each agent's rationale. Diverged case: divergence report with each agent's final position.
    • {:synthesize, fun} -- call fun.(summary) where summary is %{status, verdict, rounds, threshold, responses}. responses is [{agent_name, verdict_or_nil, rationale, raw_text}, ...] in agent order; verdict is nil when diverged.

Concurrency

One consensus at a time per ensemble. Additional tell/ask calls queue FIFO and run after the current one completes.

Failure semantics

  • A turn error aborts the round: the token fails with {agent, reason}, any in-flight parallel responses are discarded, the next queued prompt (if any) starts.
  • Agent process death halts the session -- the panel size is fixed; a missing agent invalidates the threshold.