update
This commit is contained in:
+13
-13
@@ -3,7 +3,7 @@ module agentCore
|
||||
export _agent_loop, OpenAiToUserMessage
|
||||
|
||||
using JSON, DataStructures, Dates, UUIDs, HTTP, Random, PrettyPrinting, Serialization,
|
||||
DataFrames, Serde
|
||||
DataFrames, Serde, Base.Threads
|
||||
using GeneralUtils
|
||||
using ..type, ..utils, ..llmfunction
|
||||
|
||||
@@ -34,41 +34,41 @@ julia> # Called automatically by yiemAgent constructor
|
||||
"""
|
||||
function _agent_loop(agent::yiemAgent)
|
||||
try
|
||||
processing_task = nothing
|
||||
processingTask = nothing
|
||||
|
||||
""" cases:
|
||||
1) agent -> idle, user msg -> nothing
|
||||
typeof(processing_task) == Nothing
|
||||
typeof(processingTask) == Nothing
|
||||
agent._state.activeRun -> false
|
||||
agent.inputChannel -> nothing
|
||||
agent.followUpChannel -> nothing
|
||||
|
||||
2) agent -> idle, user msg -> new msg
|
||||
typeof(processing_task) == Nothing
|
||||
typeof(processingTask) == Nothing
|
||||
agent._state.activeRun -> false
|
||||
agent.inputChannel -> new msg
|
||||
agent.followUpChannel -> nothing
|
||||
|
||||
3) agent -> running, user msg -> nothing
|
||||
typeof(processing_task) == Task, istaskdone(processing_task) -> false
|
||||
typeof(processingTask) == Task, istaskdone(processingTask) -> false
|
||||
agent._state.activeRun -> true
|
||||
agent.inputChannel -> nothing
|
||||
agent.followUpChannel -> nothing
|
||||
|
||||
4) agent -> running, user msg -> new msg
|
||||
typeof(processing_task) == Task, istaskdone(processing_task) -> false
|
||||
typeof(processingTask) == Task, istaskdone(processingTask) -> false
|
||||
agent._state.activeRun -> true
|
||||
agent.inputChannel -> new msg
|
||||
agent.followUpChannel -> nothing
|
||||
|
||||
5) agent -> running, user msg -> nothing, user msg follow up -> new msg
|
||||
typeof(processing_task) == Task, istaskdone(processing_task) -> false
|
||||
typeof(processingTask) == Task, istaskdone(processingTask) -> false
|
||||
agent._state.activeRun -> true
|
||||
agent.inputChannel -> nothing
|
||||
agent.followUpChannel -> new msg
|
||||
|
||||
6) agent -> idle, user msg -> nothing
|
||||
typeof(processing_task) == Task, istaskdone(processing_task) -> true
|
||||
typeof(processingTask) == Task, istaskdone(processingTask) -> true
|
||||
agent._state.activeRun -> false
|
||||
agent.inputChannel -> nothing
|
||||
agent.followUpChannel -> nothing
|
||||
@@ -108,12 +108,12 @@ function _agent_loop(agent::yiemAgent)
|
||||
# start _process_message loop
|
||||
if agent._state.activeRun == false
|
||||
# Dispatch message through the processing pipeline
|
||||
processing_task = @spawn _process_message(agent)
|
||||
processingTask = Threads.@spawn _process_message(agent)
|
||||
agent._state.activeRun = true
|
||||
end
|
||||
|
||||
# during agent runs, check followUp message after _process_message() is done
|
||||
if typeof(processing_task) == Task && istaskdone(processing_task) == false
|
||||
if typeof(processingTask) == Task && istaskdone(processingTask) == false
|
||||
# if followUp message available, add them all to agent.inputChannel
|
||||
if isready(agent.followUpChannel)
|
||||
while isready(agent.followUpChannel)
|
||||
@@ -123,7 +123,7 @@ function _agent_loop(agent::yiemAgent)
|
||||
end
|
||||
continue # continue to process user message in the next loop
|
||||
|
||||
elseif typeof(processing_task) == Task && istaskdone(processing_task) == true
|
||||
elseif typeof(processingTask) == Task && istaskdone(processingTask) == true
|
||||
# if agent runs is done but followUpChannel has messages, discard all message in it.
|
||||
# when agent work is done it should not accept follow up msg.
|
||||
# user should put new message in inputChannel instead
|
||||
@@ -132,10 +132,10 @@ function _agent_loop(agent::yiemAgent)
|
||||
_ = take!(agent.followUpChannel)
|
||||
end
|
||||
end
|
||||
result = fetch(processing_task)
|
||||
result = fetch(processingTask)
|
||||
put!(agent.outputChannel, result)
|
||||
agent._state.activeRun = false # reset
|
||||
processing_task = nothing # reset
|
||||
processingTask = nothing # reset
|
||||
end
|
||||
end
|
||||
catch e
|
||||
|
||||
Reference in New Issue
Block a user