update add thoughtlog

This commit is contained in:
2023-11-27 03:01:40 +00:00
parent da983f2874
commit ef67e9fd19
3 changed files with 39 additions and 16 deletions

View File

@@ -609,7 +609,8 @@ function work(a::agentReflex, usermsg::String)
if a.thinkingmode == :new_thinking
a.earlierConversation = conversationSummary(a)
_ = addNewMessage(a, "user", usermsg)
elseif a.thinkingmode == :continue_thinking
a.thoughtlog = "user: $usermsg\n"
elseif a.thinkingmode == :continue_thinking #TODO
error("continue_thinking $(@__LINE__)")
_ = addNewMessage(a, "user", usermsg)
a.thought *= "Obs $(a.attempt): $usermsg\n"
@@ -636,6 +637,7 @@ function work(a::agentReflex, usermsg::String)
_plan = replace(plan, "Plan:"=>"Plan $(a.attempt):")
logmsg = "assistant: $_plan\n"
a.memory[:shortterm] *= logmsg
a.thoughtlog *= logmsg
actorstate, msgToUser = actor(a, plan)
if actorstate == "chatbox"
@@ -658,14 +660,22 @@ function work(a::agentReflex, usermsg::String)
@show score
if score >= 8 # good enough answer
@show a.memory[:shortterm]
# a.memory[:shortterm] = ""
# a.thoughtlog = ""
a.memory[:shortterm] = ""
a.thoughtlog = ""
break
else # self evaluate and reflect then try again
report = analyze(a, a.memory[:shortterm])
@show report
lesson = selfReflext(a, report)
@show lesson
lessonwithcontext = selfReflext(a, report)
@show lessonwithcontext
a.memory[:shortterm] = ""
#TODO add lesson and context into longterm memory
headerToDetect = ["Lesson:", "Context:", ]
headers = detectCharacters(lessonwithcontext, headerToDetect)
chunkedtext = chunktext(lessonwithcontext, headers)
@show chunkedtext
push!(a.memory[:longterm], Dict(:context=>chunkedtext["Context:"],
:lesson=>chunkedtext["Lesson:"]))
error(">>>>>>>>>>")
end
else
@@ -679,10 +689,19 @@ function work(a::agentReflex, usermsg::String)
end
# good enough answer
# communicates with user
_ = addNewMessage(a, "assistant", respond)
return respond
end
function evaluate()
end
"""
Actor function.
@@ -725,6 +744,7 @@ function actor(a::agentReflex, plan::T) where {T<:AbstractString}
# add to memory
_respond = addStepNumber(respond, headers, a.step)
a.memory[:shortterm] *= _respond
a.thoughtlog *= _respond
chunkedtext = chunktext(respond, headers)
toolname = toolNameBeingCalled(chunkedtext["Act:"], a.tools)
@@ -732,10 +752,8 @@ function actor(a::agentReflex, plan::T) where {T<:AbstractString}
@show toolname
@show toolinput
#WORKING
if toolname == "chatbox" # chat with user
respond = toolinput
_ = addNewMessage(a, "assistant", respond)
msgToUser = respond
actorState = toolname
break
@@ -744,6 +762,7 @@ function actor(a::agentReflex, plan::T) where {T<:AbstractString}
result = f(a, toolinput)
_result = "\nObs $(a.step): $result\n"
a.memory[:shortterm] *= _result
a.thoughtlog *= _result
msgToUser = result
end
else #TODO finish all steps
@@ -902,15 +921,16 @@ function analyze(a, shorttermMemory::T) where {T<:AbstractString}
Your work:
$shorttermMemory
Use the following steps to analize your work in detail.
Do each of the following steps in detail to analize your work.
1. What happened?
2. List all cause and effect relationships.
3. Analyze each relationship to figure it out why it behaved that way.
4. What could you do to improve the respond?
2. List all relationships, each with cause and effect .
3. Look at each relationship, figure out why it behaved that way.
4. Do relationships behaved differently than your expectation? If yes, why?
5. What could you do to improve the respond?
<|im_end|>
"""
respond = sendReceivePrompt(a, prompt)
respond = sendReceivePrompt(a, prompt, max_tokens=2048)
return respond
end
@@ -959,11 +979,13 @@ function selfReflext(a, report::T) where {T<:AbstractString}
Your report:
$report
What lesson could be drawn from your report?.
Your job are:
1. Lesson: what lesson could you learn from your report?.
2. Context: what is the context this lesson could apply to?
<|im_end|>
"""
respond = sendReceivePrompt(a, prompt)
respond = sendReceivePrompt(a, prompt, max_tokens=2048)
return respond
end