Overview
Concrete tool for coordinating nonblocking per-session memory recall and optional periodic extraction provided by the jcode base crate.
Description
The MemoryAgent is an async coordinator that runs per-session memory recall without blocking the conversation. It maintains a channel-based context update pipeline: each turn, the conversation messages are sent to the agent, which triggers the Jev recall pipeline in the background. Optional periodic extraction (every 12 turns) and final extraction (at session end) create new memories from the transcript. Extraction is independent of recall and never gates it — different models and credentials can be used.
Usage
- Initialize: Call
init() once to get a MemoryAgentHandle.
- Per-turn update: Call
update_context(session_id, messages) after each turn.
- Final extraction: Call
trigger_final_extraction(transcript, session_id) at session end.
Code Reference
Source Location
- Repository: jcode
- File: crates/jcode-base/src/memory_agent.rs
Signature
pub struct MemoryAgentStats {
pub turns_processed: usize,
pub maintenance_runs: usize,
pub last_maintenance_ms: Option<u64>,
}
pub fn init() -> Result<MemoryAgentHandle>
pub fn update_context(session_id: &str, messages: Arc<[Message]>)
pub fn update_context_sync(session_id: &str, messages: Arc<[Message]>)
pub fn build_transcript_for_extraction(messages: &[Message]) -> String
pub async fn run_final_extraction(
transcript: String,
session_id: String,
working_dir: Option<String>,
)
pub fn trigger_final_extraction(transcript: String, session_id: String)
Import
use jcode_base::memory_agent::{init, update_context, trigger_final_extraction};
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| session_id |
&str |
Yes /// Session identifier
|
| messages |
Arc<[Message]> |
Yes /// Conversation transcript for the turn
|
| transcript |
String |
Yes (extraction) /// Full conversation transcript
|
| working_dir |
Option<String> |
No /// Working directory for project-scoped extraction
|
Outputs
| Name |
Type |
Description
|
| side effects |
async /// Triggers Jev recall pipeline; optionally extracts new memories
|
| MemoryAgentStats |
struct /// Diagnostics: turns_processed, maintenance_runs
|
Usage Examples
Per-Turn Context Update
use jcode_base::memory_agent::{init, update_context};
let _handle = init().expect("memory agent init");
// After each conversation turn:
update_context(&session_id, messages.clone());
// Recall runs in the background; results are injected via pending memory
use jcode_base::memory_agent::{build_transcript_for_extraction, trigger_final_extraction};
let transcript = build_transcript_for_extraction(&messages);
trigger_final_extraction(transcript, session_id.clone());
Related Pages
Implements Principle
Requires Environment
Uses Heuristics
Page Connections
Double-click a node to navigate. Hold to expand connections.