Spaces:
Sleeping
Sleeping
Update agentos_core.py
Browse files- agentos_core.py +30 -31
agentos_core.py
CHANGED
|
@@ -1,43 +1,42 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
from context_graph import ContextGraph
|
|
|
|
| 4 |
from identity_core import create_agent_identity
|
| 5 |
|
| 6 |
|
| 7 |
class AgentCore:
|
| 8 |
def __init__(self, model="gpt-4o-mini"):
|
| 9 |
self.agent_id = create_agent_identity()
|
| 10 |
-
self.telemetry = Telemetry(
|
| 11 |
-
self.model = model
|
| 12 |
self.memory = MemoryManager(self.agent_id)
|
| 13 |
self.context = ContextGraph()
|
| 14 |
-
|
| 15 |
-
self.telemetry.log("init", "success", {"agent_id": self.agent_id})
|
| 16 |
print(f"[INIT] Agent {self.agent_id} initialized with model {self.model}")
|
| 17 |
|
| 18 |
def run(self, prompt):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from memory import MemoryManager
|
| 3 |
from context_graph import ContextGraph
|
| 4 |
+
from telemetry import Telemetry
|
| 5 |
from identity_core import create_agent_identity
|
| 6 |
|
| 7 |
|
| 8 |
class AgentCore:
|
| 9 |
def __init__(self, model="gpt-4o-mini"):
|
| 10 |
self.agent_id = create_agent_identity()
|
| 11 |
+
self.telemetry = Telemetry(self.agent_id)
|
|
|
|
| 12 |
self.memory = MemoryManager(self.agent_id)
|
| 13 |
self.context = ContextGraph()
|
| 14 |
+
self.model = model
|
|
|
|
| 15 |
print(f"[INIT] Agent {self.agent_id} initialized with model {self.model}")
|
| 16 |
|
| 17 |
def run(self, prompt):
|
| 18 |
+
self.telemetry.log("run_start", "in_progress", {"prompt": prompt})
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
# 1️⃣ Recall related context from past messages containing “favorite”
|
| 22 |
+
previous_context = self.context.query_context(self.agent_id, "favorite")
|
| 23 |
+
|
| 24 |
+
# 2️⃣ Build contextual recall logic
|
| 25 |
+
if previous_context and not prompt.lower().startswith("my"):
|
| 26 |
+
recall_text = " ".join(previous_context)
|
| 27 |
+
response = f"From memory: {recall_text}"
|
| 28 |
+
else:
|
| 29 |
+
response = f"Agent {self.agent_id} processed: {prompt}"
|
| 30 |
+
|
| 31 |
+
# 3️⃣ Save new info to memory + link context
|
| 32 |
+
self.memory.save({"prompt": prompt, "response": response})
|
| 33 |
+
self.context.link_context(self.agent_id, prompt, response)
|
| 34 |
+
|
| 35 |
+
# 4️⃣ Log success
|
| 36 |
+
self.telemetry.log("run_complete", "success", {"response": response})
|
| 37 |
+
print(f"[RUN] {response}")
|
| 38 |
+
return response
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
self.telemetry.log("run_failed", "error", {"error": str(e)})
|
| 42 |
+
raise e
|