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.
How a request runs
- Request. A contract sends a prompt to Somnia Agents with a deposit and a callback.
- Elect. A subcommittee of validators from the Somnia Validator Network is chosen to run it.
- Infer. Each validator runs the same model with the same seed at zero temperature.
- Agree. Under majority consensus, byte-identical answers from the threshold of validators finalise the request.
- 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
// From docs.somnia.network/agents/base-agents/llm-inference
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
]
});