update
This commit is contained in:
+22
-17
@@ -35,18 +35,19 @@ julia> # Called automatically by yiemAgent constructor
|
|||||||
function _agent_loop(agent::yiemAgent)
|
function _agent_loop(agent::yiemAgent)
|
||||||
try
|
try
|
||||||
while true
|
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
|
msg = nothing
|
||||||
while msg === nothing
|
while msg === nothing
|
||||||
if isready(agent.inputChannel)
|
if isready(agent.inputChannel) && agent._state.activeRun == false
|
||||||
msg = take!(agent.inputChannel)
|
# allow _process_message() to run
|
||||||
|
|
||||||
#TODO convert raw user msg to userMessage type
|
|
||||||
|
|
||||||
#TODO add userMessage to agent._state.messages
|
|
||||||
else
|
|
||||||
yield()
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -56,20 +57,24 @@ function _agent_loop(agent::yiemAgent)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# make active
|
||||||
|
agent._state.activeRun = true
|
||||||
# Dispatch message through the processing pipeline
|
# Dispatch message through the processing pipeline
|
||||||
result = _process_message(agent, msg)
|
result = _process_message(agent, msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# check followUp message. if there are, add them all to agent.inputChannel
|
# 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
|
||||||
|
|
||||||
|
if !isready(agent.inputChannel) && !hasMore
|
||||||
|
# no more messages queued — safe to send response
|
||||||
|
|
||||||
# Send response to user if no user message in both agent.inputChannel and agent.followUpChannel,
|
|
||||||
# output the result
|
|
||||||
put!(agent.outputChannel, result)
|
put!(agent.outputChannel, result)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
catch e
|
catch e
|
||||||
# On any error, send error response and exit the loop
|
# On any error, send error response and exit the loop
|
||||||
@error "Agent loop failed" error=e
|
@error "Agent loop failed" error=e
|
||||||
@@ -107,7 +112,7 @@ julia> # Currently returns a placeholder echo response
|
|||||||
function _process_message(agent::yiemAgent, msg)
|
function _process_message(agent::yiemAgent, msg)
|
||||||
# WORKING Replace with actual processing logic
|
# WORKING Replace with actual processing logic
|
||||||
|
|
||||||
while (# )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ mutable struct agentState # Mutable runtime state of an agen
|
|||||||
tools::Vector{agentTool} # Available tools
|
tools::Vector{agentTool} # Available tools
|
||||||
messages::Vector{agentMessage} # Conversation messages
|
messages::Vector{agentMessage} # Conversation messages
|
||||||
pendingToolCalls::Vector{String} # Tool call IDs waiting for results
|
pendingToolCalls::Vector{String} # Tool call IDs waiting for results
|
||||||
|
activeRun::Bool # is agent processing user message?
|
||||||
errorMessage::Union{String, Nothing} # Last error message
|
errorMessage::Union{String, Nothing} # Last error message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user