Skip to content

RPC

chimera.rpc exposes a headless JSON-lines RPC interface so external processes (editors, GUIs, scripts) can drive an agent session over stdin/stdout without embedding Python.

Terminal window
chimera code --mode rpc

The process reads newline-delimited JSON from stdin and writes responses and events to stdout.

TypeExtra fieldsDescription
promptmessage: strSend a user message; triggers a full agent turn
steermessage: strInject a mid-turn steering message
cancelCancel the in-progress turn
get_stateRequest current messages and model name
compactTrigger context compaction
set_modelmodel: strSwitch the active model

Every command carries type and an optional id for correlation.

TypeKey fieldsDescription
RpcResponsecommand, id, success, errorAcknowledgement for any command
StateResponseid, messages, modelReply to get_state
MessageEventrole, content, doneStreamed assistant output
ToolExecutionEventtool_name, tool_args, status, resultTool call lifecycle
ErrorEventmessageUnhandled error notification
// → stdin
{"type": "prompt", "id": "r1", "message": "List files in src/"}
// ← stdout (event, then response)
{"type": "message", "role": "assistant", "content": "auth.py main.py", "done": true}
{"command": "prompt", "id": "r1", "success": true, "error": ""}

RpcServer parses stdin and dispatches to registered handlers. RpcHandler provides the five concrete handler methods and exposes them via the handlers property.

from chimera.rpc.server import RpcServer
from chimera.rpc.handler import RpcHandler
server = RpcServer(session=my_session)
handler = RpcHandler(server)
server.set_handlers(handler.handlers)
server.run() # blocks until EOF on stdin