This commit is contained in:
2026-08-04 14:51:53 +07:00
parent 937d52053f
commit 52eaeab5fc
2 changed files with 24 additions and 18 deletions
+23 -18
View File
@@ -35,18 +35,19 @@ julia> # Called automatically by yiemAgent constructor
function _agent_loop(agent::yiemAgent)
try
while true
# Wait on either channel — the one with a message fires first
# Wait on either channel — the one with a message is taken first
msg = nothing
while msg === nothing
if isready(agent.inputChannel)
msg = take!(agent.inputChannel)
#TODO convert raw user msg to userMessage type
#TODO add userMessage to agent._state.messages
else
if isready(agent.inputChannel) && agent._state.activeRun == false
# allow _process_message() to run
yield()
elseif isready(agent.inputChannel) && agent._state.activeRun == true
msg = fetch!(agent.inputChannel)
# Check for shutdown signal
if msg === :shutdown
msg = take!(agent.inputChannel)
end
else
error("undefined condition: isready(inputChannel)=$(isready(agent.inputChannel)), activeRun=$(agent._state.activeRun), msg=$msg")
end
end
@@ -56,19 +57,23 @@ function _agent_loop(agent::yiemAgent)
break
end
# make active
agent._state.activeRun = true
# Dispatch message through the processing pipeline
result = _process_message(agent, msg)
# check followUp message. if there are, add them all to agent.inputChannel
hasMore = isready(agent.followUpChannel)
while isready(agent.followUpChannel)
followMsg = take!(agent.followUpChannel)
put!(agent.inputChannel, followMsg)
hasMore = true
end
# Send response to user if no user message in both agent.inputChannel and agent.followUpChannel,
# output the result
put!(agent.outputChannel, result)
if !isready(agent.inputChannel) && !hasMore
# no more messages queued — safe to send response
put!(agent.outputChannel, result)
end
end
catch e
# On any error, send error response and exit the loop
@@ -107,7 +112,7 @@ julia> # Currently returns a placeholder echo response
function _process_message(agent::yiemAgent, msg)
# WORKING Replace with actual processing logic
while (# )
+1
View File
@@ -252,6 +252,7 @@ mutable struct agentState # Mutable runtime state of an agen
tools::Vector{agentTool} # Available tools
messages::Vector{agentMessage} # Conversation messages
pendingToolCalls::Vector{String} # Tool call IDs waiting for results
activeRun::Bool # is agent processing user message?
errorMessage::Union{String, Nothing} # Last error message
end