Compare commits

...

4 Commits

Author SHA1 Message Date
ton 1eea6c66b6 Merge pull request 'update' (#38) from v0.7.4-add_vector_search into v0.7.4
Reviewed-on: #38
2026-07-27 10:43:41 +00:00
ton 37ff68c963 update 2026-07-27 17:43:11 +07:00
ton e5fc800c83 Merge pull request 'update' (#37) from v0.7.4-add_vector_search into v0.7.4
Reviewed-on: #37
2026-07-27 09:55:11 +00:00
ton 4397ec5fb3 update 2026-07-27 16:54:36 +07:00
3 changed files with 64 additions and 109 deletions
+57 -101
View File
@@ -76,35 +76,7 @@ OrderedDict{String, Any} with 4 entries:
function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3 function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3
) where {T<:agent} ) where {T<:agent}
@info "YiemAgent decisionMaker() start " @__LINE__ @info "YiemAgent decisionMaker() start " @__LINE__
# lessonDict = copy(JSON.parsefile("lesson.json"))
# lesson =
# if isempty(lessonDict)
# ""
# else
# lessons = Dict{String, Any}()
# for (k, v) in lessonDict
# lessons[k] = lessonDict[k][:lesson]
# end
# """
# You have attempted to help the user before and failed, either because your reasoning for the
# recommendation was incorrect or your response did not exactly match the user expectation.
# The following lesson(s) give a plan to avoid failing to help the user in the same way you
# did previously. Use them to improve your strategy to help the user.
# Here are some lessons in JSON format:
# $(JSON.json(lessons))
# When providing the thought and action for the current trial, that into account these failed
# trajectories and make sure not to repeat the same mistakes and incorrect answers.
# """
# end
# recentevents_ind = GeneralUtils.recentElementsIndex(
# length(a.memory["events"]), recentevents; includelatest=true)
requiredKeys = ["plan", "action_name", "action_input"]
context = context =
""" """
<internal_context_for_assistant> <internal_context_for_assistant>
@@ -141,7 +113,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3
"action_name": { "action_name": {
"type": "string", "type": "string",
"enum": ["search_web", "get_weather", "calculate_math"], "enum": ["search_web", "get_weather", "calculate_math"],
"description": "The exact name of the tool to execute." "description": "The exact name of the action to execute."
}, },
"action_input": { "action_input": {
"type": "object", "type": "object",
@@ -171,11 +143,26 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3
"schema"=> Dict( "schema"=> Dict(
"type"=> "object", "type"=> "object",
"properties"=> Dict( "properties"=> Dict(
"plan"=> Dict("type"=> "string"), "think"=> Dict(
"action_name"=> Dict("type"=> "string"), "type"=> "string",
"action_input"=> Dict("type"=> "string"), "description"=> "Your step-by-step reasoning process. Explain why you are choosing this action."
),
"action_name"=> Dict(
"type"=> "string",
"enum"=> ["CHAT_BOX", "SEARCH_WINE_DATABASE", "WINE_PRESENTATION_GUIDELINE", "END_CONVER_GUIDELINE"],
"description"=> "one of the available actions"
),
"action_input"=> Dict(
"type"=> "object",
"properties"=> Dict(
"dialogue"=> Dict("type"=> "string", "description"=> "for CHAT_BOX"),
"query"=> Dict("type"=> "string", "description"=> "for SEARCH_WINE_DATABASE"),
"present_guide"=> Dict("type"=> "null", "description"=> "for WINE_PRESENTATION_GUIDELINE"),
"endconv_guide"=> Dict("type"=> "null", "description"=> "for END_CONVER_GUIDELINE"),
)
),
), ),
"required"=> ["plan", "action_name", "action_input"], "required"=> ["think", "action_name", "action_input"],
"additionalProperties"=> false "additionalProperties"=> false
) )
) )
@@ -191,56 +178,41 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3
for attempt in 1:maxattempt for attempt in 1:maxattempt
response = a.context.text2textInstructLLM(a.id, msg) response = a.context.text2textInstructLLM(a.id, msg)
response = GeneralUtils.remove_french_accents(response) response = GeneralUtils.remove_french_accents(response)
# think, response = GeneralUtils.extractthink(response)
# dollar sign in Julia means string interpolation # dollar sign in Julia means string interpolation
while occursin('$', response) while occursin('$', response)
response = replace(response, '$' => "USD") response = replace(response, '$' => "USD")
end end
# responsedict = nothing
# try
# responsedict = Serde.parse_yaml(response)
# catch e
# println("\nERROR YiemAgent decisionMaker() Error: $e --(not qualify response)-> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
# continue
# end
# # check whether all answer's key points are in responsedict
# println("\n---")
# println(responsedict)
# println("---\n")
# ispass, errormsg = GeneralUtils.checkAgentResponse_JSON(responsedict, requiredKeys)
# if !ispass
# errornote = errormsg
# println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)-> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
# continue
# end
responsedict = JSON.parse(response) responsedict = JSON.parse(response)
# println("\nYiem decisionMaker() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
# pprintln(responsedict)
if responsedict["action_input"] == "CHAT_BOX" && # for decision that use a single action. make it simpler
occursin("similar", responsedict["action_input"]) for (k, v) in responsedict["action_input"]
responsedict["action_input"] = v
end
if occursin("CHAT_BOX", responsedict["action_input"])
println("\nERROR YiemAgent decisionMaker() --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
continue continue
end end
# if responsedict["action_name"] ∉ ["CHAT_BOX", "SEARCH_WINE_DATABASE", "PRESENT_WINE_GUIDELINE", "END_CONVER_GUIDELINE"] if responsedict["action_name"] ["WINE_PRESENTATION_GUIDELINE", "END_CONVER_GUIDELINE"] &&
# errornote = "Your previous attempt didn't use the given functions" length(responsedict["action_input"]) < 20
# println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> $(responsedict["action_name"])", @__FILE__, ":", @__LINE__, " $(Dates.now())") println("\nERROR YiemAgent decisionMaker() --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
# continue continue
# end end
# println("\nYiem decisionMaker() ", @__FILE__, ":", @__LINE__, " $(Dates.now())") println("\nYiem decisionMaker() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
# pprintln(responsedict) pprintln(responsedict)
@info "YiemAgent decisionMaker() end " @__LINE__ @info "YiemAgent decisionMaker() end " @__LINE__
return responsedict return responsedict
end end
# in case decisionMaker failed, force to use generatechat!() # in case decisionMaker failed, force to use generatechat!()
responsedict = OrderedDict( responsedict = OrderedDict(
"plan"=> "N/A", "think"=> "N/A",
"action_name"=> "CHAT_BOX", "action_name"=> "CHAT_BOX",
"action_input"=> "N/A" "action_input"=> "N/A"
) )
@@ -776,9 +748,9 @@ function generatechat!(a::T; maxattempt::Integer=10
- Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store. - Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store.
- Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store. - Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store.
# you should then respond to the user with interleaving plan, action_name, action_input in JSON format # you should then respond to the user with interleaving think, action_name, action_input in JSON format
1) "plan", Based on the current situation, state a complete action plan to complete the task and rationale. Be specific. 1) "think", Your step-by-step reasoning process. Explain why you are choosing this action.
2) "action_name", action_name must be CHAT_BOX. 2) "action_name", Can be one of the available_actions name.
3) "action_input", Dialogue you want to chat with the user according to your plan. 3) "action_input", Dialogue you want to chat with the user according to your plan.
After the action is executed you gets "action_result". It is the output from the action you selected. After the action is executed you gets "action_result". It is the output from the action you selected.
@@ -814,20 +786,21 @@ function generatechat!(a::T; maxattempt::Integer=10
"schema"=> Dict( "schema"=> Dict(
"type"=> "object", "type"=> "object",
"properties"=> Dict( "properties"=> Dict(
"plan"=> Dict( "think"=> Dict(
"type"=> "string", "type"=> "string",
"description" => "Based on the current situation, state a complete action plan to complete the task and rationale. Be specific.", "description" => "Your step-by-step reasoning process. Explain why you are choosing this action.",
), ),
"action_name"=> Dict( "action_name"=> Dict(
"type"=> "string", "type"=> "string",
"description" => "action_name must be CHAT_BOX", "enum"=> ["CHAT_BOX"],
"description" => "one of the available actions",
), ),
"action_input"=> Dict( "action_input"=> Dict(
"type"=> "string", "type"=> "string",
"description" => "Dialogue you want to chat with the user according to your plan.", "description" => "Dialogue you want to chat with the user according to your plan.",
), ),
), ),
"required"=> ["plan", "action_name", "action_input"], "required"=> ["think", "action_name", "action_input"],
"additionalProperties"=> false "additionalProperties"=> false
) )
) )
@@ -841,43 +814,26 @@ function generatechat!(a::T; maxattempt::Integer=10
) )
response = a.context.text2textInstructLLM(a.id, msg) response = a.context.text2textInstructLLM(a.id, msg)
response = GeneralUtils.clean_json_response(response)
response = GeneralUtils.remove_french_accents(response) response = GeneralUtils.remove_french_accents(response)
think, response = GeneralUtils.extractthink(response)
response = strip(response) # dollar sign in Julia means string interpolation
while occursin('$', response)
response = replace(response, '$' => "USD")
end
responsedict = nothing responsedict = JSON.parse(response)
if occursin(requiredKeys[2], response)
try if occursin("CHAT_BOX", responsedict["action_input"]) ||
_responsedict = JSON.parse(response) length(responsedict["action_input"]) < 20
responsedict = GeneralUtils.dictify(_responsedict; keytype=String, sort_order=requiredKeys) println("\nERROR YiemAgent generatechat() --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
catch
println("\nERROR YiemAgent generatechat() failed to parse response: $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
end
else
println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
continue continue
end end
println("\nYiem generatechat!() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
pprintln(responsedict)
responsedict["action_result"] = "Action result is the next user dialogue."
@info "YiemAgent generatechat!() end " @__LINE__
# check whether all answer's key points are in responsedict
ispass, errormsg = GeneralUtils.checkAgentResponse_JSON(responsedict, requiredKeys)
if !ispass
errornote = errormsg
println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n")
continue
end
# if responsedict["action_name"] ∉ ["CHAT_BOX", "SEARCH_WINE_DATABASE", "PRESENT_WINE_GUIDELINE", "END_CONVER_GUIDELINE"]
# errornote = "Your previous attempt didn't use the given functions"
# println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> $(responsedict["action_name"])", @__FILE__, ":", @__LINE__, " $(Dates.now())")
# continue
# end
# println("\nYiem decisionMaker() ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
# pprintln(responsedict)
responsedict["action_result"] = "Action result is the next user dialogue." responsedict["action_result"] = "Action result is the next user dialogue."
@info "YiemAgent generatechat!() end " @__LINE__ @info "YiemAgent generatechat!() end " @__LINE__
return (thoughtdict=responsedict, result_raw=responsedict["action_input"]) return (thoughtdict=responsedict, result_raw=responsedict["action_input"])
-1
View File
@@ -846,7 +846,6 @@ function wine_search_term_classification(a::T, searchterm::String,
push!(vector_search, entry) push!(vector_search, entry)
end end
end end
responsedict = hard_conditions
println("") println("")
@show responsedict @show responsedict
+7 -7
View File
@@ -199,20 +199,20 @@ function sommelier(
- Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store. - Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store.
- Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store. - Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store.
# you should then respond to the user with interleaving plan, action_name, action_input in JSON format # you should then respond to the user with interleaving think, action_name, action_input in JSON format
1) "plan", Based on the current situation, state a complete action plan to complete the task and rationale. Be specific. 1) "think", Your step-by-step reasoning process. Explain why you are choosing this action.
2) "action_name", (Typically corresponds to the execution of the first step in your plan) Can be one of the available_actions name 2) "action_name", Can be one of the available actions. Typically corresponds to the execution of the first step in your thought
3) "action_input", The input to the action you are about to perform according to your plan. 3) "action_input", The input to the action you are about to perform.
After the action is executed you gets "action_result". It is the output from the action you selected. After the action is executed you gets "action_result". It is the output from the action you selected.
# available actions # available actions
"CHAT_BOX", which you can use to talk with the user. The input is dialogue you want to chat with the user according to your plan. "CHAT_BOX", which you can use to talk with the user. The input is dialogue you want to say with the user.
"SEARCH_WINE_DATABASE", allows you to search information about wines you want in your inventory's database. The input is strictly supported search term including: retailer_name, wine price, winery, name, vintage, region, country, type of wine, grape varietal, tasting notes, occasion, food pairing, intensity, tannin, sweetness, and acidity. "SEARCH_WINE_DATABASE", allows you to search information about wines you want in your inventory's database. The input is strictly supported search term including: retailer_name, wine price, winery, name, vintage, region, country, type of wine, grape varietal, tasting notes, occasion, food pairing, intensity, tannin, sweetness, and acidity.
Example query 1: "Dry, full-bodied red wine from Burgundy, France. Grape varietal could be Merlot or Syrah. price 100 to 1000 USD." Example query 1: "Dry, full-bodied red wine from Burgundy, France. Grape varietal could be Merlot or Syrah. price 100 to 1000 USD."
Example query 2: "Red or white wine, medium tannin, price under 700 USD" Example query 2: "Red or white wine, medium tannin, price under 700 USD"
Example query 3: "white wine from Tuscany, Italy or Bordeaux, France Example query 3: "white wine from Tuscany, Italy or Bordeaux, France
"WINE_PRESENTATION_GUIDELINE", which you can use to check the store guidelines about how to present wines you have found to the user. The input is "nothing" keyword. The output is the guidelines that you can follow. "WINE_PRESENTATION_GUIDELINE", store guidelines about how to present wines to the user appropriately. The input is "null" keyword.
"END_CONVER_GUIDELINE", which you can use to check the store guidelines about how to end the conversation with the user. The input is "nothing" keyword. The output is the guidelines that you can follow. "END_CONVER_GUIDELINE", store guidelines about how to end the conversation with the user appropriately. The input is "null" keyword.
""" """
system_msg = Dict( system_msg = Dict(