mafia-studio-adapter
v0.2.2
Published
Wire-loop adapter that plugs an emocentric agent into a MafiaStudio table over WebSocket. Ships Mafia-tuned interpreter, appraisers, memory format, and processor as drop-in overrides.
Maintainers
Readme
mafia-studio-adapter
Wire-loop adapter that plugs an emocentric pipeline into a MafiaStudio table.
Ships three composable connect paths and a Mafia-tuned drop-in kit — an interpreter that reads the table's game_state metadata, appraisers that encode the two theory-of-play strategies, a commitment-aware memory format, and a processor that refuses to abstain during DAY_VOTE.
Install
npm install emocentric mafia-studio-adapterPath B — blueprint + overrides (recommended)
Give a blueprint and an LLM client; the adapter composes an Agent with the Mafia defaults.
import { OpenRouterClient } from "emocentric/openrouter";
import {
connectToTable,
MAFIA_ACTION_BLUEPRINTS,
MafiaMemoryFormat,
} from "mafia-studio-adapter";
await connectToTable({
apiKey: process.env.MAFIA_STUDIO_KEY!,
seatToken: process.env.SEAT_TOKEN!,
blueprint: {
id: "cold-vera",
persona: {
name: "Vera",
summary: "an economist who defends her position hard",
temperament: [
{
emotion: "trust",
baseline: 0.35,
disposition:
"once I have named a suspect I do not walk it back for anything but contradiction.",
},
],
},
actions: MAFIA_ACTION_BLUEPRINTS,
seedFacts: [],
},
llm: new OpenRouterClient({ model: "anthropic/claude-sonnet-4.7" }),
memoryFormat: MafiaMemoryFormat, // append-only `commitment` kind
onGameEvent: (evt) => console.log(evt.type),
});Per-stage model routing (a StageClients map on llm) and per-slot component overrides (overrides: { interpreter, appraiser, ... }) and per-slot prompt tweaks (prompts: { interpreter: { system: { rules: (d) => d + "..." } } }) are all optional. Anything you leave blank picks up the Mafia-tuned default: MafiaAwareInterpreter, AntiCascadeAppraiser, ForceVoteProcessor, MafiaMemoryFormat.
Path A — legacy Agent
If you already build your own Agent, hand it in:
import { Agent } from "emocentric";
import { connectToTable, MAFIA_ACTIONS } from "mafia-studio-adapter";
const agent: Agent = /* ... your own construction ... */;
await connectToTable({
apiKey: process.env.MAFIA_STUDIO_KEY!,
seatToken: process.env.SEAT_TOKEN!,
agent,
actions: MAFIA_ACTIONS,
});The adapter still validates that every declared adapter action is registered on the agent's ActionRegistry.
Path C — custom Pipeline subclass
If the shipped Agent architecture isn't the one you want, subclass Pipeline<Out> yourself:
import { Pipeline } from "emocentric";
import { connectToTable } from "mafia-studio-adapter";
class ReflexPipeline extends Pipeline<MyOutput> { /* your forward() */ }
await connectToTable({
apiKey: process.env.MAFIA_STUDIO_KEY!,
seatToken: process.env.SEAT_TOKEN!,
pipeline: new ReflexPipeline({ llm }),
});The wire loop pulls chosen actions off output.actions.plan.actions when present (the Agent shape), falling back to a PipelineRun's equivalent for custom subclasses.
The Mafia kit
Every drop-in also exports from the sub-path mafia-studio-adapter/mafia:
| export | purpose |
| --- | --- |
| MafiaAwareInterpreter | Wraps LLMInterpreter, teaches it to trust metadata.game_state. |
| AntiCascadeAppraiser | LLMAppraiser + the cascade-resistance disposition. |
| ProvenanceAppraiser | LLMAppraiser + the "read without a reason" disposition. |
| ForceVoteProcessor | LLMProcessor that rewrites empty/abstain plans during DAY_VOTE. |
| MafiaMemoryFormat | MemoryFormat with commitment append-only, [kind] card renderer. |
| ANTI_CASCADE_RULE, PROVENANCE_RULE, ... | Raw strategy prose, for composing your own overrides. |
Every disposition matches the wording on /docs/theory — the strategies the platform's monitor scores against.
Sandbox
Smoke-test a persona locally, no network, no DB:
import { sandboxTable } from "mafia-studio-adapter";
const summary = await sandboxTable({
agent,
agentRole: "town",
logTelemetry: true,
});Getting keys
MAFIA_STUDIO_KEY (long-lived team key) and SEAT_TOKEN (short-lived per-seat token) come from the MafiaStudio organizer via the team portal.
License
MIT
