diff --git a/src/interface.jl b/src/interface.jl
index 62623bb..f550cbd 100755
--- a/src/interface.jl
+++ b/src/interface.jl
@@ -4,7 +4,8 @@ module interface
export agentReact, agentReflex,
addNewMessage, clearMessage, removeLatestMsg, conversation, directconversation,
writeEvaluationGuideline, grading, analyze, selfReflext,
- formulateUserresponse, extractinfo, updateEnvState, chat_mistral_openorca
+ formulateUserresponse, extractinfo, updateEnvState, chat_mistral_openorca,
+ recap
using JSON3, DataStructures, Dates, UUIDs, HTTP
using CommUtils, GeneralUtils
@@ -128,7 +129,7 @@ function chat_mistral_openorca(a::agentReflex)
$(a.roles[a.role])
Your earlier talk with the user:
$(a.earlierConversation)
- <|/s|>
+
$conversation
<|assistant|>
"""
@@ -202,7 +203,7 @@ function planner_mistral_openorca(a::agentReflex)
Your job is to do the following:
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.
- <|/s|>
+
$conversation
<|assistant|>
Plan:
@@ -256,7 +257,7 @@ function updatePlan(a::agentReflex)
Plan: 1. Ask the user for their food type.
Obs: It will be Thai dishes.
Updated plan: 1. Ask the user for their food type (Thai dishes).
-
+
Updated plan:
"""
@@ -304,7 +305,9 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
shorttermMemory = dictToString(a.memory[:shortterm], skiplist=["user:"])
- # conversation = messagesToString_nomark(a.messages, addressAIas="I")
+ # conversation = conversationSummary(a)
+ # println("")
+ # @show conversationSum = conversation
# context =
# """
@@ -322,9 +325,9 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
$(a.memory[:shortterm]["Plan 1:"])
-
+
$taskrecap
-
+
Use the following format:
Thought: based on the plan and the recap of the plan, what to do? (pay attention to correct numeral calculation and commonsense).
@@ -332,16 +335,16 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
Actinput: your input to the action based on your thought (pay attention to the tool's input)
Obs: observed result of the action
- P.S.1 ask user one by one question.
+ P.S.1 ask the user one by one question.
- <|/s|>
+
<|assistant|>
Thought:
"""
prompt = replace(prompt, "{toolnames}" => toolnames)
println("")
- @show prompt_actor = prompt
+ @show actor_prompt = prompt
response = nothing
chunkedtext = nothing
@@ -370,7 +373,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="")
headers = detectCharacters(response, headerToDetect)
println("")
- @show response_actor = response
+ @show actor_response = response
headerToDetect = ["Plan $(a.attempt):",
"Thought $latestTask:",
@@ -925,7 +928,7 @@ function formulateUserresponse(a)
$work
From your talk with the user and your work, formulate a response for the user.
- <|/s|>
+
<|assistant|>
response:
"""
@@ -1088,14 +1091,14 @@ function checkTaskCompletion(a)
Let's think step by step.
-
+
<|assistant|> After
"""
response = nothing
_response = nothing
_response = sendReceivePrompt(a, prompt, max_tokens=512)
@show checkTaskCompletion_raw = _response
- _response = split(_response, "")[1]
+ _response = split(_response, "")[1]
_response = split(_response, "\n\n")[1]
# response = "I " * split(_response, "{")[1] # sometime response have more than 1 {answer: done}
@@ -1110,9 +1113,46 @@ function checkTaskCompletion(a)
end
function recap(a)
- @show a.memory[:shortterm]["Plan 1:"]
# stimulus = a.memory[:shortterm]["user:"]
- work = dictToString(a.memory[:shortterm])
+ 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)
+
+ # prompt =
+ # """
+ # <|system|>
+ #
+ # Plan: a plan
+ # Thought: your thought
+ # Act: the action you took
+ # Actinput: the input to the action
+ # Obs: the result of the action
+ #
+
+ #
+ # $work
+ #
+ #
+ # Recap: list all your observed results in detail
+ #
+
+ # Let's think step by step.
+ #
+ # <|assistant|>
+ # Recap:
+ # """
prompt =
"""
@@ -1129,16 +1169,19 @@ function recap(a)
$work
- Recap: list all your observed results in detail
+ Extract info: extract info in details from ALL Actinput and corresponding observed result into JSON format
Let's think step by step.
-
+
<|assistant|>
- Recap:
+ Extracted info:
"""
+
response = sendReceivePrompt(a, prompt, max_tokens=512, temperature=0.0)
- response = split(response, "")[1]
+ response = split(response, "")[1]
+ response = split(response, "<|")[1]
+ response = split(response, "\n\n")[1]
return response
end
diff --git a/src/type.jl b/src/type.jl
index 2caea59..f476785 100644
--- a/src/type.jl
+++ b/src/type.jl
@@ -173,7 +173,8 @@ function agentReflex(
Actinput: your input to the action based on your thought (pay attention to the tool's input)
Obs: observed result of the action
- P.S.1 ask user one by one question.
+ P.S.1 ask the user one by one question.
+ P.S.2 ask the user what you want to know if you didn't ask yet.
""",
:actorOriginal=>
diff --git a/src/utils.jl b/src/utils.jl
index 3aef1c5..e4f626c 100644
--- a/src/utils.jl
+++ b/src/utils.jl
@@ -1,6 +1,6 @@
module utils
-export makeSummary, sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalTaskInPlan,
+export sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalTaskInPlan,
detectCharacters, findDetectedCharacter, extract_number, toolNameBeingCalled,
isUsePlans, conversationSummary, checkReasonableness, replaceHeaders,
addShortMem!, splittext, dictToString, removeHeaders, keepOnlyKeys, experience,
@@ -12,49 +12,6 @@ using ..type
#------------------------------------------------------------------------------------------------100
-function makeSummary(a::T1, input::T2) where {T1<:agent, T2<:AbstractString}
- summary = "Nothing."
- prompt =
- """
- <|im_start|>system
- Input text:
- $input
-
- Your job is to determine now whether you can make a summary of the input text by choosing one of following choices:
- If you cannot make a summary say, "{No}".
- If you can make a summary say, "{Yes}".
- <|im_end|>
- """
- prompt = replace(prompt, "{input}" => input)
- result = sendReceivePrompt(a, prompt)
- result = GeneralUtils.getStringBetweenCharacters(result, "{", "}")
- if result == "Yes" # seperate summary part
- prompt =
- """
- <|im_start|>system
- Input text:
- $input
- Your job is to make a concise summary of the input text.
- <|im_end|>
- """
- result = sendReceivePrompt(a, prompt)
- if result[1:1] == "\n"
- summary = result[2:end]
- else
- summary = result
- end
- end
- input_summary = input
- @show input_summary
- @show summary
-
- return summary
-end
-
-
-
-
-
"""
Send a msg to registered mqtt topic within mqttClient.
@@ -496,43 +453,22 @@ end
```
"""
function conversationSummary(a::T) where {T<:agent}
+ conversation = messagesToString_nomark(a.messages, addressAIas="I")
prompt =
"""
- <|im_start|>system
- You talked with a user earlier.
- Now you make a detailed bullet summary of the conversation from your perspective.
+ <|system|>
+ Your conversation with the user:
+ $conversation
+
+ Your job is to paraphrase a conversation from your perspective.
You must refers to yourself by "I" in the summary.
-
- Here are the conversation:
- {conversation}
- <|im_end|>
-
+ <|/s|>
+ <|assistant|>
+ Paraphrase:
"""
- conversation = ""
- summary = ""
- if length(a.messages)!= 0
- for msg in a.messages[1:end-1]
- role = msg[:role]
- content = msg[:content]
-
- if role == "user"
- conversation *= "$role: $content\n"
- elseif role == "assistant"
- conversation *= "I: $content\n"
- else
- error("undefied condition role = $role $(@__LINE__)")
- end
- end
-
- prompt = replace(prompt, "{conversation}" => conversation)
- result = sendReceivePrompt(a, prompt)
- summary = result === nothing ? "N/A" : result
- summary = split(summary, "<|im_end|>")[1]
- if summary[1:1] == "\n"
- summary = summary[2:end]
- end
- end
- @show summary
+ result = sendReceivePrompt(a, prompt)
+ summary = split(result, "<|/s|>")[1]
+ summary =
return summary
end