This commit is contained in:
2023-11-23 10:53:04 +00:00
parent 39b94bb19f
commit 049869979c
2 changed files with 90 additions and 14 deletions

View File

@@ -205,7 +205,7 @@ function chat_mistral_openorca(a::agentReflex, usermsg::String)
{context} =
"
{earlierConversation}
{env status}
{env state}
{shortterm memory}
{longterm memory}
"
@@ -268,7 +268,7 @@ function planner_mistral_openorca(a::agentReflex, usermsg::String)
{context} =
"
{earlierConversation}
{env status}
{env state}
{shortterm memory}
{longterm memory}
"
@@ -317,6 +317,77 @@ function planner_mistral_openorca(a::agentReflex, usermsg::String)
return prompt
end
function actor_mistral_openorca(a::agentReflex, usermsg::T) where {T<:AbstractString}
"""
general prompt format:
"
<|im_start|>system
{role}
{tools}
{thinkingFormat}
<|im_end|>
{context}
<|im_start|>user
{usermsg}
<|im_end|>
<|im_start|>assistant
"
Note:
{context} =
"
{earlierConversation}
{env state}
{shortterm memory}
{longterm memory}
"
"""
prompt =
"""
<|im_start|>system
{role}
{tools}
{thinkingFormat}
<|im_end|>
{context}
<|im_start|>user
{usermsg}
<|im_end|>
<|im_start|>assistant
"""
error("actor_mistral_openorca done")
prompt = replace(prompt, "{role}" => a.roles[a.role])
prompt = replace(prompt, "{thinkingFormat}" => a.thinkingFormat[:actor])
toolnames = ""
toollines = ""
for (toolname, v) in a.tools
toolline = "$toolname: $(v[:description]) $(v[:input]) $(v[:output])\n"
toollines *= toolline
toolnames *= "$toolname,"
end
prompt = replace(prompt, "{toolnames}" => toolnames)
prompt = replace(prompt, "{tools}" => "You have access to the following tools:\n$toollines")
context =
"""
{earlierConversation}
{current status}
{longterm memory}
"""
context = replace(context, "{earlierConversation}" => "My earlier talk with the user:\n$(a.earlierConversation)")
context = replace(context, "{current status}" => "")
context = replace(context, "{longterm memory}" => "")
prompt = replace(prompt, "{context}" => context)
prompt = replace(prompt, "{usermsg}" => "Assignment: $usermsg")
return prompt
end
"""
Chat with llm.
@@ -553,17 +624,21 @@ function work(a::agentReflex, usermsg::String)
respond = sendReceivePrompt(a, prompt)
plan = split(respond, "<|im_end|>")[1]
@show respond
step = 0
while true
step += 1
isstep, stepdetail = extractStepFromPlan(a, plan, step)
a.step = 0
while true # execute step by step
a.step += 1
isstep, task = extractStepFromPlan(a, plan)
@show isstep
@show stepdetail
@show task
if isstep
respond = actor_mistral_openorca(a, task)
error("work done")
else # finish all steps
break
end
error("work done")
end
# evaluate
@@ -1033,12 +1108,12 @@ function chunktext(text::T, headers) where {T<:AbstractString}
end
function extractStepFromPlan(a::agent, plan::T, stepToExtract::Int) where {T<:AbstractString}
function extractStepFromPlan(a::agent, plan::T) where {T<:AbstractString}
prompt =
"""
<|im_start|>system
You are a helpful assistant.
Your job is to determine whether step {$stepToExtract} is in the user plan.
Your job is to determine whether step {$(a.step)} is in the user plan.
Choose one of the following choices:
If there isn't say, {no}.

View File

@@ -35,7 +35,8 @@ abstract type agent end
messages = Vector{Dict{Symbol, Any}}()
tools::Union{Dict, Nothing} = nothing
thoughtlog::String = "nothing" # logs unfinished thoughts
attempt::Int = 0 # no. of attempt
attempt::Int = 0 # attempted number
step::Int = 0 # step number
thinkingroundlimit::Int = 5 # thinking round limit
thinkingmode::Symbol = :no_thinking
thinkingFormat::Union{Dict, Nothing} = nothing
@@ -86,9 +87,9 @@ function agentReflex(
:planner=>
"""Use the following format:
Assignment: the input assignment your user is assigning and you must finish
Plan: first you should always think about the assignment and the info you have thoroughly then extract and devise a step by step plan to finish (pay attention to correct numeral calculation and commonsense).
Plan: first you should always think about the assignment and the info you have thoroughly then extract and devise a step by step plan to finish the assignment (pay attention to correct numeral calculation and commonsense).
""",
:worker=>
:actor=>
"""Use the following format:
Assignment: the input assignment your user is assigning and you must finish
Thought: your should always think about what to do (pay attention to correct numeral calculation and commonsense).