update
This commit is contained in:
+18
-12
@@ -163,7 +163,7 @@ should be implemented. Currently a placeholder that echoes back the received mes
|
||||
- Implement the full processing pipeline:
|
||||
1. Add `msg` to `agent._state.messages`
|
||||
2. Call `agent.formatMsgForLLM(agent._state)` 1 to format for LLM
|
||||
3. If `agent.preprocessMessages` is set, call it on the formatted messages
|
||||
3. If `agent.preprocessContext` is set, call it on the formatted messages
|
||||
4. Call the LLM (blocking — the task waits here)
|
||||
5. If agent has tools, handle tool calls in a loop
|
||||
6. Build `assistantMessage` and return it
|
||||
@@ -173,19 +173,23 @@ should be implemented. Currently a placeholder that echoes back the received mes
|
||||
julia> # Currently returns a placeholder echo response
|
||||
```
|
||||
"""
|
||||
function _process_message(agent::yiemAgent, msg)
|
||||
# WORKING Replace with actual processing logic
|
||||
function _process_message(agent::yiemAgent, msg)::assistantMessage
|
||||
# WORKING
|
||||
|
||||
|
||||
# take every messages from agent.inputChannel, convert them into userMessage
|
||||
# and add them to agent._state.messages
|
||||
|
||||
# call agent.preprocessContext()
|
||||
|
||||
# Call agent.formatMsgForLLM(agent._state) to format for LLM
|
||||
|
||||
# Call the LLM (blocking — the task waits here)
|
||||
|
||||
# 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)
|
||||
# 5. If agent has tools, handle tool calls in a loop
|
||||
# 6. Build assistantMessage and return it
|
||||
# call toolArgumentValidation() to make sure soon-to-call tools has valid arguments
|
||||
|
||||
# If agent has tools, handle tool calls in a loop
|
||||
|
||||
# Build assistantMessage and return it
|
||||
|
||||
# Placeholder: echo back the message as a simple response
|
||||
@warn "TODO: implement _process_message"
|
||||
@@ -200,6 +204,11 @@ function _process_message(agent::yiemAgent, msg)
|
||||
end
|
||||
|
||||
|
||||
function createToolResultMessage()::toolResultMessage
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -264,9 +273,6 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+25
-17
@@ -355,24 +355,32 @@ docstring
|
||||
mutable struct yiemAgent <: agent # High-level agent wrapper
|
||||
_state::agentState # Current state (prompt, model, messages, tools, etc.)
|
||||
|
||||
inputChannel::Channel # user sends prompt message to agent.
|
||||
# if agent is idle, it process user message right away.
|
||||
# if agent is running, it process user message after
|
||||
# the current tool call finished.
|
||||
|
||||
followUpChannel::Channel # Buffers messages the user sends while the agent is busy.
|
||||
# Processed after all inputChannel messages are handled
|
||||
# and the agent is idle (not using a tool call).
|
||||
|
||||
outputChannel::Channel # agent sends response message to user after processing
|
||||
# all user messages in inputChannel and all followUp messages.
|
||||
# user sends prompt message to agent. if agent is idle, it process user message right away.
|
||||
# if agent is running, it process user message after the current tool call finished.
|
||||
inputChannel::Channel
|
||||
|
||||
# Buffers messages the user sends while the agent is busy. Processed after all inputChannel
|
||||
# messages are handled and the agent is idle (not using a tool call).
|
||||
followUpChannel::Channel
|
||||
|
||||
# agent sends response message to user after processing all user messages in inputChannel
|
||||
# and all followUp messages.
|
||||
outputChannel::Channel
|
||||
|
||||
_task::Union{Task, Nothing} # Background task running the agent loop
|
||||
|
||||
formatMsgForLLM::Function # Convert agent messages to LLM message format
|
||||
preprocessMessages ::Union{Function, Nothing} # Preprocess/transform messages before sending to LLM
|
||||
beforeToolCall::Union{Function, Nothing} # Callback invoked before executing a tool call
|
||||
afterToolCall::Union{Function, Nothing} # Callback invoked after executing a tool call
|
||||
|
||||
# Preprocess/transform messages and context (modify, filter, prune, inject, reorder, add context)
|
||||
# for a single LLM call in _process_message()'s loop returns new Vector{agentMessage}
|
||||
preprocessContext ::Union{Function, Nothing}
|
||||
|
||||
# Callback invoked before executing a tool call (ask for user permission/confirmation/abort, etc..)
|
||||
beforeToolCall::Union{Function, Nothing}
|
||||
|
||||
# Callback invoked after executing a tool call to sanitize tools output so the output is ready
|
||||
# to be converted into toolResults message
|
||||
afterToolCall::Union{Function, Nothing}
|
||||
prepareNextTurn::Union{Function, Nothing} # Callback to prepare the next conversation turn
|
||||
prepareNextTurnWithContext::Union{Function, Nothing} # Same but receives context
|
||||
sessionId::Union{String, Nothing} # Optional session identifier
|
||||
@@ -392,7 +400,7 @@ on `inputChannel` and `followUpChannel` channels concurrently.
|
||||
- `tools::Vector{agentTool}`: Available tools (default: empty)
|
||||
- `messages::Vector{agentMessage}`: Initial conversation messages (default: empty)
|
||||
- `formatMsgForLLM::Function`: Convert agent messages to LLM message format (default: `defaultformatMsgForLLM`)
|
||||
- `preprocessMessages::Union{Function, Nothing}`: Preprocess/transform messages before sending to LLM (default: `nothing`)
|
||||
- `preprocessContext::Union{Function, Nothing}`: Preprocess/transform messages before sending to LLM (default: `nothing`)
|
||||
- `beforeToolCall::Union{Function, Nothing}`: Callback invoked before executing a tool call (default: `nothing`)
|
||||
- `afterToolCall::Union{Function, Nothing}`: Callback invoked after executing a tool call (default: `nothing`)
|
||||
- `prepareNextTurn::Union{Function, Nothing}`: Callback to prepare the next conversation turn (default: `nothing`)
|
||||
@@ -416,7 +424,7 @@ function yiemAgent(
|
||||
tools::Vector{agentTool}=agentTool[],
|
||||
messages::Vector{agentMessage}=agentMessage[],
|
||||
formatMsgForLLM::Function=defaultformatMsgForLLM,
|
||||
preprocessMessages::Union{Function, Nothing}=nothing,
|
||||
preprocessContext::Union{Function, Nothing}=nothing,
|
||||
beforeToolCall::Union{Function, Nothing}=nothing,
|
||||
afterToolCall::Union{Function, Nothing}=nothing,
|
||||
prepareNextTurn::Union{Function, Nothing}=nothing,
|
||||
@@ -438,7 +446,7 @@ function yiemAgent(
|
||||
outputChannel,
|
||||
nothing, # placeholder — replaced below
|
||||
formatMsgForLLM,
|
||||
preprocessMessages,
|
||||
preprocessContext,
|
||||
beforeToolCall,
|
||||
afterToolCall,
|
||||
prepareNextTurn,
|
||||
|
||||
Reference in New Issue
Block a user