Spaces:
Sleeping
Sleeping
Update agentos_core.py
Browse files- agentos_core.py +31 -28
agentos_core.py
CHANGED
|
@@ -1,40 +1,43 @@
|
|
| 1 |
-
import
|
| 2 |
from memory import MemoryManager
|
| 3 |
-
from context_graph import ContextGraph
|
| 4 |
from telemetry import Telemetry
|
| 5 |
-
from
|
| 6 |
from summarizer import MemorySummarizer
|
| 7 |
|
| 8 |
class AgentCore:
|
| 9 |
def __init__(self, model="gpt-4o-mini"):
|
| 10 |
-
self.agent_id =
|
| 11 |
-
self.telemetry = Telemetry(self.agent_id)
|
| 12 |
-
self.memory = MemoryManager(self.agent_id)
|
| 13 |
-
self.context = ContextGraph()
|
| 14 |
-
self.summarizer = MemorySummarizer("semantic_memory.json")if "summarize" in prompt.lower() or "what do you know" in prompt.lower():
|
| 15 |
-
return self.summarizer.summarize()
|
| 16 |
self.model = model
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
print(f"[INIT] Agent {self.agent_id} initialized with model {self.model}")
|
| 19 |
|
| 20 |
def run(self, prompt):
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# 🔹 Summarization Trigger
|
| 24 |
-
if "summarize" in prompt.lower() or "what do you know" in prompt.lower() or "who am i" in prompt.lower():
|
| 25 |
-
summary = self.summarizer.summarize()
|
| 26 |
-
self.telemetry.log("run_complete", "success", {"response": summary})
|
| 27 |
-
print(f"[RUN] {summary}")
|
| 28 |
-
return summary
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import uuid
|
| 2 |
from memory import MemoryManager
|
|
|
|
| 3 |
from telemetry import Telemetry
|
| 4 |
+
from context_manager import ContextManager
|
| 5 |
from summarizer import MemorySummarizer
|
| 6 |
|
| 7 |
class AgentCore:
|
| 8 |
def __init__(self, model="gpt-4o-mini"):
|
| 9 |
+
self.agent_id = str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
self.model = model
|
| 11 |
+
print(f"[Identity] Created digital DNA for agent {self.agent_id}")
|
| 12 |
+
self.memory = MemoryManager("semantic_memory.json")
|
| 13 |
+
self.telemetry = Telemetry(self.agent_id)
|
| 14 |
+
self.context = ContextManager()
|
| 15 |
+
self.summarizer = MemorySummarizer("semantic_memory.json")
|
| 16 |
print(f"[INIT] Agent {self.agent_id} initialized with model {self.model}")
|
| 17 |
|
| 18 |
def run(self, prompt):
|
| 19 |
+
self.telemetry.log("run_start", "in_progress", {"prompt": prompt})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# 🔹 Reflection / Summarization Trigger
|
| 22 |
+
summary_triggers = [
|
| 23 |
+
"summarize",
|
| 24 |
+
"what do you know",
|
| 25 |
+
"who am i",
|
| 26 |
+
"remember about me",
|
| 27 |
+
"list everything",
|
| 28 |
+
"recall memory",
|
| 29 |
+
"summarize my data"
|
| 30 |
+
]
|
| 31 |
+
if any(trigger in prompt.lower() for trigger in summary_triggers):
|
| 32 |
+
summary = self.summarizer.summarize()
|
| 33 |
+
self.telemetry.log("run_complete", "success", {"response": summary})
|
| 34 |
+
print(f"[RUN] {summary}")
|
| 35 |
+
return summary
|
| 36 |
|
| 37 |
+
# 🔹 Normal conversation & memory flow
|
| 38 |
+
response = f"Agent {self.agent_id} processed: {prompt}"
|
| 39 |
+
self.memory.save({"prompt": prompt, "response": response})
|
| 40 |
+
self.context.link_context(self.agent_id, prompt, response)
|
| 41 |
+
self.telemetry.log("run_complete", "success", {"response": response})
|
| 42 |
+
print(f"[RUN] {response}")
|
| 43 |
+
return response
|