diff --git a/src/interface.jl b/src/interface.jl index 0eaada8..dfc2aa8 100755 --- a/src/interface.jl +++ b/src/interface.jl @@ -327,7 +327,7 @@ function planner_mistral_openorca(a::agentReflex, usermsg::String) end #WORKING try use Thought/Act/ActInput/Obs loop because some time step 2 depend on step 1 -function actor_mistral_openorca(a::agentReflex) +function actor_mistral_openorca(a::agentReflex, plan) """ general prompt format: @@ -384,10 +384,12 @@ function actor_mistral_openorca(a::agentReflex) """ {env state} {longterm memory} + {plan} """ # context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)") context = replace(context, "{env state}" => "") context = replace(context, "{longterm memory}" => "") + context = replace(context, "{plan}" => "My plan:\n$plan") prompt = replace(prompt, "{context}" => context) return prompt @@ -636,7 +638,7 @@ function work(a::agentReflex, usermsg::String) plan = split(respond, "<|im_end|>")[1] plan = split(plan, "Response:")[1] plan = replace(plan, "Plan:"=>"Plan $(a.attempt):") - a.memory[:shortterm] *= plan + # a.memory[:shortterm] *= plan actorstate, msgToUser = actor(a, plan) error("333") if actorstate == "chatbox" @@ -731,10 +733,9 @@ function actor(a::agentReflex, plan) @show a.step if a.step <= totalsteps # WORKING in step 2, I need to use a.memory[:shortterm] as input to actor() - prompt = actor_mistral_openorca(a) + prompt = actor_mistral_openorca(a, plan) @show prompt respond = sendReceivePrompt(a, prompt) - @show respond # some time LLM not generate a number after headers but I want it if occursin("Act:", respond) @@ -745,11 +746,13 @@ function actor(a::agentReflex, plan) respond = addStepNumber(respond, headers, a.step) end - respond = split(respond, "Obs $(a.step):")[1] + respond = split(respond, "Obs")[1] + respond = split(respond, "<|im_end|>")[1] + @show respond # add to memory a.memory[:shortterm] *= respond - error("111") + headerToDetect = ["Question $(a.step):", "Plan $(a.step):", "Thought $(a.step):", "Act $(a.step):", "ActInput $(a.step):", "Obs $(a.step):", "...", "Answer $(a.step):", "Conclusion $(a.step):", "Summary $(a.step):"] @@ -760,7 +763,7 @@ function actor(a::agentReflex, plan) toolinput = chunkedtext["ActInput $(a.step):"] @show toolname @show toolinput - error(">>>>>>>>>") + if toolname == "chatbox" # chat with user #TODO donot use chatbox to respond to user respond = toolinput diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 525edd0..9c64289 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -41,13 +41,13 @@ function wikisearch(a::agentReflex, phrase::T) where {T<:AbstractString} try result = json_data["query"]["pages"][page_id]["extract"] catch - result = "No info available." + result = "No info available. Try different keywords" end if result == "" - result = "No info available." + result = "No info available. Try different keywords" end - if result != "No info available." #TODO for use with wikisearch(). Not good for other tools + if result != "No info available. Try different keywords" #TODO for use with wikisearch(). Not good for other tools result = makeSummary(a, result) end return result diff --git a/src/type.jl b/src/type.jl index 936fb74..d13c8f9 100644 --- a/src/type.jl +++ b/src/type.jl @@ -41,7 +41,7 @@ abstract type agent end thinkingmode::Symbol = :no_thinking thinkingFormat::Union{Dict, Nothing} = nothing memory::Dict = Dict( - :shortterm=> "", + :shortterm=> "", #WORKING change to Dict :longterm=> Vector{Dict{Symbol, Any}}(), ) end @@ -98,9 +98,9 @@ function agentReflex( Plan: first you should always think about the stimulus and the info you have thoroughly then extract and devise a step by step plan to respond (pay attention to correct numeral calculation and commonsense). """, :actor=> - """Use the following format: - Plan: first you should always think about the question and the info you have thoroughly then extract and devise a complete plan to find the answer (pay attention to variables and their corresponding numerals). - Thought: your should always think about how to do step {step} (pay attention to correct numeral calculation and commonsense). + """ + Use the following format: + Thought: your should always think about how to do 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: the input to the action (pay attention to the tool's input) Obs: the result of the action