Docs

Somnia LLM Inference

Somnia LLM Inference

A Somnia Agents base agent that runs a pinned LLM on a subcommittee of validators and returns the agreed answer to your contract.

Somnia LLM Inference is a base agent on Somnia Agents. A contract sends a prompt, a subcommittee of validators each runs the same pinned open-weight model with a fixed seed and zero temperature, and the agreed answer is returned to the contract's callback.

The full interface is in the LLM Inference reference.

Networks and cost

LLM Inference runs on the Global chains only: Global L1 mainnet and testnet. Tokyo doesn't serve it.

Each validator in the subcommittee charges 0.07 SOMI per request (STT on testnet), on top of the operations reserve. Pricing and fund flow explains what to send as the deposit.

How a request runs

  1. Request. A contract sends a prompt to Somnia Agents with a deposit and a callback.
  2. Elect. A subcommittee of validators from the Somnia Validator Network is chosen to run it.
  3. Infer. Each validator runs the same model with the same seed at zero temperature.
  4. Agree. Under majority consensus, byte-identical answers from the threshold of validators finalise the request.
  5. Deliver. The answer goes to the contract's callback. Signed receipts of each validator's run are kept for audit, and unspent deposit is refunded.

Methods

Method Returns
inferString Single-turn text, optionally limited to a list of allowed values
inferNumber An integer, clamped to a range you set
inferChat A reply in a multi-turn conversation with system, user and assistant roles
inferToolsChat A reply that can call MCP servers, with onchain functions returned as calldata

Each method can record chain-of-thought in the execution receipts. A request can accept only identical answers (majority consensus), or receive every validator's result and aggregate them onchain (threshold).

Example

moderation.ts

import { encodeFunctionData } from "viem";

const abi = [{
  type: 'function',
  name: 'inferString',
  inputs: [
    { name: 'prompt', type: 'string' },
    { name: 'system', type: 'string' },
    { name: 'chainOfThought', type: 'bool' },
    { name: 'allowedValues', type: 'string[]' }
  ],
  outputs: [{ name: 'response', type: 'string' }]
}];

// Content moderation example — constrain output to "safe" or "unsafe"
const calldata = encodeFunctionData({
  abi,
  functionName: 'inferString',
  args: [
    'Analyze the following text: "Check out this amazing new product!"',
    'You are a content moderation assistant.',
    false,            // chainOfThought
    ['safe', 'unsafe'] // allowedValues
  ]
});

See it in use

  • LLM Inference in Somnia Explorer. The registered agents of this type, with their methods and price. Each agent's page has Try it, which sends a request from your wallet and follows it until the validators agree.
  • Live requests. Every agent request as it is created, with each validator's signed receipt on its request page.

Use it from the CLI and MCP

The Somnia CLI and MCP server have no Somnia Agents commands yet. Send a request from a contract, as in Invoking from Solidity, or from a script with viem: each agent's page in the Explorer generates both. somnia explorer tx $HASH reads the transaction that sent a request (add --network testnet for a testnet one), as does the MCP server's explorer_transaction tool given the same network.

Send feedback

Agents: POST the same to /api/feedback.