update
This commit is contained in:
+25
-23
@@ -12,9 +12,9 @@ using ..type, ..util, ..llmfunction
|
||||
"""
|
||||
Private agent loop. Runs in a background `@spawn` task.
|
||||
|
||||
Waits on `input_ch` and `followUpQueue`, processing whichever has a message first.
|
||||
Waits on `inputChannel` and `followUpChannel`, processing whichever has a message first.
|
||||
On each iteration, dispatches the message through `_process_message` and sends the result
|
||||
to `output_ch`. Exits on `:shutdown` signal.
|
||||
to `outputChannel`. Exits on `:shutdown` signal.
|
||||
|
||||
# Arguments
|
||||
- `agent::yiemAgent`: The agent whose loop to run
|
||||
@@ -25,22 +25,26 @@ to `output_ch`. Exits on `:shutdown` signal.
|
||||
# Notes
|
||||
- This function is automatically spawned as a background task when a `yiemAgent` is created.
|
||||
- On any error, logs the error with `@error` and exits the loop.
|
||||
- Message priority: `input_ch` messages are checked before `followUpQueue` messages.
|
||||
- Message priority: `inputChannel` messages are checked before `followUpChannel` messages.
|
||||
|
||||
# Examples
|
||||
```jldoctest
|
||||
julia> # Called automatically by yiemAgent constructor
|
||||
```
|
||||
"""
|
||||
function _agent_loop(agent::yiemAgent) #WORKING
|
||||
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.input_ch)
|
||||
msg = take!(agent.input_ch)
|
||||
if isready(agent.inputChannel)
|
||||
msg = take!(agent.inputChannel)
|
||||
|
||||
#TODO convert raw user msg to userMessage type
|
||||
|
||||
#TODO add userMessage to agent._state.messages
|
||||
else
|
||||
yield()
|
||||
end
|
||||
@@ -52,20 +56,19 @@ function _agent_loop(agent::yiemAgent) #WORKING
|
||||
break
|
||||
end
|
||||
|
||||
#TODO convert raw user msg to userMessage type
|
||||
|
||||
#TODO add userMessage to agent._state.messages
|
||||
|
||||
|
||||
if isready(agent.followUpQueue)
|
||||
msg = take!(agent.followUpQueue)
|
||||
end
|
||||
|
||||
# @spawn. Dispatch message through the processing pipeline.
|
||||
# Dispatch message through the processing pipeline
|
||||
result = _process_message(agent, msg)
|
||||
|
||||
# Send response to user
|
||||
put!(agent.output_ch, result)
|
||||
|
||||
|
||||
# check followUp message. if there are, add them all to agent.inputChannel
|
||||
|
||||
|
||||
|
||||
|
||||
# Send response to user if no user message in both agent.inputChannel and agent.followUpChannel,
|
||||
# output the result
|
||||
put!(agent.outputChannel, result)
|
||||
end
|
||||
catch e
|
||||
# On any error, send error response and exit the loop
|
||||
@@ -73,6 +76,7 @@ function _agent_loop(agent::yiemAgent) #WORKING
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
"""
|
||||
Process a single message through the agent pipeline.
|
||||
|
||||
@@ -81,7 +85,7 @@ should be implemented. Currently a placeholder that echoes back the received mes
|
||||
|
||||
# Arguments
|
||||
- `agent::yiemAgent`: The agent processing the message
|
||||
- `msg`: The message to process (from `input_ch` or `followUpQueue`)
|
||||
- `msg`: The message to process (from `inputChannel` or `followUpChannel`)
|
||||
|
||||
# Returns
|
||||
- An `assistantMessage` instance with the processed response
|
||||
@@ -102,14 +106,12 @@ julia> # Currently returns a placeholder echo response
|
||||
"""
|
||||
function _process_message(agent::yiemAgent, msg)
|
||||
# WORKING Replace with actual processing logic
|
||||
# check steering message
|
||||
|
||||
while (# )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 1. call agent.
|
||||
# 2. Call agent.formatMsgForLLM(agent._state) to format for LLM
|
||||
# 3. If preprocessMessages is set, call agent.preprocessMessages(...)
|
||||
# 4. Call the LLM (blocking — the task waits here)
|
||||
|
||||
Reference in New Issue
Block a user