MCPcopy Create free account
hub / github.com/AI45Lab/Code / get_short_term

Method get_short_term

sdk/python/src/lib.rs:3205–3220  ·  view source on GitHub ↗

Get current short-term memory items. Short-term memory contains items stored during this session. Returns: List of memory item dicts in short-term memory for this session.

(&self, py: Python<'py>)

Source from the content-addressed store, hash-verified

3203 /// Returns:
3204 /// List of memory item dicts in short-term memory for this session.
3205 fn get_short_term<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyList>> {
3206 let memory = self
3207 .inner
3208 .memory()
3209 .ok_or_else(|| PyRuntimeError::new_err("Memory not configured for this session"))?
3210 .clone();
3211 let items = py.allow_threads(move || get_runtime().block_on(memory.get_short_term()));
3212 let json_str = serde_json::to_string(&items)
3213 .map_err(|e| PyRuntimeError::new_err(format!("Serialization error: {e}")))?;
3214 let json_mod = py.import("json")?;
3215 let py_obj = json_mod.call_method1("loads", (json_str,))?;
3216 py_obj
3217 .downcast::<PyList>()
3218 .cloned()
3219 .map_err(|e| PyRuntimeError::new_err(format!("Unexpected result: {e}")))
3220 }
3221
3222 /// Clear short-term memory for this session.
3223 ///

Callers

nothing calls this directly

Calls 4

block_onMethod · 0.80
get_runtimeFunction · 0.70
cloneMethod · 0.45
memoryMethod · 0.45

Tested by

no test coverage detected