Skip to main content

Module rpc

Module rpc 

Source
Expand description

Agent Chat RPC: JSON-Lines event stream protocol over stdio.

Entry: skilllite agent-rpc

Scope: Agent chat streaming only. One request → many event lines (text_chunk, tool_call, done, etc.). Supports confirmation round-trips. Uses tokio for async execution.

Not this module: For skill execution (run/exec/bash) and executor RPC (JSON-RPC 2.0, one request → one response), see [crate::stdio_rpc]. That uses skilllite serve --stdio.

This module belongs to the agent layer (Layer 3). It provides a transport-agnostic RPC interface for Python/TypeScript SDKs to call the Rust agent engine.

Protocol:

Request (one JSON line on stdin):

{"method": "agent_chat", "params": {
    "message": "user input",
    "session_key": "default",
    "context": { "append": "optional string to append to system prompt" },
    "config": { "model": "gpt-4o", ... }  // optional overrides
}}

Response (multiple JSON lines on stdout):

{"event": "text_chunk", "data": {"text": "Hello"}}
{"event": "text", "data": {"text": "Hello, how can I help?"}}
{"event": "tool_call", "data": {"name": "read_file", "arguments": "{...}"}}
{"event": "tool_result", "data": {"name": "read_file", "result": "...", "is_error": false}}
{"event": "command_started", "data": {"command": "echo hello"}}
{"event": "command_output", "data": {"stream": "stdout", "chunk": "line"}}
{"event": "command_finished", "data": {"success": true, "exit_code": 0, "duration_ms": 123}}
{"event": "preview_started", "data": {"path": "dist", "port": 8765}}
{"event": "preview_ready", "data": {"url": "http://127.0.0.1:8765", "port": 8765}}
{"event": "preview_failed", "data": {"message": "port already in use"}}
{"event": "preview_stopped", "data": {"reason": "manual stop"}}
{"event": "swarm_started", "data": {"description": "delegate task"}}
{"event": "swarm_progress", "data": {"status": "submitting task"}}
{"event": "swarm_finished", "data": {"summary": "remote node completed task"}}
{"event": "swarm_failed", "data": {"message": "timeout, fallback to local execution"}}
{"event": "task_plan", "data": {"tasks": [...]}}
{"event": "task_progress", "data": {"task_id": 1, "completed": true}}
{"event": "confirmation_request", "data": {"prompt": "Execute rm -rf?"}}
{"event": "clarification_request", "data": {"reason": "no_progress", "message": "...", "suggestions": ["...", "..."]}}
{"event": "done", "data": {"task_id": "...", "response": "...", "task_completed": true, "tool_calls": 3, "new_skill": null}}
{"event": "error", "data": {"message": "..."}}

For confirmation_request, the caller sends back:

{"method": "confirm", "params": {"approved": true}}

For clarification_request, the caller sends back:

{"method": "clarify", "params": {"action": "continue", "hint": "optional user input"}}

or {"method": "clarify", "params": {"action": "stop"}}

Functions§

serve_agent_rpc
Run the agent_chat RPC server over stdio.