Tpayne101 commited on
Commit
2ca143e
·
verified ·
1 Parent(s): 3271dbe

Update agentos_core.py

Browse files
Files changed (1) hide show
  1. agentos_core.py +42 -40
agentos_core.py CHANGED
@@ -1,42 +1,44 @@
1
- from langchain.memory import ConversationBufferMemory
2
- from langchain_community.chat_models import ChatOpenAI
3
- from langchain.chains import ConversationChain
4
- from memory import MemoryManager, ContextGraph
5
- class AgentCore:
6
  def __init__(self, agent_id):
7
- self.memory = MemoryManager(agent_id)
8
- def __init__(self, agent_id): # Add this function
9
- self.memory = MemoryManager(agent_id) # Move it here
10
- class AgentCore:
11
- def __init__(self, agent_id): # Add this if it’s not there
12
- self.memory = MemoryManager(self.agent_id) # Move it here
13
-
14
- File "/app/app.py", line 2, in <module>
15
- from agentos_core import AgentCore
16
- File "/app/agentos_core.py", line 13, in <module>
17
- self.context_graph = ContextGraph()
18
- NameError: name 'self' is not defined
19
- self.memory.save({
20
- "event": "init",
21
- "details": f"Agent {self.agent_id} initialized."
22
- })
23
- self.context_graph = ContextGraph()
24
- self.memory.save({
25
- "event": "init",
26
- "details": f"Agent {self.agent_id} initialized."
27
- })
 
 
 
 
 
 
 
 
28
  class AgentCore:
29
- def __init__(self, model="gpt-4-turbo"):
30
- # Rest of the code here
31
- self.memory = ConversationBufferMemory()
32
- self.agent = ConversationChain(
33
- llm=ChatOpenAI(model_name=model),
34
- memory=self.memory
35
- )
36
-
37
- def run(self, prompt):
38
- response = self.agent.run(prompt)
39
- return {
40
- "response": response,
41
- "memory_summary": self.memory.buffer
42
- }
 
1
+ import uuid
2
+ import json
3
+ import os
4
+
5
+ class MemoryManager:
6
  def __init__(self, agent_id):
7
+ self.agent_id = agent_id
8
+ self.file_path = f"memory_{agent_id}.json"
9
+ self._init_memory()
10
+
11
+ def _init_memory(self):
12
+ if not os.path.exists(self.file_path):
13
+ with open(self.file_path, "w") as f:
14
+ json.dump({"history": []}, f)
15
+
16
+ def save(self, data):
17
+ with open(self.file_path, "r") as f:
18
+ memory = json.load(f)
19
+ memory["history"].append(data)
20
+ with open(self.file_path, "w") as f:
21
+ json.dump(memory, f, indent=2)
22
+
23
+
24
+ class ContextGraph:
25
+ def __init__(self):
26
+ self.context = {}
27
+
28
+ def update(self, key, value):
29
+ self.context[key] = value
30
+
31
+
32
+ def create_agent_identity():
33
+ return str(uuid.uuid4())
34
+
35
+
36
  class AgentCore:
37
+ def __init__(self, model="gpt-4o-mini"):
38
+ self.agent_id = create_agent_identity()
39
+ self.memory = MemoryManager(self.agent_id)
40
+ self.context_graph = ContextGraph()
41
+ self.memory.save({
42
+ "event": "init",
43
+ "details": f"Agent {self.agent_id} initialized."
44
+ })