update
This commit is contained in:
+38
-14
@@ -6,6 +6,17 @@ module type
|
|||||||
using Dates, UUIDs, DataStructures, JSON, NATS
|
using Dates, UUIDs, DataStructures, JSON, NATS
|
||||||
using GeneralUtils
|
using GeneralUtils
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Simple type aliases / definitions
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
const Timestamp = DateTime
|
||||||
|
|
||||||
|
struct Usage
|
||||||
|
inputTokens::Int64
|
||||||
|
outputTokens::Int64
|
||||||
|
end
|
||||||
|
|
||||||
# ---------------------------------------------- 100 --------------------------------------------- #
|
# ---------------------------------------------- 100 --------------------------------------------- #
|
||||||
|
|
||||||
|
|
||||||
@@ -20,6 +31,10 @@ struct userMessage <: agentMessage # Message from the user
|
|||||||
timestamp::Timestamp # When the message was sent
|
timestamp::Timestamp # When the message was sent
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function userMessage(; role="user", content=Vector{messageContent}(), timestamp=now())
|
||||||
|
return userMessage(role, content, timestamp)
|
||||||
|
end
|
||||||
|
|
||||||
struct assistantMessage <: agentMessage # Message from the AI assistant
|
struct assistantMessage <: agentMessage # Message from the AI assistant
|
||||||
role::String # Always "assistant"
|
role::String # Always "assistant"
|
||||||
content::Vector{messageContent} # Text and/or image content
|
content::Vector{messageContent} # Text and/or image content
|
||||||
@@ -32,6 +47,12 @@ struct assistantMessage <: agentMessage # Message from the AI assistant
|
|||||||
timestamp::Timestamp # When the message was received
|
timestamp::Timestamp # When the message was received
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function assistantMessage(; role="assistant", content=Vector{messageContent}(),
|
||||||
|
api="", provider="", model="", usage=Usage(0, 0), stopReason="end_turn",
|
||||||
|
errorMessage=nothing, timestamp=now())
|
||||||
|
return assistantMessage(role, content, api, provider, model, usage, stopReason, errorMessage, timestamp)
|
||||||
|
end
|
||||||
|
|
||||||
struct toolResultMessage <: agentMessage # Result returned from a tool execution
|
struct toolResultMessage <: agentMessage # Result returned from a tool execution
|
||||||
role::String # Always "tool"
|
role::String # Always "tool"
|
||||||
toolCallId::String # ID matching the tool call
|
toolCallId::String # ID matching the tool call
|
||||||
@@ -44,6 +65,12 @@ struct toolResultMessage <: agentMessage # Result returned from a tool execut
|
|||||||
timestamp::Timestamp # When the result was recorded
|
timestamp::Timestamp # When the result was recorded
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function toolResultMessage(; role="tool", toolCallId="", toolName="",
|
||||||
|
content=Vector{messageContent}(), details=nothing, usage=nothing,
|
||||||
|
addedToolNames=nothing, isError=false, timestamp=now())
|
||||||
|
return toolResultMessage(role, toolCallId, toolName, content, details, usage, addedToolNames, isError, timestamp)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Message content types
|
# Message content types
|
||||||
@@ -55,11 +82,19 @@ struct textContent <: messageContent # Plain text message content
|
|||||||
text::String # The text content
|
text::String # The text content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function textContent(; text="")
|
||||||
|
return textContent(text)
|
||||||
|
end
|
||||||
|
|
||||||
struct imageContent <: messageContent # Image message content
|
struct imageContent <: messageContent # Image message content
|
||||||
data::String # Base64-encoded image data
|
data::String # Base64-encoded image data
|
||||||
mimeType::String # MIME type (e.g., "image/png")
|
mimeType::String # MIME type (e.g., "image/png")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function imageContent(; data="", mimeType="")
|
||||||
|
return imageContent(data, mimeType)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Tool types
|
# Tool types
|
||||||
@@ -256,7 +291,7 @@ end
|
|||||||
Private agent loop. Runs in a background @task.
|
Private agent loop. Runs in a background @task.
|
||||||
Waits on input_ch and followUpQueue concurrently via select().
|
Waits on input_ch and followUpQueue concurrently via select().
|
||||||
"""
|
"""
|
||||||
function _agent_loop(agent::yiemAgent)
|
function _agent_loop(agent::yiemAgent) #WORKING
|
||||||
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 fires first
|
||||||
@@ -275,18 +310,7 @@ function _agent_loop(agent::yiemAgent)
|
|||||||
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
|
||||||
try
|
@error "Agent loop failed" error=e
|
||||||
put!(agent.output_ch, assistantMessage(
|
|
||||||
role="assistant",
|
|
||||||
content=[textContent("Agent error: $(sprint(showerror, e))")],
|
|
||||||
api="", model="", usage=nothing,
|
|
||||||
stopReason="error",
|
|
||||||
errorMessage=strip(sprint(showerror, e)),
|
|
||||||
timestamp=now(),
|
|
||||||
))
|
|
||||||
catch e2
|
|
||||||
@error "Failed to send error response" error=e2
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -295,7 +319,7 @@ Process a single message through the agent pipeline.
|
|||||||
This is where you add your LLM call, tool execution, etc.
|
This is where you add your LLM call, tool execution, etc.
|
||||||
"""
|
"""
|
||||||
function _process_message(agent::yiemAgent, msg)
|
function _process_message(agent::yiemAgent, msg)
|
||||||
# TODO: Replace with actual processing logic
|
# PENDING Replace with actual processing logic
|
||||||
#
|
#
|
||||||
# 1. Add msg to agent._state.messages
|
# 1. Add msg to agent._state.messages
|
||||||
# 2. Call agent.formatMsgForLLM(agent._state) to format for LLM
|
# 2. Call agent.formatMsgForLLM(agent._state) to format for LLM
|
||||||
|
|||||||
Reference in New Issue
Block a user