Get memory statistics. Returns: Dict with long_term_count, short_term_count, working_count.
(&self, py: Python<'py>)
| 3142 | /// Returns: |
| 3143 | /// Dict with long_term_count, short_term_count, working_count. |
| 3144 | fn memory_stats<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> { |
| 3145 | let memory = self |
| 3146 | .inner |
| 3147 | .memory() |
| 3148 | .ok_or_else(|| PyRuntimeError::new_err("Memory not configured for this session"))? |
| 3149 | .clone(); |
| 3150 | let stats = py |
| 3151 | .allow_threads(move || get_runtime().block_on(memory.stats())) |
| 3152 | .map_err(|e| PyRuntimeError::new_err(format!("Stats failed: {e}")))?; |
| 3153 | let json_str = serde_json::to_string(&stats) |
| 3154 | .map_err(|e| PyRuntimeError::new_err(format!("Serialization error: {e}")))?; |
| 3155 | let json_mod = py.import("json")?; |
| 3156 | let py_obj = json_mod.call_method1("loads", (json_str,))?; |
| 3157 | py_obj |
| 3158 | .downcast::<PyDict>() |
| 3159 | .cloned() |
| 3160 | .map_err(|e| PyRuntimeError::new_err(format!("Unexpected result: {e}"))) |
| 3161 | } |
| 3162 | |
| 3163 | /// Get current working memory items. |
| 3164 | /// |
nothing calls this directly
no test coverage detected