Substrate
A Plexus RPC server providing conversation trees and LLM orchestration.
What is Plexus RPC?
Plexus RPC is a protocol for building services where code IS schema. Services expose JSON schemas at runtime for all methods, enabling zero-drift type-safe client generation and instant streaming. The protocol supports tree-structured namespacing, where plugins organize hierarchically via dot-separated paths (arbor.tree_create, cone.chat).
Key features:
- Self-describing: Query any method's schema at runtime
- Streaming-first: All methods return streams by default
- Tree-structured: Organize methods in hierarchical namespaces
- Language-agnostic: Generate type-safe clients for any language
Abstract
Substrate is a reference Plexus RPC server implementing conversation tree storage (Arbor), LLM orchestration (Cone), and development tools (ClaudeCode, Bash). It demonstrates the full Plexus RPC architecture: hierarchical plugin structure, runtime schema introspection, streaming by default, and cross-language client generation.
This document describes the Plexus RPC architecture as implemented in Substrate. Server-specific activations (Arbor, Cone, ClaudeCode) are documented separately.
Architecture
Layer Structure
┌────────────────────────────────────────────────────────────────┐
│ Plexus RPC Backends │
│ (DynamicHub instance, future: remote hubs via URL) │
├────────────────────────────────────────────────────────────────┤
│ hub-macro │
│ #[hub_methods] #[hub_method(streaming)] │
│ → generates method enums, schemas, streaming annotations │
├────────────────────────────────────────────────────────────────┤
│ hub-core │
│ Activation trait, DynamicHub routing, PluginSchema types │
│ ChildRouter trait, streaming infrastructure │
├────────────────────────────────────────────────────────────────┤
│ substrate │
│ Foundation types (Handle, Value), serialization │
└────────────────────────────────────────────────────────────────┘
Activation Trait
The unified interface for all Plexus RPC plugins:
All plugins implement Activation. The plugin_schema() method returns a JSON Schema describing available methods, parameters, and return types.
Tree-Structured Namespace
Plexus RPC organizes methods hierarchically via dot-separated paths:
plexus
├── arbor.tree_create
├── arbor.node_create_text
├── cone.create
├── cone.chat
├── echo.echo
└── health.check
Nested plugins implement ChildRouter to delegate calls to children. Plexus RPC supports arbitrary nesting depth.
Schema System
Every Plexus RPC activation exposes a schema method:
// Query any plugin's schema
plexus.call
plexus.call
Schemas include:
- Method names and descriptions
- Parameter types (JSON Schema)
- Return types (JSON Schema)
- Streaming annotation
- Child plugin summaries (namespace, description, hash)
Child schemas are not included recursively. Clients fetch child schemas individually via {namespace}.schema, enabling lazy traversal of large plugin trees.
Hash-Based Versioning
Each method schema has a content hash. Parent hashes incorporate child hashes. The root hash changes when any descendant changes. This enables:
- Cache invalidation
- Client version detection
- Schema drift warnings
Streaming by Default
All Plexus RPC methods return PlexusStream, a stream of PlexusStreamItem:
Non-streaming methods emit a single Content item followed by Done. Streaming methods emit multiple items.
Implementation Patterns
Leaf Activation (Macro-Generated)
Simple plugins with methods, no children. Use #[hub_methods]:
;
The macro generates:
EchoMethodenum with JSON SchemaActivationtrait implementation- Automatic
schemamethod dispatch
Hub Activation (Macro-Generated with Children)
Activations containing other activations (hubs). Add hub flag and implement plugin_children():
Register hubs with register_hub():
let plexus = new
.register
.register_hub;
Dynamic Activation (Hand-Implemented)
When activations are created from runtime data, manually implement Activation:
Dynamic activations must manually:
- Include
"schema"inmethods() - Handle
"schema"incall() - Implement
ChildRouterif they have children
Code Generation Pipeline
Rust Activation hub-macro Runtime Schema
┌──────────┐ ┌──────────┐ ┌──────────┐
│ impl Foo │──────────────│ proc- │─────────────│ Plugin │
│ { │ #[hub_ │ macro │ generates │ Schema │
│ fn x() │ methods] │ expand │ schema() │ JSON │
│ } │ │ │ method │ │
└──────────┘ └──────────┘ └──────────┘
│
▼
┌──────────────────────────────────────┐
│ Synapse (Haskell) │
│ Parses schema, emits IR │
│ synapse --emit-ir │
└──────────────────────────────────────┘
│
▼
┌──────────────────────────────────────┐
│ plexus-codegen-typescript (Rust) │
│ Consumes IR, generates TypeScript │
└──────────────────────────────────────┘
│
▼
┌──────────────────────────────────────┐
│ TypeScript Client │
│ Type-safe Plexus RPC calls │
└──────────────────────────────────────┘
The pipeline is language-agnostic at the IR level. Adding Python support requires implementing a Python backend in plexus-codegen-python.
Accessing Plexus RPC
WebSocket Transport
# Start Substrate server
# Connect via WebSocket
# Call Plexus RPC methods
}}}
# Get Plexus RPC schemas
}
}}
MCP Bridge
Substrate exposes an MCP server that presents Plexus RPC methods as MCP tools using dot notation:
echo.echo(message, count)
arbor.tree_create(metadata)
cone.chat(name, prompt)
The MCP bridge automatically converts all registered Plexus RPC activation methods into callable MCP tools. Tool names mirror the Plexus RPC namespace structure directly.
In-Process (Rust)
use ;
let plexus = new.register;
let mut stream = plexus.call.await?;
while let Some = stream.next.await
Current State
| Component | Status | Notes |
|---|---|---|
| hub-core | Stable | Activation, DynamicHub, ChildRouter, schemas |
| hub-macro | Stable | Streaming attribute works |
| synapse | Stable | IR emission complete |
| plexus-codegen-typescript | Partial | Types done, namespace generator pending |
| Multi-hub (remote references) | Planned | Remote hub references not implemented |
Multi-Hub Vision
Current: All activations in-process, single DynamicHub instance.
Future: Plexus RPC hubs reference other hubs as activations via URL.
┌─────────────────┐ ┌─────────────────┐
│ Local Hub │ │ Remote Hub │
│ ┌───────────┐ │ HTTP/ │ ┌───────────┐ │
│ │ local.* │ │ SSE │ │ remote.* │ │
│ └───────────┘ │◄────────►│ └───────────┘ │
│ ┌───────────┐ │ └─────────────────┘
│ │ remote@url│──┼──────────────────┘
│ │ (proxy) │ │
│ └───────────┘ │
└─────────────────┘
Requirements for multi-hub Plexus RPC:
- Transport envelope for cross-hub calls
- Schema federation (remote schemas appear local)
- Streaming across network boundary
- Authentication/authorization
See docs/architecture/16679517135570018559_multi-hub-transport-envelope.md.
Project Structure
src/
├── plexus/ # Re-exports from hub-core
├── activations/ # Substrate-specific Plexus RPC activations
│ ├── arbor/ # Conversation tree storage
│ ├── cone/ # Generic LLM orchestration
│ ├── claudecode/ # Claude Code CLI wrapper
│ ├── bash/ # Shell command execution
│ ├── changelog/ # Change tracking
│ ├── mustache/ # Template rendering
│ ├── echo/ # Example leaf activation
│ ├── health/ # Example minimal activation
│ └── solar/ # Example hub activation
├── mcp_bridge.rs # MCP protocol adapter for Plexus RPC
└── main.rs # Plexus RPC server entry point
See Also
docs/architecture/16676565123400000000_plexus-rpc-ecosystem-naming.md- Plexus RPC naming strategydocs/architecture/16679477965835151615_hub-architecture-layering.md- Detailed Plexus RPC architecturedocs/architecture/16679613932789736703_compiler-architecture.md- Code generation pipelinedocs/architecture/16680807091363337727_introspective-rpc-protocol.md- Plexus RPC protocol designdocs/architecture/16680343462706939647_schema-as-membrane.md- Schema philosophy
License
MIT