Omics-OSDocs
Developer Guide

Lobster agent protocol v1 (stdio)

Drive Lobster AI from another program with lobster agent --stdio: NDJSON messages, runs, results, cancel and exit codes.

lobster agent --stdio lets another program chat with Lobster AI: a coding agent, a desktop app, a test harness. Your program starts the command, writes messages to its stdin and reads messages from its stdout. These are the messages the Lobster terminal UI uses, plus a few for hosts.

Which interface to use:

  • lobster agent --stdio (this page): a full chat session, with streaming output and every message type.
  • lobster mcp --stdio: for MCP hosts such as Claude Code or Cursor. It offers nine tools: read the project (lobster_overview), start a run, wait for it, read its status, answer its questions, add a turn, inspect a data file, stop it, and search the documentation (lobster_docs). See Lobster AI as an MCP server.

Start the process

lobster agent --stdio [--workspace DIR] [--session ID] [--provider NAME] [--model ID]
OptionMeaning
--workspace, -wWorkspace directory (default ./.lobster_workspace, or LOBSTER_WORKSPACE)
--session, --session-id, -sSession to continue; latest picks the most recent session in the workspace
--provider, -pLLM provider, overriding the configured one
--model, -mModel, overriding the configured one

The provider and its keys come from the same configuration as lobster chat (run lobster init first). Without --stdio, the command prints a pointer on stderr and exits with code 2.

Framing

  • One JSON object per line (NDJSON), UTF-8, in both directions.
  • stdout carries only protocol messages. Logs and any other output go to stderr.
  • Ignore message types you do not know.

Every message has this envelope:

FieldTypeMeaning
typestringMessage type
versionintegerAlways 1
payloadobjectType-specific content
idstringCorrelates a request with its response; for component_render, see Decisions
seqintegerAdded by the engine: increases by one per message, starting at 1
run_idstringAdded by the engine while a run is active

Messages you send need type, version and payload.

Session start

The engine sends a handshake, some status lines, then ready (examples on this page are from recorded sessions):

{"type": "handshake", "version": 1, "seq": 1, "payload": {"engine": "lobster-ai", "engine_version": "1.2.3", "interface": "lobster agent --stdio", "protocol_version": 1}}
{"type": "ready", "version": 1, "seq": 4, "payload": {"session_id": "session_20261110_110719"}}

Check protocol_version and send your first prompt after ready.

Send a prompt

{"type": "input", "version": 1, "payload": {"content": "What can you do with single-cell RNA-seq data?"}}

Each prompt starts a run. While it runs, the engine streams display messages (text, markdown, status, spinner, tool_execution, alert, done and others) and run_state messages.

Runs and results

run_state reports the state of a run. Its payload has state and run_id, and depending on the state reason, error or result.

stateMeaning
runningThe run started
needs_decisionThe run waits for an answer (see Decisions)
completedThe run finished; result holds the outcome
failedThe run failed; error has code, message and retryable
cancelledThe run was cancelled; reason says why (below)

A cancelled run carries one of three reasons in reason. The list is closed:

reasonWhen
cancelYou stopped a running turn: cancel, or stdin closed without quit
decision_abandonedA question ended without an answer: cancel, quit or stdin closed while the run waited
decision_unsupportedThe question cannot be presented here, for example several questions at once

A failed run has its own reasons, such as exception or stream_ended.

A completed run ends like this (shortened):

{"type": "run_state", "version": 1, "seq": 11, "run_id": "run_42c5…", "payload": {"state": "completed", "run_id": "run_42c5…", "result": {"schema_version": "lobster.result/1", "engine": {"name": "lobster-ai", "version": "1.2.3"}, "session_id": "session_20261110_110719", "run_id": "run_42c5…", "response": "I can load, quality-check, cluster and annotate single-cell RNA-seq data.", "duration": 0.0097, "has_data": false, "modalities": [], "last_agent": null}}}

result follows the lobster.result/1 schema. It always has schema_version, engine, session_id, run_id and response.

Use run_state for the outcome of a run, not done. Every run ends with exactly one terminal run_state; a host keys on it, not on done. It comes before done for cancelled and failed, and after the final done for completed (carrying result). done is a display message: its summary is "", interrupt, cancelled or error.

A run cancelled before its first event sends only run_state cancelled; it never sends running. Do not wait for running before you accept a terminal state.

