update
This commit is contained in:
+26
-19
@@ -3,7 +3,7 @@ module agentCore
|
||||
export yiemAgent, _agentLoop, OpenAiToUserMessage
|
||||
|
||||
using JSON, DataStructures, Dates, UUIDs, HTTP, Random, PrettyPrinting, Serialization,
|
||||
DataFrames, Base.Threads
|
||||
DataFrames, Base.Threads, NATS
|
||||
using GeneralUtils
|
||||
using ..type, ..utils, ..toolRegistry
|
||||
|
||||
@@ -342,20 +342,23 @@ function _processMessage(
|
||||
agentEventSink("_processMessage 1")
|
||||
# loop until llmCall() response didn't use tool calls
|
||||
final_response = nothing
|
||||
|
||||
""" example message in inputChannel
|
||||
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" => "data:mime_type;base64,image2_base64_string")
|
||||
),
|
||||
]
|
||||
)
|
||||
"""
|
||||
|
||||
while true
|
||||
|
||||
""" example message in inputChannel
|
||||
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" => "data:mime_type;base64,image2_base64_string")
|
||||
),
|
||||
]
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
# Drain inputChannel and convert OpenAI-format messages to userMessage type
|
||||
while isready(inputChannel)
|
||||
@@ -377,22 +380,26 @@ function _processMessage(
|
||||
# call prepareContext()
|
||||
state = agentState(systemPrompt, nothing, tools, messages)
|
||||
agentEventSink("_processMessage 8")
|
||||
preparedContext = prepareContext(state)
|
||||
preparedContext = prepareContext(state, agentEventSink)
|
||||
agentEventSink("_processMessage 8")
|
||||
# Call formatMessagesForLLM() to format for LLM
|
||||
formattedMessages = formatMessagesForLLM(preparedContext)
|
||||
formattedMessages = formatMessagesForLLM(preparedContext, agentEventSink)
|
||||
|
||||
agentEventSink("_processMessage 10")
|
||||
# Call llmCall() (blocking — the task waits here)
|
||||
response = llmCall(formattedMessages)
|
||||
agentEventSink(response)
|
||||
|
||||
""" response example
|
||||
response = JSON.Object{String, Any}("finish_reason" => "tool_calls", "index" => 0, "message" => JSON.Object{String, Any}("role" => "assistant", "content" => "", "reasoning_content" => "Here's a thinking process:\n\n1. **Identify User Request**: The user is asking for the weather in Bangkok.\n2. **Locate Relevant Tool**: I have a `getWeather` function available.\n3. **Check Function Parameters**:\n - `city` (required): City and country, e.g., 'San Francisco, CA' or 'Tokyo, Japan'\n - `units` (optional, default \"celsius\"): Temperature scale (\"celsius\" or \"fahrenheit\")\n4. **Prepare Parameters**:\n - `city`: \"Bangkok, Thailand\" (adding country for clarity, though just \"Bangkok\" might work, following the example format is safer)\n - `units`: Not specified, so I'll use the default (\"celsius\")\n5. **Execute Tool Call**: Call `getWeather` with `city: \"Bangkok, Thailand\"`\n6. **Anticipate Response**: The function will return current weather and forecast data for Bangkok. I'll then format it nicely for the user.\n - *Self-Correction/Verification during thought*: The prompt says \"city: City and country, e.g., 'San Francisco, CA' or 'Tokyo, Japan'\". I'll use \"Bangkok, Thailand\". The `units` parameter is optional, so I'll omit it to use the default.\n - Proceed with tool call.✅\n", "tool_calls" => Any[JSON.Object{String, Any}("type" => "function", "function" => JSON.Object{String, Any}("name" => "getWeather", "arguments" => "{\"city\":\"Bangkok, Thailand\"}"), "id" => "6fOilR5QPcdppbAAHluhkRyUDu3oWMAL")]))
|
||||
"""
|
||||
|
||||
agentEventSink(string(response))
|
||||
agentEventSink("_processMessage 11")
|
||||
error("debug marker")
|
||||
# Check if LLM used tool calls (inspect content for tool_call blocks)
|
||||
#WORKING Check if LLM used tool calls (inspect content for tool_call blocks)
|
||||
hasToolCalls = false
|
||||
toolCallList = agentToolCall[]
|
||||
|
||||
for content_block in response.content
|
||||
for content_block in response.content # extract response
|
||||
if content_block isa Dict
|
||||
if get(content_block, :type, "") == "tool_calls"
|
||||
hasToolCalls = true
|
||||
|
||||
Reference in New Issue
Block a user