This commit is contained in:
2026-08-12 04:00:09 +07:00
parent 2ad3d1df38
commit 06d51c1ee9
3 changed files with 297 additions and 376 deletions
+5 -5
View File
@@ -5,7 +5,7 @@ export yiemAgent, _agent_loop, OpenAiToUserMessage
using JSON, DataStructures, Dates, UUIDs, HTTP, Random, PrettyPrinting, Serialization,
DataFrames, Base.Threads
using GeneralUtils
using ..type, ..utils
using ..type, ..utils, ..toolRegistry
# ---------------------------------------------- 100 --------------------------------------------- #
@@ -85,7 +85,7 @@ on `inputChannel` and `followUpChannel` channels concurrently.
"""
function yiemAgent(
toolsFolderPath::String,
llmCall::Function,
llmCall,
;
systemPrompt::String="You are helpful assistant.",
model=nothing,
@@ -107,12 +107,12 @@ function yiemAgent(
outputChannel = Channel(16)
# load tools from toolsFolderPath
toolStore = YiemAgent.toolStore(name="myagent")
loadTools(toolStore, toolsFolderPath)
toolStore1 = toolStore(name="myagent")
loadTools(toolStore1, toolsFolderPath)
# Create struct with a placeholder task, then spawn and replace it
agent = yiemAgent(
agentState(systemPrompt, model, getTools(toolStore), messages),
agentState(systemPrompt, model, getTools(toolStore1), messages),
inputChannel,
followUp,
outputChannel,
+16 -16
View File
@@ -144,7 +144,7 @@ assistantMessage("assistant", [textContent("Hello!")], "", "", "gpt-4", ..., "en
```
"""
function assistantMessage(; role="assistant", content=Vector{messageContent}(),
api="", provider="", model="", usage=llmUsage(0, 0), stopReason="end_turn",
api="", provider="", model=nothing, usage=llmUsage(0, 0), stopReason="end_turn",
errorMessage=nothing, timestamp=now())
return assistantMessage(role, content, api, provider, model, usage, stopReason, errorMessage, timestamp)
end
@@ -309,7 +309,7 @@ end
mutable struct agentState # Mutable runtime state of an agent
systemPrompt::String # System prompt for the agent
model::llmModel # LLM model to use
model::Union{llmModel, Nothing} # LLM model to use
tools::OrderedDict{String, agentTool} # Available tools keyed by name, insertion-ordered
# messages history includes userMessage, assistantMessage, toolResultMessage. NO system prompt
@@ -341,21 +341,21 @@ julia> state = agentState(systemPrompt="You are a helpful assistant")
agentState("You are a helpful assistant", OrderedDict{String, agentTool}(), agentMessage[], String[], nothing)
"""
function agentState(
systemPrompt::String="",
model::llmModel=llmModel{String}("", "", "unknown", "unknown", "", false, String[],
modelCost(0.0, 0.0, 0.0, 0.0), 0, 0),
tools::OrderedDict{String, agentTool}=OrderedDict{String, agentTool}(),
messages::Vector{agentMessage}=agentMessage[],
systemPrompt::String="",
model::llmModel=llmModel{String}("", "unknown", "unknown", "", false, String[],
modelCost(0.0, 0.0, 0.0, 0.0), 0, 0),
tools::OrderedDict{String, agentTool}=OrderedDict{String, agentTool}(),
messages::Vector{agentMessage}=agentMessage[],
)
agentState(
systemPrompt,
model,
deepcopy(tools),
deepcopy(messages),
Vector{String}(),
false,
nothing,
)
agentState(
systemPrompt,
model,
deepcopy(tools),
deepcopy(messages),
Vector{String}(),
false,
nothing,
)
end