Get or create LightMem instance for a specific context.
(self, context_id: int)
| 542 | provider=provider, |
| 543 | model=model, |
| 544 | temperature=temperature, |
| 545 | max_tokens=max_tokens, |
| 546 | api_key=api_key, |
| 547 | base_url=base_url, |
| 548 | ) |
| 549 | |
| 550 | # Initialize LLM client for LightMem internal operations (memory extraction) |
| 551 | self._lightmem_llm_client: BaseLLMClient = create_llm_client( |
| 552 | provider=provider, |
| 553 | model=model, |
| 554 | temperature=lightmem_temperature, |
| 555 | max_tokens=lightmem_max_tokens, |
| 556 | api_key=api_key, |
| 557 | base_url=base_url, |
| 558 | ) |
| 559 | |
| 560 | # LightMem instances per context_id |
| 561 | self._lightmem_instances: Dict[int, Any] = {} |
| 562 | |
| 563 | # Load LightMem modules |
| 564 | self._setup_lightmem_path() |
| 565 | self._LightMemory = None |
| 566 | self._lightmem_modules_loaded = False |
| 567 | |
| 568 | def _setup_lightmem_path(self): |
| 569 | """Add LightMem src to Python path.""" |
| 570 | lightmem_src = Path(__file__).resolve().parent / "LightMem" / "src" |
| 571 | if not lightmem_src.exists(): |
| 572 | raise ImportError(f"LightMem source folder not found at {lightmem_src}") |
| 573 | |
| 574 | lightmem_src_str = str(lightmem_src) |
| 575 | if lightmem_src_str not in sys.path: |
| 576 | sys.path.insert(0, lightmem_src_str) |
| 577 |
no test coverage detected