From d90ff8d3fcf247fe5bd8846bd7ab771eb930827a Mon Sep 17 00:00:00 2001 From: tonaerospace Date: Mon, 18 Dec 2023 14:17:21 +0000 Subject: [PATCH] update --- src/interface.jl | 38 ++++++++++++++++++++++++-------------- src/type.jl | 2 +- src/utils.jl | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 87912d4..ee8594c 100755 --- a/src/interface.jl +++ b/src/interface.jl @@ -175,6 +175,9 @@ function planner_mistral_openorca(a::agentReflex) toollines *= toolline end end + + # skip objective and plan because LLM is going to generate new plan + shorttermMemory = dictToString(a.memory[:shortterm], skiplist=["Objective:", "Plan 0:"]) assistant_plan_prompt = """ @@ -192,12 +195,15 @@ function planner_mistral_openorca(a::agentReflex) You have access to the following tools: $toollines + Your work: + $shorttermMemory + Use the following format: Objective: the objective you intend to do - Aware: ask yourself what info you don't have? - Plan: first you should always think about the objective, the info you have, the info you don't have and thoroughly then extract and devise a complete, step by step plan (pay attention to correct numeral calculation and commonsense). + Aware: according to your work and your conversation with the user, ask yourself what info you have and what info you doesn't have? + Plan: first you should always think about the objective, the info you have, the info you doesn't have thoroughly then extract and devise a complete, step by step plan (pay attention to correct numeral calculation and commonsense). P.S.1 each step of the plan should be a single action. - P.S.2 ask the user all you need to know and then search your inventory. + P.S.2 ask the user if you don't have info. <|im_end|> $conversation @@ -329,6 +335,9 @@ function actor_mistral_openorca(a::agentReflex) prompt = replace(prompt, "{toolnames}" => toolnames) prompt = replace(prompt, "{step}" => a.step) + println("") + @show prompt_actor = prompt + response = nothing chunkedtext = nothing @@ -349,12 +358,12 @@ function actor_mistral_openorca(a::agentReflex) # replace headers with headers with correct attempt and step number response = replaceHeaders(response, headerToDetect, a.step) + response = split(response, "\n\n ")[1] headers = detectCharacters(response, headerToDetect) println("") - response_actor = response - @show response_actor + @show response_actor = response headerToDetect = ["Plan $(a.attempt):", "Thought $(a.step):", @@ -364,7 +373,6 @@ function actor_mistral_openorca(a::agentReflex) "Check $(a.step):",] headers = detectCharacters(response, headerToDetect) chunkedtext = chunktext(response, headers) - @show chunkedtext # assuming length more than 10 character means LLM has valid thinking if length(chunkedtext["Thought $(a.step):"]) > 10 @@ -383,21 +391,21 @@ function actor_mistral_openorca(a::agentReflex) headerToDetect = ["Question:", "Plan:", "Thought:", "Act:", "Actinput:", "Obs:", "...", "Answer:", "Conclusion:", "Summary:"] - response = replaceHeaders(response, headerToDetect, latest_step+1) + nextstep = latest_step+1 # next step in short term memory + response = replaceHeaders(response, headerToDetect, nextstep) headerToDetect = ["Plan $(a.attempt):", - "Thought $latest_step:", - "Act $latest_step:", - "Actinput $latest_step:", - "Obs $latest_step:", - "Check $latest_step:",] + "Thought $nextstep:", + "Act $nextstep:", + "Actinput $nextstep:", + "Obs $nextstep:", + "Check $nextstep:",] headers = detectCharacters(response, headerToDetect) chunkedtext = chunktext(response, headers) # add to memory addShortMem!(a.memory[:shortterm], chunkedtext) a.memory[:log] = addShortMem!(a.memory[:log], chunkedtext) - @show a.memory[:shortterm] - error(1) + return toolname, toolinput end @@ -476,6 +484,7 @@ function work(a::agentReflex) workstate = nothing response = nothing + #BUG there is no Obs 2: # user answering LLM -> Obs if haskey(a.memory[:shortterm], "Act $(a.step):") if occursin("chatbox", a.memory[:shortterm]["Act $(a.step):"]) @@ -509,6 +518,7 @@ function work(a::agentReflex) a.memory[:shortterm]["Objective:"] = objective a.memory[:shortterm]["Plan $(a.attempt):"] = plan a.memory[:log]["Plan $(a.attempt):"] = plan + a.step = 0 # reset because new plan is created println("") @show objective diff --git a/src/type.jl b/src/type.jl index acdd52c..643fb39 100644 --- a/src/type.jl +++ b/src/type.jl @@ -167,7 +167,7 @@ function agentReflex( :actor=> """ Use the following format: - Thought: you should always think about how to carry out step {step} of the plan (pay attention to correct numeral calculation and commonsense). + Thought: you should always think about what to do according to step {step} of the plan (pay attention to correct numeral calculation and commonsense). Act: the action to take that match your thought, should be one of [{toolnames}] Actinput: your input to the action you chose (pay attention to the tool's input) Obs: the result of the action diff --git a/src/utils.jl b/src/utils.jl index 7b8566c..a7a2f69 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -673,7 +673,7 @@ end function dictToString(shortMemory::T; - skiplist::Union{Array{String}, Array{Symbol}}=[""]) where {T<:AbstractDict} + skiplist::Union{Vector{String}, Vector{Symbol}}=[""]) where {T<:AbstractDict} s = "" for (k, v) in shortMemory if k ∉ skiplist