diff --git a/src/interface.jl b/src/interface.jl
index 062bfeb..d314848 100755
--- a/src/interface.jl
+++ b/src/interface.jl
@@ -182,7 +182,8 @@ function planner_mistral_openorca(a::agentReflex)
toollines = ""
for (toolname, v) in a.tools
if toolname ∉ [""]
- toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
+ # toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
+ toolline = "$toolname: $(v[:description])\n"
toollines *= toolline
end
end
@@ -193,7 +194,8 @@ function planner_mistral_openorca(a::agentReflex)
aboutYourself =
"""
Your name is $(a.agentName)
- $(a.roles[a.role])
+ $(a.roles[a.role])
+ $(a.roleSpecificInstruction[a.role])
"""
assistant_plan_prompt =
@@ -209,7 +211,7 @@ function planner_mistral_openorca(a::agentReflex)
$shorttermMemory
- Plan: first you should always think about your conversation with the user and your earlier work thoroughly then extract and devise a complete, task by task plan to achieve your objective (pay attention to correct numeral calculation and commonsense).
+ Plan: first you should always think about your conversation with the user and your earlier work thoroughly then extract and devise a complete, task by task, plan to achieve your objective (pay attention to correct numeral calculation and commonsense).
P.S.1 each task of the plan should be a single action.
@@ -219,7 +221,7 @@ function planner_mistral_openorca(a::agentReflex)
"""
plan = sendReceivePrompt(a, assistant_plan_prompt, max_tokens=512, temperature=0.1, stopword=["<|", ""])
- # plan = split(plan, "<|")[1]
+ plan = split(plan, "<|")[1]
# plan = split(plan, "\n\n")[1]
return plan
@@ -276,7 +278,59 @@ function updatePlan(a::agentReflex)
end
-function actor_mistral_openorca(a::agentReflex, taskrecap="")
+function selfAwareness(a::agentReflex)
+ getonlykeys = ["Actinput", "Obs"]
+ worknoplan = similar(a.memory[:shortterm])
+ for (k, v) in a.memory[:shortterm]
+ count = 0
+ for i in getonlykeys
+ if occursin(i, k)
+ count += 1
+ end
+ end
+ if count != 0
+ worknoplan[k] = v
+ end
+ end
+
+ work = dictToString(worknoplan)
+
+ aboutYourself =
+ """
+ Your name is $(a.agentName)
+ $(a.roles[a.role])
+ """
+
+ prompt =
+ """
+ <|system|>
+
+ $aboutYourself
+
+
+ $work
+
+ $(a.memory[:shortterm]["Plan 1:"])
+
+
+ Use the following format:
+ What I know: based on observed results, repeat all the details of what you have been gathered.
+ Current progress: check your progress against the plan.
+ What I am missing: describe in detail what you are missing.
+
+
+ <|assistant|>
+ What I know:
+ """
+ response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=180,
+ stopword=["/n/n", "END", "End", "Obs", "<|", ""])
+ @show response
+
+ return response
+end
+
+function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
getonlykeys = ["Actinput", "Obs"]
worknoplan = similar(a.memory[:shortterm])
for (k, v) in a.memory[:shortterm]
@@ -321,7 +375,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
{longterm memory}
"
"""
- #BUG BIG output from winestock cause recap() to fail.
+
toolslist = []
toolnames = ""
toollines = ""
@@ -344,27 +398,17 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
# $conversation
# """
- start = "Thought:"
- aware = ""
thought = "Thought: you should always think about what to do according to the plan (pay attention to correct numeral calculation and commonsense and do one thing at a time.)"
- if length(a.memory[:shortterm]) > 2 # must have User:, Plan:, Thought:, Act:, Actinput:
- start = "Self-awareness:"
+ if selfaware !== nothing
+
# aware = "Self-awareness: based on the recap, assess your progress against the plan then identify areas where you need to address."
# aware = "Self-awareness: based on the recap and the plan, state your current understanding of the matter in details then identify areas where you need to address."
# aware = "Self-awareness: Based on Obs, review your progress against the plan. Then, describe in detail the results you have achieved so far. Finally, describe in detail what you are missing. (focus on your actions and their results)"
# aware = "Self-awareness: Based on action's input and observed results, check your progress against the plan. Then, repeat all the details of what you have been gathered. Finally, describe in detail what you are missing."
- aware = "Self-awareness: Based on action's input and observed results, repeat all the details of what you have been gathered. Then, check your progress against the plan. Finally, describe in detail what you are missing."
- thought = "Thought: you should always think about what to do according to self-awareness (1. let's think a single step. 2. focus on incomplete task 3. pay attention to correct numeral calculation and commonsense.)"
- end
-
- winestockResult = ""
- if a.winestockResult != ""
- winestockResult =
- """
-
- $(a.winestockResult)
-
- """
+ thought =
+ "Self-awareness: $selfaware
+ Thought: you should always think about what to do according to self-awareness (1. let's think a single step. 2. focus on incomplete task 3. pay attention to correct numeral calculation and commonsense.)
+ "
end
aboutYourself =
@@ -387,17 +431,21 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
Use the following format:
- $aware
$thought
Act: an action you intend to do according to your thought, must be one of [{toolnames}].
Actinput: your input to the action (pay attention to the tool's input)
Obs: observed result of the action
- END: end of session
+
+ Thought: Greet user and begin the conversation.
+ Act: askbox
+ Actinput 2: {\"askbox\": \"Hello! Welcome to our wine store. I'd be happy to help you find a perfect bottle for your occasion. Could you please tell me about the special event or occasion for which you are buying this wine?\"}
+
+
<|assistant|>
$work
- $start
+ "Thought:"
"""
prompt = replace(prompt, "{toolnames}" => toolnames)
@@ -424,7 +472,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
# response = "Self-awareness $latestTask: " * response
# end
- response = start * response
+ response = "Thought:" * response
headerToDetect = ["Question:", "Plan:", "Self-awareness:", "Thought:",
"Act:", "Actinput:", "Obs:", "...",
@@ -463,15 +511,17 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
break
end
end
+
if length(chunkedtext["Thought $latestTask:"]) > 5 && istoolnameValid &&
- length(chunkedtext["Actinput $latestTask:"]) > 5
+ length(chunkedtext["Actinput $latestTask:"]) > 5 &&
+ occursin('{', response) && occursin('}', response)
break
end
end
+ println("retry actor")
end
toolname = toolNameBeingCalled(chunkedtext["Act $latestTask:"], a.tools)
- toolinput = chunkedtext["Actinput $latestTask:"]
# change trailing number to continue a.memory[:shortterm]
headerToDetect = ["Question:", "Plan:", "Self-awareness:", "Thought:",
@@ -479,7 +529,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
"Answer:", "Conclusion:", "Summary:"]
response = replaceHeaders(response, headerToDetect, latestTask)
println("")
- @show actor_response = response
+ @show actor_response_1 = response
headerToDetect = ["Plan $(a.attempt):",
"Thought $latestTask:",
"Act $latestTask:",
@@ -489,7 +539,14 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
headers = detectCharacters(response, headerToDetect)
chunkedtext = chunktext(response, headers)
chunkedtext = delete!(chunkedtext, "Self-awareness $latestTask")
- chunkedtext["Actinput $latestTask:"] = split(chunkedtext["Actinput $latestTask:"], "\n\n")[1]
+ act = GeneralUtils.getStringBetweenCharacters(response, '{', '}', endCharLocation="end")
+ println("")
+ @show actor_response_2 = act
+ act = Dict(JSON3.read(act))
+
+ chunkedtext["Act $latestTask:"] = toolname
+ chunkedtext["Actinput $latestTask:"] = act[Symbol(toolname)]
+ toolinput = chunkedtext["Actinput $latestTask:"]
return toolname, toolinput, chunkedtext
end
@@ -711,7 +768,13 @@ function actor(a::agentReflex)
latestTask = shortMemLatestTask(a.memory[:shortterm]) +1
println(">>> working")
# work
- toolname, toolinput, chunkedtext = actor_mistral_openorca(a)
+ selfaware = nothing
+ if length(a.memory[:shortterm]) > 2 # must have User:, Plan:, Thought:, Act:, Actinput: already
+ selfaware = selfAwareness(a)
+ println("")
+ @show selfaware
+ end
+ toolname, toolinput, chunkedtext = actor_mistral_openorca(a, selfaware)
println("")
@show toolname
@show toolinput
diff --git a/src/llmfunction.jl b/src/llmfunction.jl
index 0c0badd..6ee73dd 100644
--- a/src/llmfunction.jl
+++ b/src/llmfunction.jl
@@ -114,7 +114,12 @@ end
julia> score = grading(agent, guideline, shorttermMemory)
```
"""
-function winestockDB(a::agentReflex, phrase::T) where {T<:AbstractString}
+function winestockDB(a::agentReflex, query::T) where {T<:AbstractString}
+ @show query
+
+
+
+ error("winestockDB done")
return result
end
diff --git a/src/type.jl b/src/type.jl
index 0fcc245..8f3a370 100644
--- a/src/type.jl
+++ b/src/type.jl
@@ -98,6 +98,7 @@ julia> agent = ChatAgent.agentReflex(
task::Int = 1 # task number
env::AbstractString = "N/A"
thinkingFormat::Union{Dict, Nothing} = nothing
+ roleSpecificInstruction::Union{Dict, Nothing} = nothing
memory::Dict = Dict(
:shortterm=> OrderedDict{String, Any}(),
:longterm=> OrderedDict{String, Any}(),
@@ -243,6 +244,7 @@ function agentReflex(
newAgent.role = role
newAgent.roles = roles
newAgent.thinkingFormat = thinkingFormat
+ newAgent.roleSpecificInstruction = roleSpecificInstruction
newAgent.agentName = agentName
return newAgent