tinycodinglm / agentic /aiagent-0030.jsonl
winapiadmin's picture
Upload folder using huggingface_hub
1f3a244 verified
|
Raw History Blame Contribute Delete
2.23 kB
{"type": "session", "harness": "opencode", "id": "aiagent-0030", "name": "memory systems"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "How do agents implement working, episodic (vector DB), semantic and procedural memory? Show ChromaDB storage with required ids and LM Studio embeddings. Include code examples."}}
{"type": "message", "message": {"role": "assistant", "content": "**Agent memory layers:**\n\n1. **Working:** current context window - summarize/slide when full\n2. **Episodic:** past turns in a vector DB, retrieved by similarity\n3. **Semantic:** facts as triples/rules\n4. **Procedural:** reusable skills/scripts\n\nChromaDB `add()` requires unique `ids` (see Chroma docs).\n\n```python\nimport chromadb\nfrom openai import OpenAI\n\nclient = OpenAI(base_url=\"http://localhost:1234/v1\", api_key=\"lm-studio\")\nMODEL = \"text-embedding-nomic-embed-text-v1.5\" # example; use loaded id\n\nclass AgentMemory:\n def __init__(self, name: str = \"agent_memory\"):\n self.db = chromadb.Client()\n self.collection = self.db.get_or_create_collection(name=name)\n\n def _embed(self, text: str) -> list[float]:\n resp = client.embeddings.create(model=MODEL, input=[text.replace(\"\\n\", \" \")])\n return resp.data[0].embedding\n\n def store(self, doc_id: str, content: str, metadata: dict | None = None) -> None:\n self.collection.add(\n ids=[doc_id],\n documents=[content],\n embeddings=[self._embed(content)],\n metadatas=[metadata or {}],\n )\n\n def recall(self, query: str, n: int = 3) -> list[str]:\n res = self.collection.query(query_embeddings=[self._embed(query)], n_results=n)\n docs = res.get(\"documents\") or [[]]\n return docs[0]\n```"}}