Skip to main content
Glama

consensus

Poll 3-7 models and aggregate responses using majority, supermajority, or unanimous voting. Returns consensus answer with confidence score.

Instructions

Query 3-7 models and aggregate responses using voting strategy (majority/supermajority/unanimous). Returns consensus answer with confidence score.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelsYesList of model IDs to poll (3-7 models)
promptYesThe prompt to send to all models
strategyNoVoting strategy — how many models must agreemajority
judge_modelNoOptional model ID to use as judge. Auto-picks if not specified.
system_promptNo
temperatureNo
max_tokensNo

Implementation Reference

  • src/server.ts:144-165 (registration)
    Registration of the 'consensus' tool with the MCP server, including its description, schema, and handler binding.
    // --- consensus ---
    server.tool(
      "consensus",
      "Query 3-7 models and aggregate responses using voting strategy (majority/supermajority/unanimous). Returns consensus answer with confidence score.",
      consensusSchema.shape,
      async (input) => {
        logger.info(
          `consensus: polling ${input.models.length} models (${input.strategy})`
        );
        try {
          const result = await consensus(provider, input);
          return { content: [{ type: "text" as const, text: result }] };
        } catch (err) {
          const message = err instanceof Error ? err.message : String(err);
          logger.error(`consensus failed: ${message}`);
          return {
            content: [{ type: "text" as const, text: `Error: ${message}` }],
            isError: true,
          };
        }
      }
    );
  • Main handler function 'consensus' that polls multiple models, determines agreement via a judge model (or keyword fallback), and returns a consensus result.
    export async function consensus(
      provider: Provider,
      input: ConsensusInput
    ): Promise<string> {
      // Query all models in parallel
      const results = await Promise.allSettled(
        input.models.map((model) =>
          provider.query(model, input.prompt, {
            system_prompt: input.system_prompt,
            temperature: input.temperature,
            max_tokens: input.max_tokens,
          })
        )
      );
    
      const votes: ModelVote[] = results.map((result, i) => {
        if (result.status === "fulfilled") {
          return { model: input.models[i], content: result.value.content };
        }
        return {
          model: input.models[i],
          content: "",
          error:
            result.reason instanceof Error
              ? result.reason.message
              : String(result.reason),
        };
      });
    
      const successful = votes.filter((v) => !v.error);
      const failed = votes.filter((v) => v.error);
    
      if (successful.length < 2) {
        return `## Consensus Failed\n\nOnly ${successful.length} model(s) responded. Need at least 2 for consensus.\n\nErrors:\n${failed.map((f) => `- ${f.model}: ${f.error}`).join("\n")}`;
      }
    
      const threshold = getThreshold(input.strategy ?? "majority");
      const requiredVotes = Math.ceil(successful.length * threshold);
    
      // Use a judge model to determine agreement
      const judgeModel = input.judge_model ?? await pickJudge(provider, input.models);
      let agreeing: ModelVote[];
      let dissenting: ModelVote[];
      let judgeLatency: number | undefined;
    
      if (judgeModel) {
        logger.info(`consensus: using ${judgeModel} as judge`);
        const judgeStart = Date.now();
        const judgeResult = await judgeAgreement(provider, judgeModel, successful);
        judgeLatency = Date.now() - judgeStart;
    
        if (judgeResult) {
          agreeing = judgeResult.agreeing;
          dissenting = judgeResult.dissenting;
        } else {
          // Judge failed, fall back to keyword matching
          logger.warn("consensus: judge failed, falling back to keyword matching");
          ({ agreeing, dissenting } = keywordFallback(successful));
        }
      } else {
        logger.warn("consensus: no judge available, using keyword matching");
        ({ agreeing, dissenting } = keywordFallback(successful));
      }
    
      const reached = agreeing.length >= requiredVotes;
    
      return formatConsensus({
        reached,
        strategy: input.strategy ?? "majority",
        agreeing,
        dissenting,
        failed,
        requiredVotes,
        totalVoters: successful.length,
        judgeModel,
        judgeLatency,
      });
    }
  • Zod schema 'consensusSchema' defining the tool's input: models array (3-7), prompt, strategy (majority/supermajority/unanimous), judge_model, system_prompt, temperature, and max_tokens.
    export const consensusSchema = z.object({
      models: z
        .array(z.string())
        .min(3)
        .max(7)
        .describe("List of model IDs to poll (3-7 models)"),
      prompt: z.string().describe("The prompt to send to all models"),
      strategy: z
        .enum(["majority", "supermajority", "unanimous"])
        .optional()
        .default("majority")
        .describe("Voting strategy — how many models must agree"),
      judge_model: z.string().optional().describe("Optional model ID to use as judge. Auto-picks if not specified."),
      system_prompt: z.string().optional(),
      temperature: z.number().min(0).max(2).optional().default(0),
      max_tokens: z.number().int().positive().optional().default(1024),
    });
  • Helper function 'getThreshold' that maps strategy names to numeric thresholds (0.5, 0.66, 1.0).
    function getThreshold(strategy: "majority" | "supermajority" | "unanimous"): number {
      switch (strategy) {
        case "majority":
          return 0.5;
        case "supermajority":
          return 0.66;
        case "unanimous":
          return 1.0;
      }
    }
  • Helper function 'formatConsensus' that formats the consensus result into a markdown string with agreement stats, individual responses, and dissenting views.
    function formatConsensus(result: ConsensusResult): string {
      const confidence = Math.round(
        (result.agreeing.length / result.totalVoters) * 100
      );
    
      const lines: string[] = [
        `## Consensus: ${result.reached ? "REACHED" : "NOT REACHED"}`,
        "",
        `**Strategy:** ${result.strategy} (needed ${result.requiredVotes}/${result.totalVoters})`,
        `**Agreement:** ${result.agreeing.length}/${result.totalVoters} models (${confidence}%)`,
        result.judgeModel
          ? `**Judge:** ${result.judgeModel}${result.judgeLatency ? ` (${result.judgeLatency}ms)` : ""}`
          : "",
        "",
      ];
    
      // Show the consensus answer (first agreeing model's response)
      if (result.agreeing.length > 0) {
        lines.push("### Consensus Response");
        lines.push("");
        lines.push(result.agreeing[0].content);
        lines.push("");
        lines.push(
          `*Agreed by: ${result.agreeing.map((v) => v.model).join(", ")}*`
        );
        lines.push("");
      }
    
      // Show what each model actually said so the judge can be sanity-checked
      const allVotes = [...result.agreeing, ...result.dissenting];
      if (allVotes.length > 1) {
        lines.push("### Individual Responses");
        for (const v of allVotes) {
          const summary = v.content.slice(0, 150).replace(/\n/g, " ");
          lines.push(`- **${v.model}:** ${summary}${v.content.length > 150 ? "..." : ""}`);
        }
        lines.push("");
      }
    
      // Show dissent
      if (result.dissenting.length > 0) {
        lines.push("### Dissenting Views");
        for (const d of result.dissenting) {
          lines.push(`- **${d.model}:** ${d.content.slice(0, 200)}${d.content.length > 200 ? "..." : ""}`);
        }
        lines.push("");
      }
    
      // Show failures
      if (result.failed.length > 0) {
        lines.push(`*${result.failed.length} model(s) failed to respond*`);
      }
    
      return lines.join("\n");
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided; description only says it queries and aggregates. Does not disclose performance implications, rate limits, or failure modes (e.g., no consensus).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence conveying essence with no wasted words. Efficient and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With 7 parameters, no output schema, and no annotations, the description is too minimal. Lacks details on return format, error handling, and default behaviors.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 57%, description adds context for strategy (enum values) but does not elaborate on system_prompt, temperature, or max_tokens beyond schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states the action (query and aggregate), resource (models), and result (consensus answer with confidence). Distinguishes from siblings like 'ask_model' and 'compare_models'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies use for consensus among models, but lacks explicit when-not-to-use or alternative comparisons. Context is clear but not directive.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Pickle-Pixel/HydraMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server