This commit is contained in:
youremail@yourdomain.com
2023-12-22 04:42:21 +00:00
parent f6427d6c35
commit 12c12f64e7
2 changed files with 49 additions and 36 deletions

View File

@@ -187,7 +187,7 @@ function planner_mistral_openorca(a::agentReflex)
The required info you need for wine recommendation:
- type of food: ask the user
- occasion: ask the user
- type of wine (red, white, rose, sparkling, etc): ask the user
- type of wine (red, white, etc): ask the user
- user's personal taste of wine characteristic (sweetness, acidity, etc): ask the user
- wine price range: ask the user
- ambient temperature at the serving location: ask the user
@@ -459,7 +459,7 @@ function actor_mistral_openorca(a::agentReflex)
@show iskey_Act = haskey(chunkedtext, "Act $(a.step):")
@show iskey_Actinput = haskey(chunkedtext, "Actinput $(a.step):")
if iskey_Thought && iskey_Act && iskey_Actinput
if length(chunkedtext["Thought $(a.step):"]) > 10 && length(chunkedtext["Act $(a.step):"]) > 10
if chunkedtext["Thought $(a.step):"] != " " && chunkedtext["Act $(a.step):"] != " "
break
end
end
@@ -690,9 +690,14 @@ function actor(a::agentReflex)
# check whether the current step is completed
isstepcomplete, reason = checkStepCompletion(a)
@show stepcompletecheck = reason
iskey_Thought = haskey(a.memory[:shortterm], "Thought $(a.step):")
chunkedtext = nothing
if !haskey(a.memory[:shortterm], "Thought $(a.step):") # agent didn't do this step yet.
if isstepcomplete # step complete
println(">>> step +1")
a.step += 1
elseif isstepcomplete == false && iskey_Thought == false # step not done, do work
println(">>> working")
# work
toolname, toolinput, chunkedtext = actor_mistral_openorca(a)
println("")
@@ -709,6 +714,7 @@ function actor(a::agentReflex)
actorState = toolname
break
elseif toolname == "noaction"
println(">>> already done")
a.step += 1
else # function call
f = a.tools[toolname][:func]
@@ -717,44 +723,50 @@ function actor(a::agentReflex)
a.memory[:shortterm]["Obs $(a.step):"] = toolresult
a.memory[:log]["Obs $(a.step):"] = toolresult
end
elseif haskey(a.memory[:shortterm], "Thought $(a.step):") && isstepcomplete == false
elseif isstepcomplete == false && iskey_Thought == true # step done but not complete try again
a.memory[:shortterm] = removeHeaders(a.memory[:shortterm], a.step, ["Plan"])
println("repeating step $(a.step)")
elseif haskey(a.memory[:shortterm], "Thought $(a.step):") && isstepcomplete == true
println(">>> step +1")
a.step += 1
else
iskey = haskey(a.memory[:shortterm], "Thought $(a.step):")
error("undefined condition. Thought key=$iskey, isstepcomplete=$isstepcomplete $(@__LINE__)")
error("undefined condition. isstepcomplete=$isstepcomplete, Thought key=$iskey_Thought $(@__LINE__)")
end
# if !haskey(a.memory[:shortterm], "Thought $(a.step):") # agent didn't do this step yet.
# # work
# toolname, toolinput, chunkedtext = actor_mistral_openorca(a)
# println("")
# @show toolname
# @show toolinput
# println("")
# @show a.step
# addShortMem!(a.memory[:shortterm], chunkedtext)
# println("")
# if toolname == "chatbox" # chat with user
# msgToUser = toolinput
# msgToUser = split(msgToUser, "\n\n")[1]
# actorState = toolname
# break
# elseif toolname == "noaction"
# a.step += 1
# else # function call
# f = a.tools[toolname][:func]
# toolresult = f(a, toolinput)
# @show toolresult
# a.memory[:shortterm]["Obs $(a.step):"] = toolresult
# a.memory[:log]["Obs $(a.step):"] = toolresult
# end
# elseif haskey(a.memory[:shortterm], "Thought $(a.step):") && isstepcomplete == false
# a.memory[:shortterm] = removeHeaders(a.memory[:shortterm], a.step, ["Plan"])
# println("repeating step $(a.step)")
# elseif haskey(a.memory[:shortterm], "Thought $(a.step):") && isstepcomplete == true
# println(">>> step +1")
# a.step += 1
# else
# iskey = haskey(a.memory[:shortterm], "Thought $(a.step):")
# error("undefined condition. Thought key=$iskey, isstepcomplete=$isstepcomplete $(@__LINE__)")
# end
@@ -1237,7 +1249,7 @@ function checkStepCompletion(a)
So for instance the following:
Step 2 of the plan: Ask user about their preferred taste of a pizza.
Obs: I love Malvasia.
assistant: I can't find any relevant info that the user tell me their preferred taste in pizza wine according to Obs. Thus, step 2 isn't done yet. {answer: not done}
assistant: I can't find any relevant info that the user tell me their preferred taste in pizza wine according to Thought and Obs. Thus, step 2 isn't done yet. {answer: not done}
Step 5 of the plan: Ask user if they have any preferred type of car.
Obs: I like a semi truck.
@@ -1247,6 +1259,7 @@ function checkStepCompletion(a)
<|assistant|>
"""
response = nothing
_response = nothing
while true
_response = sendReceivePrompt(a, prompt, max_tokens=512)
response = split(_response, "}")[1] * "}"

View File

@@ -167,8 +167,8 @@ function agentReflex(
:actor=>
"""
Your task is to do the following:
Thought: you think what to do based on step {step} of the plan (pay attention to correct numeral calculation and commonsense).
Act: the action to take according to your thought, should be one of [{toolnames}]
Thought: using step {step} of the plan as a guideline, what to do? (pay attention to correct numeral calculation and commonsense).
Act: the action to take based on your thought, must be one of [{toolnames}]
Actinput: your input to the action you chose (pay attention to the tool's input)
Obs: observed result of the action
""",