This commit is contained in:
2023-12-05 09:12:23 +00:00
parent ec8cc6bbf9
commit 6ece544cc8
2 changed files with 69 additions and 54 deletions

View File

@@ -761,7 +761,6 @@ function actor(a::agentReflex)
totalsteps = checkTotalStepInPlan(a)
while true # Actor loop
#WORKING
if a.step == 0
a.step = 1
else
@@ -774,8 +773,9 @@ function actor(a::agentReflex)
a.step += 1
elseif decision == "No"
# repeat the latest step
# TODO delete Thought/Act/ActInput from the latest input
error("repete step $(a.step)")
# WORKING delete Thought/Act/ActInput from the latest input
a.memory[:shortterm] = removeHeaders(a.memory[:shortterm], a.step, ["Plan"])
println("repeating step $(a.step)")
elseif decision == "formulateUserRespond"
actorState = "formulateUserRespond"
msgToUser = nothing
@@ -1234,52 +1234,6 @@ function goNogo(a)
return decision, reason
end
# function goNogo(a)
# stimulus = a.memory[:shortterm]["user:"]
# work = ""
# for (k, v) in a.memory[:shortterm]
# if k ∉ ["user:"]
# work *= "$k $v"
# end
# end
# prompt =
# """
# <|im_start|>system
# You have access to the following tools:
# chatbox: Useful for when you need to ask a customer for more context. Input should be a conversation to customer.
# wikisearch: Useful for when you need to search an encyclopedia Input is keywords and not a question.
# Symbol:
# Stimulus: the input user gives to you and you must respond
# Plan: a plan
# Thought: your thought
# Act: the action you took
# ActInput: the input to the action
# Obs: the result of the action
# Stimulus:
# $stimulus
# Your work:
# $work
# From your work, you job is to decide whether you're ready to do the next step in the plan by choosing one of the following choices:
# If you are ready say, "{Yes}". And what is the rationale behind the decision?
# If you are not ready say, "{No}". And what is the rationale behind the decision?
# <|im_end|>
# """
# respond = sendReceivePrompt(a, prompt)
# decision = GeneralUtils.getStringBetweenCharacters(respond, "{", "}")
# start = findfirst("}", respond)[end] +1
# reason = respond[start:end]
# return decision, reason
# end

View File

@@ -3,7 +3,7 @@ module utils
export makeSummary, sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalStepInPlan,
detectCharacters, findDetectedCharacter, extract_number, toolNameBeingCalled,
chooseThinkingMode, conversationSummary, checkReasonableness, replaceHeaders,
addShortMem!, splittext, shortMemoryToString
addShortMem!, splittext, shortMemoryToString, removeHeaders
using UUIDs, Dates, DataStructures
using CommUtils, GeneralUtils
@@ -622,7 +622,7 @@ end
""" Convert short term memory into 1 continous string.
Args:
shortMemory = a short memory of a ChatAgent's agent
shortMemory = a short term memory of a ChatAgent's agent
skiplist = a list of keys in memory you want to skip
Return:
@@ -631,13 +631,15 @@ Return:
# Example
```jldoctest
julia> shortMemory = OrderedDict(
"Thought" => "I like it.",
"Act" => "chatbox",
"ActInput" => "I get this one.",
"user:" => "Umm",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"ActInput 1:" => "I get this one.",
)
julia> headers = ["user:"]
julia> shortMemoryToString(shortMemory, headers)
"Thought 1: I like it.\nAct 1: chatbox\nActInput 1: I get this one.\n"
```
"""
function shortMemoryToString(shortMemory::OrderedDict,
@@ -658,8 +660,67 @@ function shortMemoryToString(shortMemory::OrderedDict,
end
""" Remove headers of specific step from memory.
Args:
shortMemory = a short term memory of a ChatAgent's agent
skipHeaders = a list of keys in memory you want to skip
step = a step number you want to remove
Return:
a short term memory
# Example
```jldoctest
julia> shortMemory = OrderedDict(
"user:" => "May I try this one?",
"Plan 1:" => "testing a small portion of icecream",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"ActInput 1:" => "I get this one.",
"Plan 2:" => "I'm meeting my wife this afternoon",
"Thought 2:" => "I also want it for my wife",
"Act 2:" => "chatbox",
"ActInput 2:" => "I would like to get 2 more",
)
julia> skipHeaders = ["Plan"]
julia> step = 2
julia> removeHeaders(shortMemory, step, skipHeaders)
OrderedDict(
"user:" => "May I try this one?",
"Plan 1:" => "testing a small portion of icecream",
"Thought 1:" => "I like it.",
"Act 1:" => "chatbox",
"ActInput 1:" => "I get this one.",
"Plan 2:" => "I'm meeting my wife this afternoon",
)
```
""" #WORKING
function removeHeaders(shortMemory::OrderedDict, step::Int,
skipHeaders::Union{Array{String}, Array{Symbol}, Nothing}=nothing)
newdict = similar(shortMemory)
for (k, v) in shortMemory
if occursin("$step", k)
if skipHeaders !== nothing
for i in skipHeaders
if occursin(i, k)
newdict[k] = v
else
# skip, not copy
end
end
else
# no copy
end
else
newdict[k] = v
end
end
return newdict
end