This commit is contained in:
2026-08-24 13:33:20 +07:00
parent 5f284883b3
commit 9193260539
4 changed files with 58 additions and 117 deletions
-54
View File
@@ -1,54 +0,0 @@
{
"nats_server_info": {
"description": "nats server",
"url": "nats.yiem.cc"
},
"testingOrProduction": "testing",
"agentId": "2b74b87a-5413-4fe2-a4d3-405891051680",
"agentCentralConfigSubject": "/yiem/hq/agent/sommelier/backend/config/api/v1.1",
"this_service_name": "agent_backend",
"this_service_input_channel": {
"mqtt": [
"/yiem/hq/agent/sommpanion/backend/db/api_v1"
],
"nats": [
"sommpanion.backend.agentbackend.v1.inbox"
]
},
"agentRole": "sommelier",
"organization": "yiem_hq",
"externalservice": {
"servicesloadbalancer": {
"nats": "sommpanion.backend.servicesloadbalancer.v1.inbox"
},
"textembedding": {
"url": "textembedding.api.v1"
},
"textimage_to_text_llm": {
"url": "https://llmcoder.yiem.cc/v1/chat/completions",
"modelname": "Qwen3.6-35B-A3B-UD-Q4_K_M"
},
"virtualWineCustomer_1": {
"serviceSubject": "",
"modelName": "qwen3:8b"
},
"sommpanion_db" : {
"description": "A database connection info for LibPQ client",
"url": "192.168.88.106:5432",
"dbname": "winedb",
"user": "admin",
"password": "admin@Sommpanion_0.0"
},
"sommpanion_vectordb" : {
"description": "A wine database connection info for LibPQ client",
"url": "192.168.88.106:5433",
"dbname": "vectordb",
"user": "admin",
"password": "admin@Sommpanion_0.0"
},
"fileserver": {
"description": "temporary file server",
"url": "https://fileserver.yiem.cc"
}
}
}
+1 -4
View File
@@ -12,9 +12,6 @@ module YiemAgent
include("toolRegistry.jl")
using .toolRegistry
# include("llmfunction.jl")
# using .llmfunction
include("agentCore.jl")
using .agentCore
@@ -30,4 +27,4 @@ module YiemAgent
end # module YiemAgent_v1
end # end module
+2 -2
View File
@@ -176,7 +176,7 @@ function yiemAgent(
afterToolCall::Function=afterToolCall,
# prepareNextTurn::Union{Function, Nothing}=nothing,
# prepareNextTurnWithContext::Union{Function, Nothing}=nothing,
sessionId::Union{String, Nothing}=nothing,
sessionId::Union{String, Nothing}="",
maxRetryDelayMs::Union{Int64, Nothing}=nothing,
parallelToolExecute::Bool=false,
eventSink=eventSink,
@@ -189,7 +189,7 @@ function yiemAgent(
tools = OrderedDict{String, agentTool}()
registerAllTools(tools, mcpServer; eventSink=eventSink)
registerAllTools(tools, mcpServer; eventSink=eventSink, sessionId=sessionId)
# Create struct with a placeholder task, then spawn and replace it
agent = yiemAgent(
+55 -57
View File
@@ -38,7 +38,7 @@ Wrap an MCP tool definition as an `agentTool`.
The returned tool's `execute` function calls the MCP server's "tools/call"
method with the validated arguments.
"""
function _wrap_mcp_tool(mcpserver, tool_def::AbstractDict{String, Any}; eventSink=nothing)::agentTool
function _wrap_mcp_tool(mcpserver, tool_def::AbstractDict{String, Any}; eventSink=nothing, sessionId=nothing)::agentTool
name = tool_def["name"]
title = get(tool_def, "title", get(tool_def, "label", name))
desc = get(tool_def, "description", "")
@@ -68,7 +68,7 @@ function _wrap_mcp_tool(mcpserver, tool_def::AbstractDict{String, Any}; eventSin
signal::Union{Nothing,abortSignal},
eventSink) -> begin
try
response = mcpserver("tools/call", name, args)
response = mcpserver("tools/call", name, args, sessionId)
# Parse JSON-RPC 2.0 response envelope
if haskey(response, "error")
@@ -115,76 +115,74 @@ Handles pagination via `nextCursor`. Skips tools already registered.
# Returns
- `Int`: number of new tools registered
"""
function register_mcp_tools(tools::OrderedDict{String, agentTool}, mcpserver; eventSink=nothing)::Int
if mcpserver === nothing
function register_mcp_tools(tools::OrderedDict{String, agentTool}, mcpserver; eventSink=nothing, sessionId=nothing)::Int
if mcpserver === nothing
return 0
end
new_count = 0
try
eventSink("register_mcp_tools 1")
response = mcpserver("tools/list", sessionId)
eventSink("register_mcp_tools 2")
# Parse JSON-RPC 2.0 response envelope
if haskey(response, "error")
rpc_error = response["error"]
err_msg = get(rpc_error, "message", "Unknown MCP error")
println("[toolRegistry] MCP tools/list failed: $err_msg")
return 0
end
if haskey(response, "result")
response = response["result"]
end
new_count = 0
tools_array = response["tools"]
cursor = get(response, "nextCursor", nothing)
try
eventSink("register_mcp_tools 1")
response = mcpserver("tools/list")
eventSink("register_mcp_tools 2")
# Parse JSON-RPC 2.0 response envelope
if haskey(response, "error")
rpc_error = response["error"]
err_msg = get(rpc_error, "message", "Unknown MCP error")
println("[toolRegistry] MCP tools/list failed: $err_msg")
return 0
for tool_def in tools_array
name = tool_def["name"]
if haskey(tools, name)
continue
end
wrapped = _wrap_mcp_tool(mcpserver, tool_def, eventSink=eventSink, sessionId=sessionId)
tools[name] = wrapped
new_count += 1
end
# Paginate: fetch remaining tools if nextCursor is present
while cursor !== nothing && cursor !== ""
response = sessionId !== nothing ? mcpserver("tools/list", sessionId) : mcpserver("tools/list")
if haskey(response, "result")
response = response["result"]
end
tools_array = response["tools"]
tools_array = get(response, "tools", Any[])
cursor = get(response, "nextCursor", nothing)
for tool_def in tools_array
name = tool_def["name"]
if haskey(tools, name)
continue
end
wrapped = _wrap_mcp_tool(mcpserver, tool_def, eventSink=eventSink)
wrapped = _wrap_mcp_tool(mcpserver, tool_def, eventSink=eventSink, sessionId=sessionId)
tools[name] = wrapped
new_count += 1
end
# Paginate: fetch remaining tools if nextCursor is present
while cursor !== nothing && cursor !== ""
response = mcpserver("tools/list")
if haskey(response, "result")
response = response["result"]
end
tools_array = get(response, "tools", Any[])
cursor = get(response, "nextCursor", nothing)
for tool_def in tools_array
name = tool_def["name"]
if haskey(tools, name)
continue
end
wrapped = _wrap_mcp_tool(mcpserver, tool_def, eventSink=eventSink)
tools[name] = wrapped
new_count += 1
end
end
println("[toolRegistry] Discovered $new_count MCP tools. Total: $(length(tools))")
catch e
bt = catch_backtrace()
err_msg = sprint() do io
showerror(io, e, bt)
println(io)
end
eventSink(err_msg)
errMsg = sprint(showerror, e)
println("[toolRegistry] MCP tools/list failed: $errMsg")
end
return new_count
println("[toolRegistry] Discovered $new_count MCP tools. Total: $(length(tools))")
catch e
bt = catch_backtrace()
err_msg = sprint() do io
showerror(io, e, bt)
println(io)
end
eventSink(err_msg)
errMsg = sprint(showerror, e)
println("[toolRegistry] MCP tools/list failed: $errMsg")
end
return new_count
end
"""
@@ -234,7 +232,7 @@ pagination via nextCursor), then returns the full tool list.
Subsequent calls: returns the current list (tools remain registered).
"""
function listTool(tools::OrderedDict{String, agentTool}, mcpserver; eventSink=nothing)::agentTool
function listTool(tools::OrderedDict{String, agentTool}, mcpserver; eventSink=nothing, sessionId=nothing)::agentTool
return agentTool(
name="listTools",
label="List Tools",
@@ -248,7 +246,7 @@ function listTool(tools::OrderedDict{String, agentTool}, mcpserver; eventSink=no
signal::Union{Nothing,abortSignal},
eventSink) -> begin
# Discover and register MCP tools (idempotent — skips already registered)
new_count = register_mcp_tools(tools, mcpserver; eventSink=eventSink)
new_count = register_mcp_tools(tools, mcpserver; eventSink=eventSink, sessionId=sessionId)
eventSink("tools dump: " * sprint(show, tools))
# Always include listTools itself in the count
@@ -285,8 +283,8 @@ Register all tools for an agent:
- `tools`: The tool dict to populate
- `mcpserver`: A callable struct that communicates with the MCP server
"""
function registerAllTools(tools::OrderedDict{String, agentTool}, mcpserver=nothing; eventSink=nothing)
list_t = listTool(tools, mcpserver; eventSink=eventSink)
function registerAllTools(tools::OrderedDict{String, agentTool}, mcpserver=nothing; eventSink=nothing, sessionId=nothing)
list_t = listTool(tools, mcpserver; eventSink=eventSink, sessionId=sessionId)
registerTool(tools, list_t; eventSink=eventSink)
end