Spaces:
Sleeping
Sleeping
Create agentos_core_v2.py
Browse files- agentos_core_v2.py +50 -0
agentos_core_v2.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 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 |
+
class AgentCore:
|
| 8 |
+
def __init__(self, model="gpt-4o-mini"):
|
| 9 |
+
self.agent_id = create_agent_identity()
|
| 10 |
+
self.telemetry = Telemetry(self.agent_id)
|
| 11 |
+
self.memory = MemoryManager(self.agent_id)
|
| 12 |
+
self.context = ContextGraph()
|
| 13 |
+
self.model = model
|
| 14 |
+
print(f"[INIT] Agent {self.agent_id} initialized with model {self.model}")
|
| 15 |
+
|
| 16 |
+
def categorize(self, prompt):
|
| 17 |
+
prompt_l = prompt.lower()
|
| 18 |
+
if "goal" in prompt_l or "want" in prompt_l or "plan" in prompt_l:
|
| 19 |
+
return "goals"
|
| 20 |
+
elif "friend" in prompt_l or "person" in prompt_l or "met" in prompt_l:
|
| 21 |
+
return "people"
|
| 22 |
+
elif "favorite" in prompt_l or "like" in prompt_l:
|
| 23 |
+
return "preferences"
|
| 24 |
+
elif "city" in prompt_l or "food" in prompt_l or "color" in prompt_l:
|
| 25 |
+
return "personal"
|
| 26 |
+
return "general"
|
| 27 |
+
|
| 28 |
+
def run(self, prompt):
|
| 29 |
+
self.telemetry.log("run_start", "in_progress", {"prompt": prompt})
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
category = self.categorize(prompt)
|
| 33 |
+
|
| 34 |
+
# Store new fact
|
| 35 |
+
if re.match(r"my |i |i'm |i am |i like", prompt.lower()):
|
| 36 |
+
response = f"Got it — I'll remember that about your {category}."
|
| 37 |
+
self.context.link_context(self.agent_id, category, prompt, response)
|
| 38 |
+
self.memory.save({"prompt": prompt, "response": response})
|
| 39 |
+
else:
|
| 40 |
+
recall = self.context.query_context(self.agent_id, category)
|
| 41 |
+
recall_text = "; ".join(recall)
|
| 42 |
+
response = f"Here’s what I know from your {category}: {recall_text}"
|
| 43 |
+
|
| 44 |
+
self.telemetry.log("run_complete", "success", {"response": response})
|
| 45 |
+
print(f"[RUN] {response}")
|
| 46 |
+
return response
|
| 47 |
+
|
| 48 |
+
except Exception as e:
|
| 49 |
+
self.telemetry.log("run_failed", "error", {"error": str(e)})
|
| 50 |
+
raise e
|