From 45a1d93bc77db54bee9c38f5f17d1d9b0e3a39f7 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Mon, 15 Apr 2024 21:05:30 +0700 Subject: [PATCH] update --- src/interface.jl | 10 ++++---- src/type.jl | 65 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 49388f9..1d64185 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -1,6 +1,6 @@ module interface -export addNewMessage +export add_new_message using JSON3, DataStructures, Dates, UUIDs, HTTP, Random using GeneralUtils @@ -47,7 +47,7 @@ using ..type, ..util, ..llmfunction Return\n ----- - message left + nothing Example\n ----- @@ -72,13 +72,13 @@ using ..type, ..util, ..llmfunction msgMeta, agentConfig, ) - julia> YiemAgent.addNewMessage(a, "user", "hello") + julia> YiemAgent.add_new_message(a, "user", "hello") ``` Signature\n ----- -""" #WORKING -function addNewMessage(a::T1, role::String, text::T2; +""" +function add_new_message(a::T1, role::String, text::T2; maximumMsg::Integer=20) where {T1<:agent, T2<:AbstractString} if role ∉ ["system", "user", "assistant"] # guard against typo error("role is not in agent.availableRole $(@__LINE__)") diff --git a/src/type.jl b/src/type.jl index 9d11975..478f89c 100644 --- a/src/type.jl +++ b/src/type.jl @@ -1,6 +1,6 @@ module type -export agent, sommelier, initAgentMemory +export agent, sommelier, clearhistory using Dates, UUIDs, DataStructures, JSON3 using GeneralUtils @@ -67,7 +67,7 @@ abstract type agent end tools=tools ) ``` -""" +""" #TODO update document @kwdef mutable struct sommelier <: agent name::String id::String @@ -154,29 +154,52 @@ function sommelier( return newAgent end +""" Clear agent history. + Arguments\n + ----- + a::agent + an agent -# function initAgentMemory(a::T) where {T<:agent} -# a.chathistory = Dict{String,Any}() -# a.mctstree = Dict{Symbol, Any}() -# a.plan[:activeplan] = Dict{Symbol, Any}() -# a.plan[:currenttrajectory] = Dict{Symbol, Any}() -# end + Return\n + ----- + nothing + Example\n + ----- + ```jldoctest + julia> using YiemAgent, MQTTClient, GeneralUtils + julia> client, connection = MakeConnection("test.mosquitto.org", 1883) + julia> connect(client, connection) + julia> msgMeta = GeneralUtils.generate_msgMeta("testtopic") + julia> agentConfig = Dict( + :receiveprompt=>Dict( + :mqtttopic=> "testtopic/receive", + ), + :receiveinternal=>Dict( + :mqtttopic=> "testtopic/internal", + ), + :text2text=>Dict( + :mqtttopic=> "testtopic/text2text", + ), + ) + julia> a = YiemAgent.sommelier( + client, + msgMeta, + agentConfig, + ) + julia> YiemAgent.add_new_message(a, "user", "hello") + julia> YiemAgent.clearhistory(a) + ``` -function clearMessage(a::T) where {T<:agent} - for i in eachindex(a.messages) - if length(a.messages) > 0 - pop!(a.messages) - else - break - end - end - - a.memory = newAgentMemory() - - # @show a.messages - # @show a.memory + Signature\n + ----- +""" #TODO update document +function clearhistory(a::T) where {T<:agent} + empty!(a.chathistory) + empty!(a.mctstree) + empty!(a.plan[:activeplan]) + empty!(a.plan[:currenttrajectory]) end