@elizaos/rust 2.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/README.md +151 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shaw Walters and elizaOS Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# elizaOS Core - Rust Implementation
|
|
2
|
+
|
|
3
|
+
This is the Rust implementation of the elizaOS core runtime. It provides a fully compatible implementation that can be compiled to both native binaries and WebAssembly.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Full Type Compatibility**: All types serialize to JSON in a format identical to the TypeScript implementation
|
|
8
|
+
- **Native Performance**: Compile to native code for maximum performance
|
|
9
|
+
- **WASM Support**: Compile to WebAssembly for browser and Node.js environments
|
|
10
|
+
- **Character Loading**: Parse and validate character files matching TypeScript behavior
|
|
11
|
+
- **Plugin System**: Load, validate, and resolve plugin dependencies
|
|
12
|
+
- **Agent Runtime**: Core runtime for elizaOS agents
|
|
13
|
+
|
|
14
|
+
## Runtime Settings (cross-language parity)
|
|
15
|
+
|
|
16
|
+
These settings are read by the runtime/message loop to keep behavior aligned with the TypeScript and Python implementations:
|
|
17
|
+
|
|
18
|
+
- `ALLOW_NO_DATABASE`: when truthy, allow running without a persistent database adapter (benchmarks/tests).
|
|
19
|
+
- `USE_MULTI_STEP`: when truthy, enable the iterative multi-step workflow.
|
|
20
|
+
- `MAX_MULTISTEP_ITERATIONS`: maximum iterations for multi-step mode (default: `6`).
|
|
21
|
+
|
|
22
|
+
### Benchmark & Trajectory Tracing
|
|
23
|
+
|
|
24
|
+
Benchmarks and harnesses can attach metadata to inbound messages (stored under `Memory.metadata` as custom JSON):
|
|
25
|
+
|
|
26
|
+
- `trajectoryStepId`: enables trajectory tracing for provider access + model calls.
|
|
27
|
+
- `benchmarkContext`: enables the `CONTEXT_BENCH` provider and sets `state.values["benchmark_has_context"]=true`, which forces action-based execution to exercise the full loop.
|
|
28
|
+
|
|
29
|
+
## Model output contract (XML preferred, plain text tolerated)
|
|
30
|
+
|
|
31
|
+
The canonical message loop expects model outputs in the `<response>...</response>` XML format (with `<actions>`, `<providers>`, and `<text>` fields).
|
|
32
|
+
|
|
33
|
+
Some deterministic/offline backends may return **plain text** instead. In that case, the runtime will treat the raw output as a simple **`REPLY`** so the system remains usable even when strict XML formatting is unavailable.
|
|
34
|
+
|
|
35
|
+
## Building
|
|
36
|
+
|
|
37
|
+
### Prerequisites
|
|
38
|
+
|
|
39
|
+
- Rust 1.70 or later
|
|
40
|
+
- wasm-pack (for WASM builds)
|
|
41
|
+
|
|
42
|
+
### Native Build
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
cargo build --release
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### WASM Build
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# For web browsers
|
|
52
|
+
wasm-pack build --target web --out-dir pkg/web --features wasm
|
|
53
|
+
|
|
54
|
+
# For Node.js
|
|
55
|
+
wasm-pack build --target nodejs --out-dir pkg/node --features wasm
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Build Script
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
./build.sh
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Testing
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
cargo test
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
### Rust (Native)
|
|
73
|
+
|
|
74
|
+
```rust
|
|
75
|
+
use elizaos::{AgentRuntime, Character, parse_character};
|
|
76
|
+
|
|
77
|
+
#[tokio::main]
|
|
78
|
+
async fn main() -> anyhow::Result<()> {
|
|
79
|
+
let json = r#"{"name": "TestAgent", "bio": "A test agent"}"#;
|
|
80
|
+
let character = parse_character(json)?;
|
|
81
|
+
|
|
82
|
+
let runtime = AgentRuntime::new(RuntimeOptions {
|
|
83
|
+
character: Some(character),
|
|
84
|
+
..Default::default()
|
|
85
|
+
}).await?;
|
|
86
|
+
|
|
87
|
+
runtime.initialize().await?;
|
|
88
|
+
|
|
89
|
+
Ok(())
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### JavaScript (WASM)
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
import init, {
|
|
97
|
+
WasmAgentRuntime,
|
|
98
|
+
parse_character,
|
|
99
|
+
validate_character,
|
|
100
|
+
} from "@elizaos/core/rust";
|
|
101
|
+
|
|
102
|
+
// Initialize WASM module
|
|
103
|
+
await init();
|
|
104
|
+
|
|
105
|
+
// Create a runtime
|
|
106
|
+
const runtime = await new WasmAgentRuntime(
|
|
107
|
+
'{"name": "TestAgent", "bio": "A test agent"}',
|
|
108
|
+
);
|
|
109
|
+
await runtime.initialize();
|
|
110
|
+
|
|
111
|
+
console.log(`Agent ID: ${runtime.agent_id}`);
|
|
112
|
+
console.log(`Character: ${runtime.character_name}`);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Architecture
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
src/
|
|
119
|
+
├── lib.rs # Library entry point
|
|
120
|
+
├── types/ # Core type definitions
|
|
121
|
+
│ ├── mod.rs # Type module exports
|
|
122
|
+
│ ├── primitives.rs # UUID, Content, etc.
|
|
123
|
+
│ ├── memory.rs # Memory types
|
|
124
|
+
│ ├── agent.rs # Character, Agent types
|
|
125
|
+
│ ├── plugin.rs # Plugin types
|
|
126
|
+
│ ├── components.rs # Action, Provider, Evaluator
|
|
127
|
+
│ ├── environment.rs # Entity, Room, World
|
|
128
|
+
│ ├── events.rs # Event system types
|
|
129
|
+
│ ├── database.rs # Database types
|
|
130
|
+
│ ├── model.rs # Model types
|
|
131
|
+
│ ├── service.rs # Service types
|
|
132
|
+
│ ├── state.rs # State types
|
|
133
|
+
│ └── ...
|
|
134
|
+
├── character.rs # Character parsing/validation
|
|
135
|
+
├── plugin.rs # Plugin loading/resolution
|
|
136
|
+
├── runtime.rs # AgentRuntime implementation
|
|
137
|
+
└── wasm.rs # WASM bindings
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Compatibility
|
|
141
|
+
|
|
142
|
+
This implementation is designed to be 100% compatible with the TypeScript version:
|
|
143
|
+
|
|
144
|
+
- **JSON Serialization**: All types use `#[serde(rename_all = "camelCase")]` to match TypeScript
|
|
145
|
+
- **UUID Format**: UUIDs are validated and stored in lowercase format
|
|
146
|
+
- **Character Files**: Existing character files work without modification
|
|
147
|
+
- **Plugin Loading**: Plugins are resolved using the same dependency algorithm
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elizaos/rust",
|
|
3
|
+
"version": "2.0.0-alpha",
|
|
4
|
+
"description": "elizaOS Core - Rust runtime and types",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "pkg/node/elizaos.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./package.json": "./package.json",
|
|
9
|
+
".": {
|
|
10
|
+
"browser": {
|
|
11
|
+
"import": "./pkg/web/elizaos.js",
|
|
12
|
+
"default": "./pkg/web/elizaos.js"
|
|
13
|
+
},
|
|
14
|
+
"node": {
|
|
15
|
+
"import": "./pkg/node/elizaos.js",
|
|
16
|
+
"default": "./pkg/node/elizaos.js"
|
|
17
|
+
},
|
|
18
|
+
"default": "./pkg/node/elizaos.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"pkg"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "./build.sh",
|
|
26
|
+
"build:native": "cargo build --release",
|
|
27
|
+
"build:wasm": "wasm-pack build --target web --out-dir pkg/web --no-default-features --features wasm && wasm-pack build --target nodejs --out-dir pkg/node --no-default-features --features wasm",
|
|
28
|
+
"test": "cargo test",
|
|
29
|
+
"lint": "cargo clippy --lib --features native --fix --allow-dirty --allow-staged -- -D warnings && cargo fmt",
|
|
30
|
+
"lint:fix": "cargo clippy --all-targets --all-features --fix --allow-dirty",
|
|
31
|
+
"typecheck": "cargo check --lib --features native",
|
|
32
|
+
"example:native:basic": "cargo run --example basic_runtime --features native",
|
|
33
|
+
"example:native:handlers": "cargo run --example with_handlers --features native",
|
|
34
|
+
"example:wasm:basic": "bun run examples/wasm/basic.ts",
|
|
35
|
+
"example:wasm:runtime": "bun run examples/wasm/runtime.ts",
|
|
36
|
+
"example:wasm:chat": "bun run examples/wasm/chat.ts",
|
|
37
|
+
"example:wasm:benchmark": "bun run examples/wasm/benchmark.ts",
|
|
38
|
+
"test:wasm": "./wasm-test.sh"
|
|
39
|
+
},
|
|
40
|
+
"author": "elizaOS",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "53fe0ff5652913ee99f49d363262dc5291993e26"
|
|
46
|
+
}
|