A cancel while a question is open ends the run with reason decision_abandoned; a cancel at any other time ends it with reason cancel.

One limit: an interrupt raised inside engine code while the run is streaming is recorded as failed with reason exception, not as cancelled.

Cancel

{"type": "cancel", "version": 1, "payload": {}}

The run ends with run_state cancelled. A cancel also drops every queued input that has not started yet; prompts whose runs already ended are not affected. To keep a prompt, send it after the cancelled state. The run stops when its current model or tool call returns.

Ending the session

Send quit to end the session:

{"type": "quit", "version": 1, "payload": {}}

What happens to a turn that is still running:

  1. input, quit, then stdin closed: the turn finishes normally (run_state completed, text, done), then the process exits 0.
  2. input, then stdin closed without quit: the host is gone, so the turn is cancelled as by cancel (reason cancel), then the process exits 0.
  3. After quit, a run that reaches needs_decision is cancelled at once with reason decision_abandoned, because nobody can answer it, and the process exits 0.
  4. cancel, then quit, is the fast way out.

Nothing after quit is read. With no turn running, quit or closing stdin exits 0 at once.

Exit codeMeaning
0Ended by quit or by closing stdin
1Unexpected failure
otherThe session could not start; the code is the startup diagnostic's

Decisions

When an analysis needs your answer, the run stops and waits. You receive, in this order: run_state needs_decision, then done with summary interrupt, spinner, and component_render.

The needs_decision state carries the question in its decision field:

FieldMeaning
decision_idThe question's id. Treat it as opaque.
request_versionStarts at 1 and goes up by one each time the engine asks the same question again. An answer must carry the current one.
questionThe question as text
componentsOne entry {n, component, data, fallback_prompt}, with n = 1. component names the input (for example threshold_slider), data holds its settings, and fallback_prompt is the question as plain text, enough to answer without drawing the component.

component_render carries the same question for a terminal UI; its id is the decision_id.

To answer, send decision_answer:

{"type": "decision_answer", "version": 1, "payload": {"decision_id": "dec_535d…", "request_version": 1, "answer": {"value": 0.1}, "source": "human"}}
FieldRequiredMeaning
decision_idyesFrom the decision field
request_versionyesFrom the decision field
answeryesAny JSON value: the form the component returns (threshold_slider {value}, confirm {confirmed}, select {selected, index}, text_input {answer}, cell_type_selector {assignments}), or plain text for any of them
sourceyeshuman when a person chose the answer, model when a model did. It is recorded as you state it.
commentnoFree text, recorded verbatim with the answer

Other fields are refused. The engine does not check the answer against the question; it is passed verbatim to the supervisor model, which reads it.

After an accepted answer, the waiting run reports run_state completed with a resumed_by field naming a new run, and with no result. This is not the end of your turn: the new run starts with running, and its terminal run_state ends the turn.

Refused answers

A refused answer does not change the run: it keeps waiting, and the question is not sent again. You receive an alert with level error, a code and a message; when the answer named a known question, also its decision_id and current request_version.

codeWhen
unknown_decisionNo question with this decision_id is waiting
already_answeredThe question was answered already; the alert names the new run in resumed_by. Sending the same answer again is refused too.
rejected_cancelledThe run was cancelled before the answer arrived
rejected_stalerequest_version is not the current one
bad_answerA required field is missing or has the wrong type, source is not human or model, or the payload has another field

Not answering

There is no "answer later". To give up on a question, send cancel: the run is cancelled with reason decision_abandoned. A waiting run has no time limit over stdio, but it ends with the process; an answer cannot outlive it.

Not in 1.3: deferring a question, questions with more than one component, and several questions at once. A run that would need several questions at once is cancelled with reason decision_unsupported, after an alert with code decision_unsupported.

Validate messages

The JSON Schema for the envelope and the full list of message types ships with the package: lobster/schemas/protocol-v1.schema.json. The lobster.result/1 schema is next to it. Validating needs jsonschema, which is not installed with lobster-ai.

LOBSTER_TEST_REPLAY_FIXTURE is for Lobster AI's own tests only: recorded answers stand in for the model. When a run uses it, Lobster prints one line on stderr: Replay fixture active: answers come from <path>, not from a model.

Known limits

See Lobster 1.3: known limits.

On this page