The Plugwise Agent CLI supports JSON-RPC 2.0 protocol for programmatic interaction.
# Start JSON-RPC mode
node dist/cli/plugwise-agent-cli.js --jsonrpc
# Or with npm script
npm run agent -- --jsonrpcThe CLI implements JSON-RPC 2.0 specification.
{
"jsonrpc": "2.0",
"method": "execute",
"params": {
"instruction": "natural language command"
},
"id": 1
}{
"jsonrpc": "2.0",
"result": {
"text": "Response from the agent",
"steps": 3
},
"id": 1
}{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "Invalid params: instruction is required"
},
"id": 1
}| Code | Message | Description |
|---|---|---|
| -32700 | Parse error | Invalid JSON was received |
| -32602 | Invalid params | Missing or invalid instruction parameter |
| -32603 | Internal error | Agent execution failed |
| -32000 | Server error | Missing API key or configuration error |
Request:
echo '{"jsonrpc":"2.0","method":"execute","params":{"instruction":"List all devices"},"id":1}' | \
node dist/cli/plugwise-agent-cli.js --jsonrpcResponse:
{
"jsonrpc": "2.0",
"result": {
"text": "Here are your Plugwise devices:\n- Living Room Thermostat (Adam)\n- Bedroom Radiator (Anna)",
"steps": 2
},
"id": 1
}Request:
echo '{"jsonrpc":"2.0","method":"execute","params":{"instruction":"Set bedroom to 19 degrees"},"id":2}' | \
node dist/cli/plugwise-agent-cli.js --jsonrpcResponse:
{
"jsonrpc": "2.0",
"result": {
"text": "I've set the bedroom temperature to 19°C.",
"steps": 3
},
"id": 2
}Request (missing instruction):
echo '{"jsonrpc":"2.0","method":"execute","params":{},"id":3}' | \
node dist/cli/plugwise-agent-cli.js --jsonrpcResponse:
{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "Invalid params: instruction is required"
},
"id": 3
}Request:
echo '{invalid json}' | node dist/cli/plugwise-agent-cli.js --jsonrpcResponse:
{
"jsonrpc": "2.0",
"error": {
"code": -32700,
"message": "Parse error: Invalid JSON"
},
"id": null
}import json
import subprocess
def call_plugwise_agent(instruction):
request = {
"jsonrpc": "2.0",
"method": "execute",
"params": {"instruction": instruction},
"id": 1
}
proc = subprocess.Popen(
["node", "dist/cli/plugwise-agent-cli.js", "--jsonrpc"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, _ = proc.communicate(json.dumps(request).encode() + b'\n')
return json.loads(stdout.decode())
# Usage
response = call_plugwise_agent("List my devices")
print(response["result"]["text"])import { spawn } from 'child_process';
function callPlugwiseAgent(instruction) {
return new Promise((resolve, reject) => {
const cli = spawn('node', ['dist/cli/plugwise-agent-cli.js', '--jsonrpc']);
let output = '';
cli.stdout.on('data', (data) => {
output += data.toString();
});
cli.on('close', () => {
try {
resolve(JSON.parse(output));
} catch (err) {
reject(err);
}
});
const request = {
jsonrpc: '2.0',
method: 'execute',
params: { instruction },
id: 1
};
cli.stdin.write(JSON.stringify(request) + '\n');
cli.stdin.end();
});
}
// Usage
const response = await callPlugwiseAgent('List my devices');
console.log(response.result.text);# Create a named pipe
mkfifo /tmp/plugwise_pipe
# Start the JSON-RPC server
node dist/cli/plugwise-agent-cli.js --jsonrpc < /tmp/plugwise_pipe &
# Send request
echo '{"jsonrpc":"2.0","method":"execute","params":{"instruction":"List devices"},"id":1}' > /tmp/plugwise_pipeOPENAI_API_KEY- Required for OpenAI modelsGOOGLE_GENERATIVE_AI_API_KEY- Required for Gemini modelsPLUGWISE_AGENT_MODEL- Model to use (default: gpt-4o-mini)
- Initialization: First request includes agent initialization (~2-5 seconds)
- Subsequent requests: Faster as agent is already initialized
- Connection reuse: Keep the process running for multiple requests
- Timeouts: Set appropriate timeouts (30s+ recommended for complex queries)
| Feature | JSON-RPC Mode | MCP Mode |
|---|---|---|
| Protocol | JSON-RPC 2.0 | MCP Protocol |
| Transport | stdin/stdout | stdio |
| Output | Pure JSON | MCP messages |
| Use case | Scripting | MCP clients |
| Debugging | No stderr | Stderr logs |
# Run JSON-RPC test suite
npx tsx scripts/test-jsonrpc-mode.ts
# Manual testing
echo '{"jsonrpc":"2.0","method":"execute","params":{"instruction":"test"},"id":1}' | \
node dist/cli/plugwise-agent-cli.js --jsonrpc --skip-build