This commit is contained in:
2023-12-08 01:30:49 +00:00
parent c4d090ee72
commit d04379b782
2 changed files with 23 additions and 17 deletions

View File

@@ -631,6 +631,8 @@ function work(a::agentReflex, usermsg::String)
if a.thinkingmode == :new_thinking
_ = addNewMessage(a, "user", usermsg)
a.memory[:shortterm] = OrderedDict{String, Any}()
a.memory[:log] = OrderedDict{String, Any}()
a.memory[:shortterm]["user:"] = usermsg
a.memory[:log]["user:"] = usermsg
a.newplan = true
@@ -655,9 +657,7 @@ function work(a::agentReflex, usermsg::String)
println("")
@show prompt_plan
respond = sendReceivePrompt(a, prompt_plan, max_tokens=1024)
println("")
plan_raw = respond
@show plan_raw
# sometimes LLM add not-need word I don't want
plan = splittext(respond, ["Step 1", "<|im_end|>", "Response", "Execution",
"Result", "Recommendation", "My response"])
@@ -670,8 +670,8 @@ function work(a::agentReflex, usermsg::String)
a.memory[:log]["Plan $(a.attempt):"] = plan
end
println("")
@show a.attempt
@show a.memory[:shortterm]["user:"]
# enter actor loop
actorstate, msgToUser = actor(a)
@@ -693,18 +693,22 @@ function work(a::agentReflex, usermsg::String)
# evaluate. if score < 8/10 try again.
guideline = writeEvaluationGuideline(a, a.memory[:shortterm]["user:"])
println("")
@show guideline
score = grading(a, guideline, respond)
@show score
if score >= 8 # good enough answer
@show a.memory[:shortterm]
a.memory[:shortterm] = OrderedDict{String, Any}()
a.memory[:log] = OrderedDict{String, Any}()
if score >= 6 # good enough answer
break
else # self evaluate and reflect then try again
analysis = analyze(a)
println("")
@show analysis
lessonwithcontext = selfReflext(a, analysis)
println("")
@show lessonwithcontext
newdict = OrderedDict()
@@ -714,10 +718,13 @@ function work(a::agentReflex, usermsg::String)
headerToDetect = ["Lesson:", "Context:", ]
headers = detectCharacters(lessonwithcontext, headerToDetect)
chunkedtext = chunktext(lessonwithcontext, headers)
@show chunkedtext
a.memory[:longterm][chunkedtext["Context:"]] = chunkedtext["Lesson:"]
a.newplan = true
println("")
println("RETRY $(a.attempt +1)")
println("")
end
else
error("undefied condition, actorstate $actorstate $(@__LINE__)")
@@ -796,13 +803,13 @@ function actor(a::agentReflex)
if a.step < totalsteps
prompt_actor = actor_mistral_openorca(a)
println("")
@show prompt_actor
respond = sendReceivePrompt(a, prompt_actor)
respond = splittext(respond, ["Obs", "<|im_end|>"])
respond_actor_raw = respond
println("")
@show respond_actor_raw
if !occursin("Thought", respond)
respond = "Thought: " * respond
end
@@ -816,8 +823,8 @@ function actor(a::agentReflex)
headers = detectCharacters(respond, headerToDetect)
respond_actor = respond
println("")
respond_actor = respond
@show respond_actor
headerToDetect = ["Plan $(a.attempt):",
@@ -828,7 +835,7 @@ function actor(a::agentReflex)
"Check $(a.step):",]
headers = detectCharacters(respond, headerToDetect)
chunkedtext = chunktext(respond, headers)
@show chunkedtext
# add to memory
a.memory[:shortterm] = addShortMem!(a.memory[:shortterm], chunkedtext)
@@ -1220,9 +1227,7 @@ function goNogo(a)
respond = sendReceivePrompt(a, prompt)
println("")
goNogo_raw = respond
@show goNogo_raw
decision = nothing
reason = nothing

View File

@@ -105,6 +105,7 @@ function agentReflex(
Stimulus: the input user gives to you and you must respond
Plan: first you should always think about the stimulus, the info you need and the info you have thoroughly then extract and devise a step by step plan (pay attention to correct numeral calculation and commonsense).
p.s.1 each step should be a single action.
p.s.2 don't respond to the stimulus yet.
""",
:actor=>
"""