Skip to content

Commit 967f943

Browse files
Exposes graph and memory APIs to zomes
Enables zomes to interact with the AIngle Cortex semantic graph and Titans memory system. Adds new host functions to query and store triples in the graph, and to recall and remember memories via Cortex. This allows zomes to leverage the knowledge layer for enhanced reasoning and data management capabilities.
1 parent 55fb3d1 commit 967f943

18 files changed

Lines changed: 1487 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/aingle/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ aingle_sqlite = { version = "0.0.1", path = "../aingle_sqlite" }
3333
aingle_middleware_bytes = "=0.0.3"
3434
aingle_state = { version = "0.0.1", path = "../aingle_state" }
3535
aingle_types = { version = "0.0.1", path = "../aingle_types" }
36+
aingle_cortex = { version = "0.2.0", path = "../aingle_cortex", default-features = false, features = ["rest"] }
3637
aingle_wasmer_host = "0.0.1"
3738
aingle_websocket = { version = "0.0.1", path = "../aingle_websocket" }
3839
wasmer = "=6.0.0"

crates/aingle/src/core/ribosome/host_fn.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,12 @@ host_fn_api_impls! {
172172
// These are constant for the lifetime of a zome call.
173173
fn zome_info (()) -> zt::info::ZomeInfo;
174174

175+
// Semantic graph operations — query/store triples via Cortex.
176+
fn graph_query (zt::graph::GraphQueryInput) -> zt::graph::GraphQueryOutput;
177+
fn graph_store (zt::graph::GraphStoreInput) -> zt::graph::GraphStoreOutput;
178+
179+
// Titans memory operations — recall/remember via Cortex.
180+
fn memory_recall (zt::graph::MemoryRecallInput) -> zt::graph::MemoryRecallOutput;
181+
fn memory_remember (zt::graph::MemoryRememberInput) -> zt::graph::MemoryRememberOutput;
182+
175183
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::core::ribosome::CallContext;
2+
use crate::core::ribosome::RibosomeT;
3+
use aingle_cortex::client::{CortexClientConfig, CortexInternalClient};
4+
use aingle_types::prelude::*;
5+
use aingle_wasmer_host::prelude::WasmError;
6+
use aingle_zome_types::graph::{GraphQueryInput, GraphQueryOutput};
7+
use std::sync::Arc;
8+
9+
/// Host function: query the Cortex semantic graph from within a zome.
10+
pub fn graph_query(
11+
_ribosome: Arc<impl RibosomeT>,
12+
_call_context: Arc<CallContext>,
13+
input: GraphQueryInput,
14+
) -> Result<GraphQueryOutput, WasmError> {
15+
let client = CortexInternalClient::new(CortexClientConfig::default());
16+
17+
tokio_helper::block_forever_on(async move {
18+
client.graph_query(input).await
19+
})
20+
.map_err(|e| WasmError::Host(format!("graph_query failed: {}", e)))
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::core::ribosome::CallContext;
2+
use crate::core::ribosome::RibosomeT;
3+
use aingle_cortex::client::{CortexClientConfig, CortexInternalClient};
4+
use aingle_types::prelude::*;
5+
use aingle_wasmer_host::prelude::WasmError;
6+
use aingle_zome_types::graph::{GraphStoreInput, GraphStoreOutput};
7+
use std::sync::Arc;
8+
9+
/// Host function: store a triple in the Cortex semantic graph from within a zome.
10+
pub fn graph_store(
11+
_ribosome: Arc<impl RibosomeT>,
12+
_call_context: Arc<CallContext>,
13+
input: GraphStoreInput,
14+
) -> Result<GraphStoreOutput, WasmError> {
15+
let client = CortexInternalClient::new(CortexClientConfig::default());
16+
17+
tokio_helper::block_forever_on(async move {
18+
client.graph_store(input).await
19+
})
20+
.map_err(|e| WasmError::Host(format!("graph_store failed: {}", e)))
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::core::ribosome::CallContext;
2+
use crate::core::ribosome::RibosomeT;
3+
use aingle_cortex::client::{CortexClientConfig, CortexInternalClient};
4+
use aingle_types::prelude::*;
5+
use aingle_wasmer_host::prelude::WasmError;
6+
use aingle_zome_types::graph::{MemoryRecallInput, MemoryRecallOutput};
7+
use std::sync::Arc;
8+
9+
/// Host function: recall memories from the Titans system via Cortex.
10+
pub fn memory_recall(
11+
_ribosome: Arc<impl RibosomeT>,
12+
_call_context: Arc<CallContext>,
13+
input: MemoryRecallInput,
14+
) -> Result<MemoryRecallOutput, WasmError> {
15+
let client = CortexInternalClient::new(CortexClientConfig::default());
16+
17+
tokio_helper::block_forever_on(async move {
18+
client.memory_recall(input).await
19+
})
20+
.map_err(|e| WasmError::Host(format!("memory_recall failed: {}", e)))
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::core::ribosome::CallContext;
2+
use crate::core::ribosome::RibosomeT;
3+
use aingle_cortex::client::{CortexClientConfig, CortexInternalClient};
4+
use aingle_types::prelude::*;
5+
use aingle_wasmer_host::prelude::WasmError;
6+
use aingle_zome_types::graph::{MemoryRememberInput, MemoryRememberOutput};
7+
use std::sync::Arc;
8+
9+
/// Host function: store a memory in the Titans system via Cortex.
10+
pub fn memory_remember(
11+
_ribosome: Arc<impl RibosomeT>,
12+
_call_context: Arc<CallContext>,
13+
input: MemoryRememberInput,
14+
) -> Result<MemoryRememberOutput, WasmError> {
15+
let client = CortexInternalClient::new(CortexClientConfig::default());
16+
17+
tokio_helper::block_forever_on(async move {
18+
client.memory_remember(input).await
19+
})
20+
.map_err(|e| WasmError::Host(format!("memory_remember failed: {}", e)))
21+
}

crates/aingle/src/core/ribosome/real_ribosome.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ use crate::core::ribosome::host_fn::x_25519_x_salsa20_poly1305_encrypt::x_25519_
6767
use crate::core::ribosome::host_fn::x_salsa20_poly1305_decrypt::x_salsa20_poly1305_decrypt;
6868
use crate::core::ribosome::host_fn::x_salsa20_poly1305_encrypt::x_salsa20_poly1305_encrypt;
6969
use crate::core::ribosome::host_fn::zome_info::zome_info;
70+
use crate::core::ribosome::host_fn::graph_query::graph_query;
71+
use crate::core::ribosome::host_fn::graph_store::graph_store;
72+
use crate::core::ribosome::host_fn::memory_recall::memory_recall;
73+
use crate::core::ribosome::host_fn::memory_remember::memory_remember;
7074
use crate::core::ribosome::CallContext;
7175
use crate::core::ribosome::Invocation;
7276
use crate::core::ribosome::RibosomeT;
@@ -568,6 +572,29 @@ impl RealRibosome {
568572
imports.define("env", "__schedule", host_fn!(store, func_env, unreachable));
569573
}
570574

575+
// Semantic graph and Titans memory host functions.
576+
// These are always available (gated by Cortex connectivity, not permissions).
577+
imports.define(
578+
"env",
579+
"__graph_query",
580+
host_fn!(store, func_env, graph_query),
581+
);
582+
imports.define(
583+
"env",
584+
"__graph_store",
585+
host_fn!(store, func_env, graph_store),
586+
);
587+
imports.define(
588+
"env",
589+
"__memory_recall",
590+
host_fn!(store, func_env, memory_recall),
591+
);
592+
imports.define(
593+
"env",
594+
"__memory_remember",
595+
host_fn!(store, func_env, memory_remember),
596+
);
597+
571598
(imports, func_env)
572599
}
573600
}

crates/aingle_cortex/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ path = "src/main.rs"
2929
aingle_graph = { version = "0.2", path = "../aingle_graph" }
3030
aingle_logic = { version = "0.2", path = "../aingle_logic" }
3131
aingle_zk = { version = "0.2", path = "../aingle_zk" }
32+
titans_memory = { version = "0.2", path = "../titans_memory" }
3233

3334
# Web framework (use 0.7 for async-graphql-axum compatibility)
3435
axum = { version = "0.7", features = ["ws", "macros"] }
@@ -75,6 +76,12 @@ validator = { version = "0.20", features = ["derive"] }
7576
# Regular expressions (for SPARQL FILTER)
7677
regex = "1.10"
7778

79+
# HTTP client (for CortexInternalClient used by WASM host functions)
80+
reqwest = { version = "0.12", features = ["json"] }
81+
82+
# Zome types (for WASM boundary types in client.rs)
83+
aingle_zome_types = { version = "^0.0.1", path = "../aingle_zome_types" }
84+
7885
# Rate limiting
7986
dashmap = "6.0"
8087

0 commit comments

Comments
 (0)