This commit is contained in:
narawat lamaiin
2024-05-09 21:27:28 +07:00
parent a4e7dee5bf
commit c7fd7bc40d
3 changed files with 77 additions and 18 deletions

View File

@@ -96,18 +96,24 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
""
else
"""
You have attempted to answer the following question before and failed, either because your reasoning for the answer was incorrect or the phrasing of your response did not exactly match what the user want. The following lesson(s) give a plan to avoid failing to answer the question in the same way you did previously. Use them to improve your strategy of correctly answering the given question.
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:
$(JSON3.write(a.lesson[:lesson_1][:lesson]))
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.
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
_prompt =
"""
You are a helpful sommelier working for a wine store.
Your goal is to reccommend the best wine from your inventory that match the user preferences.
You are also an advanced reasoning agent that can improve based on self refection.
Your goal is to recommend the best wine from your inventory that match the user preferences.
You are also keen to improve your recommendation with lesson(s).
You must follow the following criteria:
1) Get to know what occasion the user is buying wine for
@@ -123,7 +129,7 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
Thought can reason about the current situation, and Action can be three types:
1) winestock[query], which you can use to find wine in your inventory. The more input data the better.
2) chatbox[text], which you can use to interact with the user.
3) recommendbox[answer], which returns your wine reccommendation to the user.
3) recommendbox[answer], which returns your wine recommendation to the user.
After each observation, provide the next Thought and next Action.
You should only respond in JSON format as describe below:
@@ -183,7 +189,7 @@ function decisionMaker(a::T1, state::T2)::Dict{Symbol, Any} where {T1<:agent, T2
)
)
)
@show outgoingMsg
attempt = 0
while true
attempt += 1
@@ -256,7 +262,7 @@ function progressValueEstimator(a::T1, state::T2)::Tuple{String, Integer} where
the current situation and actions that can be three types:
1) winestock[query], which you can use to find wine in your inventory.
2) chatbox[text], which you can use to interact with the user.
3) recommendbox[answer], which returns your wine reccommendation to the user.
3) recommendbox[answer], which returns your wine recommendation to the user.
Given a question and a trajectory, evaluate its correctness and provide your reasoning and
analysis in detail. Focus on the latest thought, action, and observation. Incomplete trajectories
@@ -373,11 +379,61 @@ julia>
function reflector(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractDict}
# https://github.com/andyz245/LanguageAgentTreeSearch/blob/main/hotpot/hotpot.py
# _prompt =
# """
# You are an advanced reasoning agent that can improve based on self refection.
# You will be given the information related to the previous help you've done for a user.
# You were unsuccessful in helping the user either because you guessed the wrong answer with Finish[answer], or you used up your set number of reasoning steps.
# In a few sentences, Diagnose a possible reason for failure and devise a new, concise, high level plan that aims to mitigate the same failure.
# Use complete sentences.
# You should only respond in JSON format as describe below:
# {"reflection": "your relection"}
# Here are some examples:
# Previous Trial:
# {
# "question": "Hello, I would like a get a bottle of wine",
# "thought_1": "A customer wants to buy a bottle of wine. Before making a recommendation, I need to know more about their preferences.",
# "action_1": {"name": "chatbox", "input": "What is the occasion for which you're buying this wine?"},
# "observation_1": "We are holding a wedding party",
# "thought_2": "A wedding party, that's a great occasion! The customer might be looking for a celebratory drink. Let me ask some more questions to narrow down the options.",
# "action_2": {"name": "chatbox", "input": "What type of food will you be serving at the wedding?"},
# "observation_2": "It will be Thai dishes.",
# "thought_3": "With Thai food, I should recommend a wine that complements its spicy and savory flavors. And since it's a celebratory occasion, the customer might prefer a full-bodied wine.",
# "action_3": {"name": "chatbox", "input": "What is your budget for this bottle of wine?"},
# "observation_3": "I would spend up to 50 bucks.",
# "thought_4": "Now that I have some more information, it's time to narrow down the options.",
# "action_4": {"name": "winestock", "input": "red wine with full body, pairs well with spicy food, budget \$50"},
# "observation_4": "I found the following wines in our stock: \n{\n 1: El Enemigo Cabernet Franc 2019\n2: Tantara Chardonnay 2017\n\n}\n",
# "thought_5": "Now that I have a list of potential wines, I need to know more about the customer's taste preferences.",
# "action_5": {"name": "chatbox", "input": "What type of wine characteristics are you looking for? (e.g. t.e.g. tannin level, sweetness, intensity, acidity)"},
# "observation_5": "I like full-bodied Red wine with low tannin.",
# "thought_6": "Now that I have more information about the customer's preferences, it's time to make a recommendation.",
# "action_6": {"name": "recommendbox", "input": "El Enemigo Cabernet Franc 2019"},
# "observation_6": "I don't like the one you recommend. I want dry wine."
# }
# {
# "reflection": "I asked the user about the occasion, food type, and budget, and then searched for wine in the inventory right away. However, I should have asked the user for the specific wine type and their preferences in order to gather more information before making a recommendation."
# }
# Previous trial:
# $(JSON3.write(state[:thoughtHistory]))
# {"reflection"
# """
_prompt =
"""
You are an advanced reasoning agent that can improve based on self refection.
You will be given the information related to the previous help you've done for a user.
You were unsuccessful in helping the user either because you guessed the wrong answer with Finish[answer], or you used up your set number of reasoning steps.
You are a helpful sommelier working for a wine store.
Your goal is to recommend the best wine from your inventory that match the user preferences.
You will be given a question and a trajectory of the previous help you've done for a user.
You were unsuccessful in helping the user either because you guessed the wrong answer with Finish[answer], or you didn't know the user enough.
In a few sentences, Diagnose a possible reason for failure and devise a new, concise, high level plan that aims to mitigate the same failure.
Use complete sentences.
@@ -417,6 +473,8 @@ function reflector(a::T1, state::T2)::String where {T1<:agent, T2<:AbstractDict}
"reflection": "I asked the user about the occasion, food type, and budget, and then searched for wine in the inventory right away. However, I should have asked the user for the specific wine type and their preferences in order to gather more information before making a recommendation."
}
Let's begin!
Previous trial:
$(JSON3.write(state[:thoughtHistory]))
{"reflection"