This commit is contained in:
2026-08-06 19:30:59 +07:00
parent ebd79aa686
commit 51fca0aa8c
2 changed files with 39 additions and 52 deletions
+1 -1
View File
@@ -179,7 +179,7 @@ function _process_message(agent::yiemAgent)::assistantMessage
# call agent.prepareContext()
preparedContext = agent.prepareContext(agent._state)
#WORKING Call agent.formatMsgForLLM(agent._state) to format for LLM
# Call agent.formatMsgForLLM(agent._state) to format for LLM
formatted_messages = agent.formatMsgForLLM(preparedContext)
# Call llmCall() (blocking — the task waits here)
+38 -51
View File
@@ -115,60 +115,47 @@ end
""" convert preparedcontext into openai message format ready to be used by LLM
"""
function formatMsgForLLM(messages::Vector{agentMessage})::Vector{Dict{String, Any}}
openai_messages = Vector{Dict{String, Any}}()
for msg in messages
if msg isa userMessage
push!(openai_messages, _toOpenAIUserMsg(msg))
elseif msg isa assistantMessage
push!(openai_messages, _toOpenAIAssistantMsg(msg))
elseif msg isa toolResultMessage
push!(openai_messages, _toOpenAIToolResultMsg(msg))
end
end
return openai_messages
end
function _toOpenAIUserMsg(msg::userMessage)::Dict{String, Any}
return Dict{String, Any}(
"role" => "user",
"content" => _toOpenAIBlocks(msg.content),
function formatMsgForLLM(preparedContext::Vector{agentMessage})::Dict{String, Any}
""" openai message format example
msg = Dict(
"model" => "gemma-4-E4B-it-UD-Q4_K_XL",
"messages" => [
Dict(
"role" => "system",
"content" => [
Dict("type" => "text", "text" => systemmsg),
]
),
Dict(
"role" => "user",
"content" => [
Dict("type" => "text", "text" => "Do you have something similar to the one in the image?"),
Dict(
"type" => "image_url",
"image_url" => Dict("url" => data1_uri)
)
]
),
Dict(
"role" => "assistant",
"content" => [
Dict("type" => "text", "text" => "let me check."),
]
),
Dict(
"role" => "toolResult",
"content" => [
Dict("type" => "text", "text" => "name: Chateau Montelena ..."),
]
),
],
"temperature" => 0.7
)
end
"""
function _toOpenAIAssistantMsg(msg::assistantMessage)::Dict{String, Any}
return Dict{String, Any}(
"role" => "assistant",
"content" => _toOpenAIBlocks(msg.content),
)
end
# convert various messages to openai message format
function _toOpenAIToolResultMsg(msg::toolResultMessage)::Dict{String, Any}
return Dict{String, Any}(
"role" => "tool",
"tool_call_id" => msg.toolCallId,
"name" => msg.toolName,
"content" => _toOpenAIBlocks(msg.content),
)
end
function _toOpenAIBlocks(contents::Vector{messageContent})::Vector{Dict{String, Any}}
blocks = Vector{Dict{String, Any}}()
for c in contents
if c isa textContent
push!(blocks, Dict("type" => "text", "text" => c.text))
elseif c isa imageContent
data_uri = "data:$(c.mimeType);base64,$(c.data)"
push!(blocks, Dict(
"type" => "image_url",
"image_url" => Dict("url" => data_uri),
))
end
end
return blocks
return openai_message
end