diff --git a/src/interface.jl b/src/interface.jl
index 92b0e57..7a57a6f 100755
--- a/src/interface.jl
+++ b/src/interface.jl
@@ -214,27 +214,44 @@ function planner_mistral_openorca(a::agentReflex)
Plan: first you should always think about your conversation with the user and your earlier work thoroughly then extract and devise a complete, task by task, plan to achieve your objective (pay attention to correct numeral calculation and commonsense).
+ Keyword memory: using JSON format, list all variables in the plan you need to find out
P.S.1 each task of the plan should be a single action.
+ Plan:
1. Ask the user about how many miles per day they drive
2. Ask the user about what stuff they usually carry with
3. Ask the user about preferred type of car they want to buy (sedan, sport, SUV, etc)
8. Ask the user about their price range
9. Use inventory tool to find cars that match the user's preferences and are within their price range
10. Use finalanswer tool to present the recommended car to the user.
+ Keyword memory: {"mile per day": null, "carry item": null, "car type": null, "price range": null}
$conversation
<|assistant|>
- Plan:
+
"""
-# provide ecmaple that show good planning
- plan = sendReceivePrompt(a, assistant_plan_prompt, max_tokens=1024, temperature=0.1,
+
+ response = sendReceivePrompt(a, assistant_plan_prompt, max_tokens=1024, temperature=0.1,
timeout=180, stopword=["<|user|>", ""])
- plan = split(plan, "<|")[1]
- plan = split(plan, "")[1]
- # plan = split(plan, "\n\n")[1]
+ response = split(response, "<|")[1]
+ response = split(response, "")[1]
+ response = split(response, "\n\n")[1]
+ @show response
+
+ headerToDetect = ["Plan:", "Keyword memory:",]
+ headers = detectCharacters(response, headerToDetect)
+ @show headers
+ chunkedtext = chunktext(response, headers)
+ a.memory[:c] = chunkedtext
+
+ plan = chunkedtext["Plan:"]
+ keywordmem = JSON3.read(chunkedtext["Keyword memory:"]) # use JSON to change from json string to dict
+
+ for (k, v) in keywordmem
+ a.memory[:keyword][String(k)] = v
+ end
return plan
end
@@ -394,6 +411,8 @@ end
# end
function selfAwareness(a::agentReflex)
+ latestTask = shortMemLatestTask(a.memory[:shortterm])
+
getonlykeys = ["Actinput", "Obs"]
worknoplan = similar(a.memory[:shortterm])
for (k, v) in a.memory[:shortterm]
@@ -427,28 +446,32 @@ function selfAwareness(a::agentReflex)
$work
-
-
- $(a.memory[:shortterm]["Plan 1:"])
-
+
+ $(JSON3.write(a.memory[:keyword]))
+
Use the following format strictly:
- What I know: based on observed results, breakdown then repeat all information you got one by one
- Info matching: using JSON format, explicitly state what information matches which variable name in my plan
- What am I missing: based on Info matching, describe in detail what you are still missing based on the plan
- P.S. do not mention any toolnames
+ Info extraction: repeat all keywords from the latest observed result thoroughly
+ Info mapping: based on extracted info, explicitly state what each keyword could match which keyword memory's key
+ Info matching: using JSON format, what key in my memory matches which info
- What do I know:
- - The user is buying an electric SUV car.
+
+ The user wants to buy an electric SUV car.
+
+
+ {"car type": null, "color": null, "financing": null}
+
+ Info extraction:
+ - The user is buying an electric SUV car.
+ Info mapping:
+ - SUV could matches "car type" key
+ - electric could matches "engine type" key
Info matching: {"car type": "SUV", "engine type": "electric motor", "color": null, "financing": null}
- What am I missing:
- - The user's preferred color
- - The user's financing method
<|assistant|>
- What I know:
+ Info extraction:
"""
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.2, timeout=180,
stopword=["/n/n", "END", "End", "Obs", "<|", ""])
@@ -458,48 +481,52 @@ function selfAwareness(a::agentReflex)
@show selfaware_1 = response
#WORKING
- headerToDetect = ["What I know:", "Info matching:", "What am I missing:",]
+ headerToDetect = ["Info extraction:", "Info matching:",]
headers = detectCharacters(response, headerToDetect)
chunkedtext = chunktext(response, headers)
println("")
_infomatch = chunkedtext["Info matching:"]
_infomatch = GeneralUtils.getStringBetweenCharacters(_infomatch, '{', '}', endCharLocation="next")
infomatch = copy(JSON3.read(_infomatch))
+
+ println("")
+ @show chunkedtext
+
+
keywordMemoryUpdate!(a.memory[:keyword], infomatch)
-
- prompt =
- """
- <|system|>
-
- $aboutYourself
- $(a.roleSpecificInstruction[a.role])
-
+ # prompt =
+ # """
+ # <|system|>
+ #
+ # $aboutYourself
+ # $(a.roleSpecificInstruction[a.role])
+ #
-
- $(a.memory[:shortterm]["Plan 1:"])
-
-
- Use the following format strictly:
- What am I missing: based on Info matching, describe in detail what you are still missing according to the plan
- P.S. do not mention any toolnames
-
-
- Info matching: {"car type": "SUV", "engine type": "electric motor", "color": null, "financing": null}
- What am I missing:
- - The user's preferred color
- - The user's financing method
-
-
- <|assistant|>
- Info matching: $(JSON3.write(a.memory[:keyword]))
- What am I missing:
- """
- response = "What am I missing:" * sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=180,
- stopword=["/n/n", "END", "End", "Obs", "<|", ""])
- response = split(response, "<|")[1]
- response = split(response, "")[1]
+ #
+ # $(a.memory[:shortterm]["Plan 1:"])
+ #
+ #
+ # Use the following format strictly:
+ # What I know: what you know in JSON format
+ # What am I missing: based on what I know, list all items I am missing
+ # P.S. do not mention any toolnames
+ #
+ #
+ # What I know: {"car type": "SUV", "engine type": "electric motor", "color": null, "financing": null}
+ # What am I missing:
+ # - The user's preferred color
+ # - The user's financing method
+ #
+ #
+ # <|assistant|>
+ # What I know: $(JSON3.write(a.memory[:keyword]))
+ # """
+ # response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=180,
+ # stopword=["/n/n", "END", "End", "Obs", "<|", ""])
+ # response = split(response, "<|")[1]
+ # response = split(response, "")[1]
- response = "Info matching:" * chunkedtext["Info matching:"] * response
+ response = "What I know about user:" * JSON3.write(a.memory[:keyword]) # * response
@show selfaware_2 = response
@@ -562,15 +589,12 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
push!(toolslist, toolname)
end
- println("")
- @show actor_selfaware = selfaware
-
thought = "Thought: you should always think about what to do according to the plan (pay attention to correct numeral calculation and commonsense and do one thing at a time.)"
if selfaware !== nothing
thought =
- "Self-awareness: $selfaware
- Thought: To think about your next step, reflect on your self-awareness and prioritize what you need to improve first then consult your plan. (P.S. 1) let's think a single step. 2) pay attention to correct numeral calculation and commonsense.)
+ "Self-awareness: $(JSON3.write(a.memory[:keyword]))
+ Thought: To think about your next step, reflect on your self-awareness and prioritize what you need to improve first (null) then consult your plan. (P.S. 1) let's think a single step. 2) pay attention to correct numeral calculation and commonsense.)
"
end
# your should request the missing information first before making a decision
diff --git a/src/utils.jl b/src/utils.jl
index fc32fd1..69c7654 100644
--- a/src/utils.jl
+++ b/src/utils.jl
@@ -978,7 +978,13 @@ function keywordMemoryUpdate!(keywordmemory::AbstractDict, newinfo::AbstractDict
if v === nothing && haskey(keywordmemory, k) && keywordmemory[k] !== nothing
# skip
else
+ if haskey(keywordmemory, k)
+ println("before k $k v $(keywordmemory[k])") #BUG this function write null to a non-empty key
+ end
+ println("write k $k v $v")
keywordmemory[k] = v
+ println("after k $k v $(keywordmemory[k])")
+ println("-----")
end
end
end