This commit is contained in:
2026-06-30 21:18:59 +07:00
parent d076d5f912
commit b4f2a6185b
7 changed files with 443 additions and 510 deletions
+7 -87
View File
@@ -130,7 +130,9 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
context =
"""
<internal_context_for_assistant>
$(GeneralUtils.dict_to_string_html(a.memory["shortmem"]))
<thought_history>
$(GeneralUtils.dict_to_string_html(a.memory["shortmem"]))
</thought_history>
</internal_context_for_assistant>
"""
@@ -150,14 +152,15 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
println("\nYiemAgent decisionMaker() attempt $attempt/$maxattempt ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
end
openai_msg = Dict(
msg = Dict(
"model" => "gemma-4-E4B-it-UD-Q4_K_XL",
"messages" => a.chathistory,
"temperature" => 0.7
)
response = a.context.text2textInstructLLM(a.id, openai_msg)
# response = GeneralUtils.deFormatLLMtext(response, a.llmFormatName)
response = a.context.text2textInstructLLM(a.id, msg)
response = GeneralUtils.clean_json_response(response)
response = GeneralUtils.remove_french_accents(response)
think, response = GeneralUtils.extractthink(response)
response = String(split(response, ", observation")[1]) # in case LLM generate observation key which it isn't supposed to
@@ -188,89 +191,6 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10
println("\nYiem decisionMaker() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
pprintln(Dict(responsedict))
# # check whether an agent recommend wines before checking inventory or recommend wines
# # outside its inventory
# # ask LLM whether there are any winery mentioned in the response
# mentioned_winery = detectWineryName(a, response)
# if mentioned_winery != "None"
# mentioned_winery = String.(strip.(split(mentioned_winery, ",")))
# # check whether the wine is in event
# isWineInEvent = false
# for winename in mentioned_winery
# for event in a.memory["events"]
# if event["observation"] !== nothing && occursin(winename, event["observation"])
# isWineInEvent = true
# break
# end
# end
# end
# # then the agent is not supposed to recommend the wine
# if isWineInEvent == false
# errornote = "You recommended wines that are not in your inventory before. Please only recommend wines that you have previously found in your inventory."
# println("\nERROR YiemAgent decisionMaker() $errornote $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
# continue
# end
# end
# delete!(responsedict, :mentioned_winery)
# check whether responsedict["action_input"] is the same as previous dialogue
# if !isempty(a.chathistory) && responsedict["action_input"] == a.chathistory[end]["text"]
# errornote = "In your previous attempt, you repeated the previous dialogue. Please try again."
# println("\nERROR YiemAgent decisionMaker() $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
# continue
# end
# evaluationdict = evaluator(a, timeline, responsedict, context)
# if evaluationdict[:approval] == "no"
# mentor_comment = evaluationdict[:suggestion]
# errornote = "Your previous attempt was not good enough. Please try again. Here is the mentor's suggestion: $mentor_comment"
# println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> \n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
# continue
# end
# # store for later training
# responsedict["system"] = systemmsg
# responsedict["unformatPrompt"] = unformatPrompt
# responsedict["prompt"] = prompt
# responsedict["context"] = context
# responsedict["think"] = think
# responsedict["response"] = response
# # responsedict["QandA"] = QandA
# # check whether there is a file path exists before writing to it
# if !haskey(a.memory["shortmem"], "decisionlog")
# a.memory["shortmem"]["decisionlog"] = [responsedict]
# else
# push!(a.memory["shortmem"]["decisionlog"], responsedict)
# end
# # save to filename ./log/decisionlog.txt
# println("\nsaving YiemAgent decisionMaker() to disk ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
# filename = "agent_decision_log_$(a.id).json"
# filepath = "/appfolder/app/log/$filename"
# # check whether there is a file path exists before writing to it
# if !isfile(filepath)
# decisionlist = [responsedict]
# println("Creating file $filepath")
# open(filepath, "w") do io
# JSON.pretty(io, decisionlist)
# end
# else
# # read the file and append new data
# decisionlist = copy(JSON.parsefile(filepath))
# push!(decisionlist, responsedict)
# println("Appending new data to file $filepath")
# open(filepath, "w") do io
# JSON.pretty(io, decisionlist)
# end
# end
# println("\nYiemAgent decisionMaker() saved to disk is done. agent $(a.id)")
# responsedict["prompt"] = prompt
return responsedict
end
error("DecisionMaker failed to generate a thought ", response)