diff --git a/src/interface.jl b/src/interface.jl index ecb5dff..85d2de1 100755 --- a/src/interface.jl +++ b/src/interface.jl @@ -230,11 +230,11 @@ function chat_mistral_openorca(a::agentReflex, usermsg::String) context = """ {earlierConversation} - {current status} + {env state} {longterm memory} """ context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)") - context = replace(context, "{current status}" => "") + context = replace(context, "{env state}" => "") context = replace(context, "{longterm memory}" => "") prompt = replace(prompt, "{context}" => context) @@ -303,11 +303,11 @@ function planner_mistral_openorca(a::agentReflex, usermsg::String) context = """ {earlierConversation} - {current status} + {env state} {longterm memory} """ context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)") - context = replace(context, "{current status}" => "") + context = replace(context, "{env state}" => "") context = replace(context, "{longterm memory}" => "") prompt = replace(prompt, "{context}" => context) @@ -359,7 +359,7 @@ function actor_mistral_openorca(a::agentReflex, usermsg::T) where {T<:AbstractSt <|im_start|>assistant """ - error("actor_mistral_openorca done") + prompt = replace(prompt, "{role}" => a.roles[a.role]) prompt = replace(prompt, "{thinkingFormat}" => a.thinkingFormat[:actor]) toolnames = "" @@ -375,17 +375,17 @@ function actor_mistral_openorca(a::agentReflex, usermsg::T) where {T<:AbstractSt context = """ {earlierConversation} - {current status} + {env state} {longterm memory} """ context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)") - context = replace(context, "{current status}" => "") + context = replace(context, "{env state}" => "") context = replace(context, "{longterm memory}" => "") prompt = replace(prompt, "{context}" => context) prompt = replace(prompt, "{usermsg}" => "Stimulus: $usermsg") - + error("actor_mistral_openorca done") return prompt end @@ -629,17 +629,17 @@ function work(a::agentReflex, usermsg::String) respond = sendReceivePrompt(a, prompt) plan = split(respond, "<|im_end|>")[1] @show plan + totalsteps = checkTotalStepInPlan(a, plan) logmsg = "<|im_start|>assistant:\n$plan\n" a.memory[:shortterm] *= logmsg a.step = 0 while true # execute step by step a.step += 1 - isstep, task = extractStepFromPlan(a, plan) - @show isstep - @show task - if isstep - respond = actor_mistral_openorca(a, task) + if a.step <= totalsteps + stepdetail = extractStepFromPlan(a, plan, a.step) + @show stepdetail + respond = actor_mistral_openorca(a, stepdetail) error("work done 1") else # finish all steps error("work done 2") @@ -1119,16 +1119,16 @@ function chunktext(text::T, headers) where {T<:AbstractString} end -function extractStepFromPlan(a::agent, plan::T) where {T<:AbstractString} +function extractStepFromPlan(a::agent, plan::T, step::Int) where {T<:AbstractString} prompt = """ <|im_start|>system You are a helpful assistant. - Your job is to determine whether step {$(a.step)} is in the user plan. + Your job is to extract step 2 in the user plan. + + Use the following format only: + {copy the step and put it here} - Choose one of the following choices: - If there isn't say, {no} - If there is say, {yes} {copy the step and put it here} <|im_end|> <|im_start|>user @@ -1137,31 +1137,34 @@ function extractStepFromPlan(a::agent, plan::T) where {T<:AbstractString} <|im_start|>assistant """ - isStep = nothing - step = nothing - for i in 1:3 - respond = sendReceivePrompt(a, prompt) - isStep = GeneralUtils.getStringBetweenCharacters(respond, "{", "}") - if isStep == "no" - isStep = false - step = "nothing" - break - elseif isStep == "yes" - isStep = true - step = split(respond, "{yes}")[end] - break - else - # keep trying - isStep = nothing - step = nothing - end - end - if isStep === nothing || step === nothing - error("undefined condition. step $(a.step) isStep=$isStep $(@__LINE__)") - end + respond = sendReceivePrompt(a, prompt) - return isStep, step + return respond +end + +function checkTotalStepInPlan(a::agent, plan::T) where {T<:AbstractString} + prompt = + """ + <|im_start|>system + You are a helpful assistant. + Your job is to determine how many steps in a user plan. + + Use the following format only: + {total step number} + <|im_end|> + + <|im_start|>user + $plan + <|im_end|> + <|im_start|>assistant + + """ + respond = sendReceivePrompt(a, prompt) + result = GeneralUtils.getStringBetweenCharacters(respond, "{", "}") + result = parse(Int, result) + + return result end @@ -1207,8 +1210,6 @@ end - -