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:
|
- Implement the full processing pipeline:
|
||||||
1. Add `msg` to `agent._state.messages`
|
1. Add `msg` to `agent._state.messages`
|
||||||
2. Call `agent.formatMsgForLLM(agent._state)` 1 to format for LLM
|
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)
|
4. Call the LLM (blocking — the task waits here)
|
||||||
5. If agent has tools, handle tool calls in a loop
|
5. If agent has tools, handle tool calls in a loop
|
||||||
6. Build `assistantMessage` and return it
|
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
|
julia> # Currently returns a placeholder echo response
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function _process_message(agent::yiemAgent, msg)
|
function _process_message(agent::yiemAgent, msg)::assistantMessage
|
||||||
# WORKING Replace with actual processing logic
|
# 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
|
# call toolArgumentValidation() to make sure soon-to-call tools has valid arguments
|
||||||
# 3. If preprocessMessages is set, call agent.preprocessMessages(...)
|
|
||||||
# 4. Call the LLM (blocking — the task waits here)
|
# If agent has tools, handle tool calls in a loop
|
||||||
# 5. If agent has tools, handle tool calls in a loop
|
|
||||||
# 6. Build assistantMessage and return it
|
# Build assistantMessage and return it
|
||||||
|
|
||||||
# Placeholder: echo back the message as a simple response
|
# Placeholder: echo back the message as a simple response
|
||||||
@warn "TODO: implement _process_message"
|
@warn "TODO: implement _process_message"
|
||||||
@@ -200,6 +204,11 @@ function _process_message(agent::yiemAgent, msg)
|
|||||||
end
|
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
|
mutable struct yiemAgent <: agent # High-level agent wrapper
|
||||||
_state::agentState # Current state (prompt, model, messages, tools, etc.)
|
_state::agentState # Current state (prompt, model, messages, tools, etc.)
|
||||||
|
|
||||||
inputChannel::Channel # user sends prompt message to agent.
|
# user sends prompt message to agent. if agent is idle, it process user message right away.
|
||||||
# if agent is idle, it process user message right away.
|
# if agent is running, it process user message after the current tool call finished.
|
||||||
# if agent is running, it process user message after
|
inputChannel::Channel
|
||||||
# the current tool call finished.
|
|
||||||
|
# Buffers messages the user sends while the agent is busy. Processed after all inputChannel
|
||||||
followUpChannel::Channel # Buffers messages the user sends while the agent is busy.
|
# messages are handled and the agent is idle (not using a tool call).
|
||||||
# Processed after all inputChannel messages are handled
|
followUpChannel::Channel
|
||||||
# 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.
|
|
||||||
|
|
||||||
|
# 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
|
_task::Union{Task, Nothing} # Background task running the agent loop
|
||||||
|
|
||||||
formatMsgForLLM::Function # Convert agent messages to LLM message format
|
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
|
# Preprocess/transform messages and context (modify, filter, prune, inject, reorder, add context)
|
||||||
afterToolCall::Union{Function, Nothing} # Callback invoked after executing a tool call
|
# 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
|
prepareNextTurn::Union{Function, Nothing} # Callback to prepare the next conversation turn
|
||||||
prepareNextTurnWithContext::Union{Function, Nothing} # Same but receives context
|
prepareNextTurnWithContext::Union{Function, Nothing} # Same but receives context
|
||||||
sessionId::Union{String, Nothing} # Optional session identifier
|
sessionId::Union{String, Nothing} # Optional session identifier
|
||||||
@@ -392,7 +400,7 @@ on `inputChannel` and `followUpChannel` channels concurrently.
|
|||||||
- `tools::Vector{agentTool}`: Available tools (default: empty)
|
- `tools::Vector{agentTool}`: Available tools (default: empty)
|
||||||
- `messages::Vector{agentMessage}`: Initial conversation messages (default: empty)
|
- `messages::Vector{agentMessage}`: Initial conversation messages (default: empty)
|
||||||
- `formatMsgForLLM::Function`: Convert agent messages to LLM message format (default: `defaultformatMsgForLLM`)
|
- `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`)
|
- `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`)
|
- `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`)
|
- `prepareNextTurn::Union{Function, Nothing}`: Callback to prepare the next conversation turn (default: `nothing`)
|
||||||
@@ -416,7 +424,7 @@ function yiemAgent(
|
|||||||
tools::Vector{agentTool}=agentTool[],
|
tools::Vector{agentTool}=agentTool[],
|
||||||
messages::Vector{agentMessage}=agentMessage[],
|
messages::Vector{agentMessage}=agentMessage[],
|
||||||
formatMsgForLLM::Function=defaultformatMsgForLLM,
|
formatMsgForLLM::Function=defaultformatMsgForLLM,
|
||||||
preprocessMessages::Union{Function, Nothing}=nothing,
|
preprocessContext::Union{Function, Nothing}=nothing,
|
||||||
beforeToolCall::Union{Function, Nothing}=nothing,
|
beforeToolCall::Union{Function, Nothing}=nothing,
|
||||||
afterToolCall::Union{Function, Nothing}=nothing,
|
afterToolCall::Union{Function, Nothing}=nothing,
|
||||||
prepareNextTurn::Union{Function, Nothing}=nothing,
|
prepareNextTurn::Union{Function, Nothing}=nothing,
|
||||||
@@ -438,7 +446,7 @@ function yiemAgent(
|
|||||||
outputChannel,
|
outputChannel,
|
||||||
nothing, # placeholder — replaced below
|
nothing, # placeholder — replaced below
|
||||||
formatMsgForLLM,
|
formatMsgForLLM,
|
||||||
preprocessMessages,
|
preprocessContext,
|
||||||
beforeToolCall,
|
beforeToolCall,
|
||||||
afterToolCall,
|
afterToolCall,
|
||||||
prepareNextTurn,
|
prepareNextTurn,
|
||||||
|
|||||||
Reference in New Issue
Block a user