@@ -10,11 +10,14 @@ import (
1010 "strings"
1111 "time"
1212
13+ "github.com/google/uuid"
1314 coreTypes "github.com/mudler/LocalAgent/core/types"
1415 "github.com/mudler/LocalAgent/pkg/llm"
1516 "github.com/mudler/LocalAgent/pkg/xlog"
1617 "github.com/mudler/LocalAgent/services"
18+ "github.com/mudler/LocalAgent/services/connectors"
1719 "github.com/mudler/LocalAgent/webui/types"
20+ "github.com/sashabaranov/go-openai"
1821 "github.com/sashabaranov/go-openai/jsonschema"
1922
2023 "github.com/mudler/LocalAgent/core/sse"
@@ -405,7 +408,7 @@ func (a *App) ListActions() func(c *fiber.Ctx) error {
405408 }
406409}
407410
408- func (a * App ) Responses (pool * state.AgentPool ) func (c * fiber.Ctx ) error {
411+ func (a * App ) Responses (pool * state.AgentPool , tracker * connectors. ConversationTracker [ string ] ) func (c * fiber.Ctx ) error {
409412 return func (c * fiber.Ctx ) error {
410413 var request types.RequestBody
411414 if err := c .BodyParser (& request ); err != nil {
@@ -414,9 +417,15 @@ func (a *App) Responses(pool *state.AgentPool) func(c *fiber.Ctx) error {
414417
415418 request .SetInputByType ()
416419
417- agentName := request .Model
420+ var previousResponseID string
421+ conv := []openai.ChatCompletionMessage {}
422+ if request .PreviousResponseID != nil {
423+ previousResponseID = * request .PreviousResponseID
424+ conv = tracker .GetConversation (previousResponseID )
425+ }
418426
419- messages := request .ToChatCompletionMessages ()
427+ agentName := request .Model
428+ messages := append (conv , request .ToChatCompletionMessages ()... )
420429
421430 a := pool .GetAgent (agentName )
422431 if a == nil {
@@ -435,7 +444,17 @@ func (a *App) Responses(pool *state.AgentPool) func(c *fiber.Ctx) error {
435444 xlog .Info ("we got a response from the agent" , "agent" , agentName , "response" , res .Response )
436445 }
437446
447+ conv = append (conv , openai.ChatCompletionMessage {
448+ Role : "assistant" ,
449+ Content : res .Response ,
450+ })
451+
452+ id := uuid .New ().String ()
453+
454+ tracker .SetConversation (id , conv )
455+
438456 response := types.ResponseBody {
457+ ID : id ,
439458 Object : "response" ,
440459 // "created_at": 1741476542,
441460 CreatedAt : time .Now ().Unix (),
0 commit comments