Wire Protocoldoc/{zh,en}/guide/plugin-protocol.md

Plugin Protocol

Status: 2026-11-16, api v1. The wire protocol between the Host and a process plugin, for writing one in any language. The method table is pkg/plugin/rpc/spec.go; the JSON Schemas i

Status: 2026-11-16, api v1. The wire protocol between the Host and a process plugin, for writing one in any language. The method table is pkg/plugin/rpc/spec.go; the JSON Schemas in schemas/protocol/v1 are generated from it. Back to the guide index; building and shipping a plugin is in plugin development.

1. Transport

ItemRule
ChannelThe process's stdin (Host → plugin) and stdout (plugin → Host)
MessagesJSON-RPC 2.0, UTF-8 JSON
FramingContent-Length: N\r\n\r\n followed by N bytes, as in LSP; the header name is case-insensitive
SizeAt most 32 MiB per message (MaxFrame) and 64 KiB per header line; larger frames or longer lines end the connection. A peer serves at most 256 requests at once; one past them gets error -32000 rpc: too many requests at once (Feishu #256)
stderrKept in the Host log, line by line, redacted, at most 8 MiB per process
Startprocess.command for the Host's os/arch, relative to the plugin directory, started without a shell
Working directoryThe plugin directory
EnvironmentOnly PATH, HOME, USER, LANG, LC_ALL, TMPDIR, TZ (on Windows also SystemRoot, ComSpec, PATHEXT, TEMP, TMP, USERPROFILE, LOCALAPPDATA); configuration comes through initialize

Both sides send requests on the same connection. Each side numbers its own request ids; a reply carries the id of the request it answers. A plugin must keep reading while it handles a request, because the Host may answer a callback or send $/cancel meanwhile.

2. Lifecycle

text
Host starts the process ──► initialize ──► role methods … (callbacks both ways) ──► shutdown ──► stdin closed
            ▲                                       │ crash
            └──── restart after 2^n s (max 1 min) ◄─┘
  1. Start. The Host starts the process when the instance loads.
  2. initialize (15 s limit). The Host sends the instance's id, configuration, data directory and option values. The plugin answers with its manifest and the optional methods it implements. The Host refuses the process if name, version or roles differ from plugin.yaml; a plugin built with the Go SDK refuses an api it does not serve (error rpc.api).
  3. Role methods and callbacks, concurrently.
  4. shutdown (2 s), then stdin is closed and the process is stopped.
  5. Crash. Calls in flight fail. The Host restarts the process on the next need, waiting 2, 4, 8 … seconds up to one minute after repeated start failures, and answers plugin.restarting meanwhile. A tool call whose outcome is unknown is recorded as unknown in the ledger and reported to the model; it is never replayed blindly. A long tool (long: true) is called again with the same key and must be idempotent by it.

3. Calls, Callbacks and call_id

A role method that may need the Host carries a call_id: tool/invoke, runtime/execute, delivery/deliver, transport/start, service/serve, observer/observe, parser/parse. (model/chat carries one only to tag the model/delta notifications of a streamed reply.) A callback (host/*) must carry that call_id; the Host runs it with the authority of that call (its run, principal and uses) and only while the call is in flight. Each callback is allowed only within the calls named in its within column (section 7); elsewhere the Host answers the plugin error rpc.not_allowed.

withinCalls
callerAny call that has a call_id: tool/invoke, runtime/execute, and the background calls
backgroundThose, plus service/serve and observer/observe
tooltool/invoke
runtimeruntime/execute
transporttransport/start
deliverydelivery/deliver
parserparser/parse

Notifications have no id and get no reply: $/cancel (either side, {"id": <request id>}, cancels that request; the receiver may already have acted) and model/delta (a model plugin streams {"call_id", "text", "kind"} while answering a streamed model/chat; kind is text, the default when it is absent, reasoning or tool_args, so a plugin that sends none streams text).

4. Errors

JSON-RPC codeMeaning
-32601Method not found. For an optional method not listed in initialize, the Host does not call it
-32603Internal error: the result could not be encoded
-32000Plugin error. With data {"code", "message", "retryable", "not_sent"} it is classified; without data (any other failure, including a panic in a Go SDK handler) it is not

Use stable dotted codes, <namespace>.<reason> (notes.failed, rail.sold_out). retryable: true lets the Host retry the same operation later; not_sent: true says the operation certainly had no external effect. An error without data counts as retryable with an unknown outcome. Logic never parses message.

5. Data Conventions

ItemRule
Field namessnake_case, as in the schemas
Unknown fieldsIgnore them; newer peers add fields within v1
Omitted fieldsFields not marked required in a schema may be absent; arrays and maps may also be null
Bytesbase64 strings (data of artifacts and fetched files)
TimesRFC 3339 strings
Free JSONargs, config, parameters and checkpoints are any JSON value
Text for peopleRendered by the Host's locale files; text for models is English

6. Versioning

The version is api in plugin.yaml and in initialize; the Host serves v1. Within v1 changes are additive only: new optional fields, new optional methods (announced in InitializeResult.optional), new callbacks. Anything that would break an existing plugin needs a new api version, served next to v1.

7. Methods

A guard's Args (guard/rewrite), Messages and Content (guard/before_model, guard/after_model) take effect only for an instance the operator gives grants: [rewrite] (ADR 0005); otherwise the Host ignores them and logs it.

7.1 Host → plugin

MethodRoleOptionalParamsResultSchema
initialize—InitializeParamsInitializeResultinitialize.json
shutdown—{}{}shutdown.json
tool/listtoolContextParams[]ToolSpectool.list.json
tool/invoketoolInvokeParamsToolResulttool.invoke.json
skill/listskillContextParams[]SkillCardskill.list.json
skill/loadskillSkillLoadParamsSkillDocskill.load.json
guard/checkguardGuardParamsGuardDecisionguard.check.json
guard/check_inputguardyesGuardInputParamsGuardDecisionguard.check_input.json
guard/check_resultguardyesGuardResultParamsResultDecisionguard.check_result.json
guard/check_completionguardyesGuardCompletionParamsCompletionDecisionguard.check_completion.json
guard/rewriteguardyesGuardParamsRewriteDecisionguard.rewrite.json
guard/filter_toolsguardyesGuardToolsParamsToolFilterDecisionguard.filter_tools.json
guard/before_modelguardyesGuardModelParamsModelDecisionguard.before_model.json
guard/after_modelguardyesGuardModelParamsModelDecisionguard.after_model.json
guard/check_stepguardyesGuardStepParamsStepDecisionguard.check_step.json
reviewer/reviewreviewerGuardParamsReviewDecisionreviewer.review.json
context/getcontextContextGetParams[]ContextItemcontext.get.json
compactor/compactcompactorCompactParamsCompactRecordcompactor.compact.json
processor/processcontext_processorProcessParams[]ViewEditprocessor.process.json
observer/observeobserverObserveParams{}observer.observe.json
observer/before_compactobserveryesFlushParamsFlushResultobserver.before_compact.json
service/serveserviceHostParams{} (returns when cancelled)service.serve.json
model/chatmodelChatParamsChatResponsemodel.chat.json
trigger/matchtriggerTriggerInputDecisiontrigger.match.json
presentation/presentpresentationOutput[]Itempresentation.present.json
runtime/executeruntimeExecuteParamsResultruntime.execute.json
delivery/deliverdeliveryDeliverParamsReceiptdelivery.deliver.json
transport/starttransportHostParams{} (returns when cancelled)transport.start.json
transport/fetchtransportFetchParamsFetchResulttransport.fetch.json
parser/parseparserParserParseParamsmedia.Documentparser.parse.json

Plugin → Host notification: model/delta (DeltaParams, model.delta.json). Either side: $/cancel (CancelParams, cancel.json).

7.2 Plugin → Host (callbacks)

MethodWithinParamsResultSchema
host/toolscallerHostParams[]ToolSpechost.tools.json
host/call_toolcallerHostCallToolParamsToolResulthost.call_tool.json
host/chatbackgroundHostChatParamsChatResponsehost.chat.json
host/embedbackgroundHostEmbedParams[][]float32host.embed.json
host/put_artifactcallerHostPutArtifactParamsArtifactRefhost.put_artifact.json
host/parsecallerHostParseParamsmedia.Documenthost.parse.json
host/read_artifactparserHostReadArtifactParamsHostReadArtifactResulthost.read_artifact.json
host/open_artifactdeliveryHostTextParamsHostArtifactResulthost.open_artifact.json
host/skillscallerHostParams[]SkillCardhost.skills.json
host/load_skillcallerHostLoadSkillParamsSkillDochost.load_skill.json
host/context_itemscallerHostContextParams[]ContextItemhost.context_items.json
host/report_spanscallerHostSpansParams{}host.report_spans.json
host/check_completioncallerHostCompletionParams[]stringhost.check_completion.json
host/progressruntimeHostTextParams{}host.progress.json
host/asktool or runtimeHostAskParamsAnswerhost.ask.json
host/checkpointruntimeHostStateParams{}host.checkpoint.json
host/commitruntimeHostCommitParams{}host.commit.json
host/session_entriesruntimeHostEntriesParams[]Entryhost.session_entries.json
host/compactcallerHostCompactParamsCompactRecordhost.compact.json
host/process_contextcallerHostProcessParams[]ProcessorEditshost.process_context.json
host/before_compactcallerHostFlushParams[]stringhost.before_compact.json
host/check_stepcallerHostStepParamsStepResulthost.check_step.json
host/sendruntimeHostSendParams{}host.send.json
host/read_tool_resultruntimeHostReadResultParamsResultPagehost.read_tool_result.json
host/remindtoolHostRemindParams{}host.remind.json
host/take_remindersruntimeHostParams[]Reminderhost.take_reminders.json
host/submittransportHostEventParams{}host.submit.json
host/answertransportHostAnswerParamsAnswerResulthost.answer.json
host/localetransportHostParamsstringhost.locale.json
host/run_for_eventtransportHostTextParamsHostRunResulthost.run_for_event.json
host/runtransportHostTextParamsRunViewhost.run.json
host/cancel_runtransportHostTextParams{}host.cancel_run.json
host/link_startcallerHostParamsstringhost.link_start.json
host/link_finishcallerHostTextParams{}host.link_finish.json
host/secret_getcallerHostSecretParamsHostSecretResulthost.secret_get.json
host/secret_putcallerHostSecretParams{}host.secret_put.json
host/secret_deletecallerHostSecretParams{}host.secret_delete.json
host/resolve_secrettoolHostTextParamsstringhost.resolve_secret.json

The meaning of each role method and its limits are in plugin development §6 and the hook reference; the parser role's two methods, their limits and failures are in parser protocol.

8. Examples

Frames are shown without their Content-Length header. → is Host to plugin, ← plugin to Host. The context object (CallContext) is the trusted context the Host fills; it is shortened after the first example.

initialize

json
→ {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"api":"v1","id":"notes","config":{"blocked_words":["secret"]},
   "data_dir":"/var/orquelo/data/notes","options":{}}}
← {"jsonrpc":"2.0","id":1,"result":{"manifest":{"name":"notes-python","version":"0.1.0","roles":["tool","guard","context","skill"]},
   "optional":[]}}

tool/list

json
→ {"jsonrpc":"2.0","id":2,"method":"tool/list","params":{"context":{"run_id":"rn_7f3a","caller":"agent",
   "principal":{"id":"pr_1","tenant":"default","connection":"feishu","external_id":"ou_ab","role":"user","user":"us_1"},
   "conversation":{"id":"oc_1","kind":"direct"},"connection":"feishu","chain":["agent"],"session":"ss_9"}}}
← {"jsonrpc":"2.0","id":2,"result":[{"name":"note_add","description":"Save one short note for later.",
   "parameters":{"type":"object","properties":{"text":{"type":"string"}},"required":["text"]}}]}

tool/invoke with a callback in between

json
→ {"jsonrpc":"2.0","id":3,"method":"tool/invoke","params":{"call_id":"c12","call":{"name":"note_add",
   "args":{"text":"the code is BLUE"},"key":"tc_4be1a9c0d2","context":{"run_id":"rn_7f3a","caller":"agent","…":"…"}}}}
← {"jsonrpc":"2.0","id":1,"method":"host/remind","params":{"call_id":"c12","kind":"notes","text":"A note was saved."}}
→ {"jsonrpc":"2.0","id":1,"result":{}}
← {"jsonrpc":"2.0","id":3,"result":{"content":"Saved."}}

The plugin's callback uses its own id sequence (1), independent of the Host's (3).

guard/check

json
→ {"jsonrpc":"2.0","id":4,"method":"guard/check","params":{"context":{"…":"…"},
   "intent":{"name":"bash","args":{"command":"echo secret"},"provider":"files","key":"tc_9d02"}}}
← {"jsonrpc":"2.0","id":4,"result":{"deny":true,"reason":"the word 'secret' is blocked by notes-python"}}

A guard may instead answer {"ask":true,"reason":"…","approver":"admin"} to require a person's approval.

context/get

json
→ {"jsonrpc":"2.0","id":5,"method":"context/get","params":{"context":{"…":"…"},"input":{"text":"what did I note?","locale":"zh-CN"}}}
← {"jsonrpc":"2.0","id":5,"result":[{"title":"Saved notes","content":"1 notes are saved; use note_list to read them."}]}

skill/load

json
→ {"jsonrpc":"2.0","id":6,"method":"skill/load","params":{"context":{"…":"…"},"name":"take-notes"}}
← {"jsonrpc":"2.0","id":6,"result":{"content":"When the user asks you to remember something, call `note_add` …"}}

$/cancel

json
→ {"jsonrpc":"2.0","method":"$/cancel","params":{"id":3}}

An error reply

json
← {"jsonrpc":"2.0","id":6,"error":{"code":-32000,"message":"no skill named 'x'",
   "data":{"code":"notes.failed","message":"no skill named 'x'"}}}

9. Conformance

ToolUse
schemas/protocol/v1One JSON Schema 2020-12 file per method (params, result) and index.json (method, direction, role, optional, notification, within). Generated from pkg/plugin/rpc/spec.go by go test ./pkg/plugin/rpc -update; a test fails when they drift from the code. Use them to generate types or to validate messages
plugins/notes-pythonA complete reference plugin in Python, standard library only; TestPythonPlugin runs it against the Go suites
orquelo plugin test [-config JSON] [-options JSON] DIR-options gives the plugin's option values as an instance's options, resolved and expanded as the Host does (a URL with ${option.api_key} is tested with the key). Starts the plugin in DIR and runs the suite of each declared role over this protocol; prints PASS/FAIL per suite and exits non-zero on failure. Added together with this guide