MCPcopy Create free account
hub / github.com/InternScience/InternAgent / advancedMemAgent

Class advancedMemAgent

tasks/AutoMem/code/eval.py:51–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49sentence_model = None
50
51class advancedMemAgent:
52 def __init__(self, model, backend, retrieve_k, temperature_c5, sglang_host="http://localhost", sglang_port=30000):
53 self.memory_system = AgenticMemorySystem(
54 model_name='all-MiniLM-L6-v2',
55 llm_backend=backend,
56 llm_model=model,
57 sglang_host=sglang_host,
58 sglang_port=sglang_port
59 )
60 self.retriever_llm = LLMController(
61 backend=backend,
62 model=model,
63 api_key=None,
64 sglang_host=sglang_host,
65 sglang_port=sglang_port
66 )
67 self.retrieve_k = retrieve_k
68 self.temperature_c5 = temperature_c5
69
70 def add_memory(self, content, time=None):
71 self.memory_system.add_note(content, time=time)
72
73 def retrieve_memory(self, content, k=10):
74 return self.memory_system.find_related_memories_raw(content, k=k)
75
76 def retrieve_memory_llm(self, memories_text, query):
77 prompt = f"""Given the following conversation memories and a question, select the most relevant parts of the conversation that would help answer the question. Include the date/time if available.
78
79 Conversation memories:
80 {memories_text}
81
82 Question: {query}
83
84 Return only the relevant parts of the conversation that would help answer this specific question. Format your response as a JSON object with a "relevant_parts" field containing the selected text.
85 If no parts are relevant, do not do any things just return the input.
86
87 Example response format:
88 {{"relevant_parts": "2024-01-01: Speaker A said something relevant..."}}"""
89
90 # Get LLM response
91 response = self.retriever_llm.llm.get_completion(prompt,response_format={"type": "json_schema", "json_schema": {
92 "name": "response",
93 "schema": {
94 "type": "object",
95 "properties": {
96 "relevant_parts": {
97 "type": "string",
98 }
99 },
100 "required": ["relevant_parts"],
101 "additionalProperties": False
102 },
103 "strict": True
104 }})
105 # print("response:{}".format(response))
106 return response
107
108 def generate_query_llm(self, question):

Callers 1

process_single_sampleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected