refactor(agents): not returning an error on factory method
This commit is contained in:
@ -90,7 +90,7 @@ type linkContactArguments struct {
|
|||||||
ContactID string `json:"contactId"`
|
ContactID string `json:"contactId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContactAgent(log *log.Logger, contactModel models.ContactModel) (client.AgentClient, error) {
|
func NewContactAgent(log *log.Logger, contactModel models.ContactModel) client.AgentClient {
|
||||||
agentClient := client.CreateAgentClient(client.CreateAgentClientOptions{
|
agentClient := client.CreateAgentClient(client.CreateAgentClientOptions{
|
||||||
SystemPrompt: contactPrompt,
|
SystemPrompt: contactPrompt,
|
||||||
JsonTools: contactTools,
|
JsonTools: contactTools,
|
||||||
@ -151,5 +151,5 @@ func NewContactAgent(log *log.Logger, contactModel models.ContactModel) (client.
|
|||||||
return "Saved", nil
|
return "Saved", nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return agentClient, nil
|
return agentClient
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ type linkEventArguments struct {
|
|||||||
EventID string `json:"eventId"`
|
EventID string `json:"eventId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEventAgent(log *log.Logger, eventsModel models.EventModel, locationAgent client.AgentClient) (client.AgentClient, error) {
|
func NewEventAgent(log *log.Logger, eventsModel models.EventModel, locationModel models.LocationModel) client.AgentClient {
|
||||||
agentClient := client.CreateAgentClient(client.CreateAgentClientOptions{
|
agentClient := client.CreateAgentClient(client.CreateAgentClientOptions{
|
||||||
SystemPrompt: eventPrompt,
|
SystemPrompt: eventPrompt,
|
||||||
JsonTools: eventTools,
|
JsonTools: eventTools,
|
||||||
@ -116,6 +116,10 @@ func NewEventAgent(log *log.Logger, eventsModel models.EventModel, locationAgent
|
|||||||
EndToolCall: "finish",
|
EndToolCall: "finish",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
locationAgent := NewLocationAgent(log.With("Locations 📍"), locationModel)
|
||||||
|
locationQuery := "Can you get me the ID of the location present in this image?"
|
||||||
|
locationAgent.Options.Query = &locationQuery
|
||||||
|
|
||||||
agentClient.ToolHandler.AddTool("listEvents", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
|
agentClient.ToolHandler.AddTool("listEvents", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
|
||||||
return eventsModel.List(context.Background(), info.UserId)
|
return eventsModel.List(context.Background(), info.UserId)
|
||||||
})
|
})
|
||||||
@ -179,12 +183,10 @@ func NewEventAgent(log *log.Logger, eventsModel models.EventModel, locationAgent
|
|||||||
|
|
||||||
agentClient.ToolHandler.AddTool("getEventLocationId", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
|
agentClient.ToolHandler.AddTool("getEventLocationId", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
|
||||||
// TODO: reenable this when I'm creating the agent locally instead of getting it from above.
|
// TODO: reenable this when I'm creating the agent locally instead of getting it from above.
|
||||||
// query := "Can you get me the ID of the location present in this image?"
|
locationAgent.RunAgent(info.UserId, info.ImageId, info.ImageName, *info.Image)
|
||||||
// locationAgent.Log = log.With("Locations 📍", true)
|
|
||||||
// locationAgent.RunAgent(info.UserId, info.ImageId, info.ImageName, *info.Image)
|
|
||||||
|
|
||||||
return locationAgent.Reply, nil
|
return locationAgent.Reply, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return agentClient, nil
|
return agentClient
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ type linkLocationArguments struct {
|
|||||||
LocationID string `json:"locationId"`
|
LocationID string `json:"locationId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLocationAgent(log *log.Logger, locationModel models.LocationModel) (client.AgentClient, error) {
|
func NewLocationAgent(log *log.Logger, locationModel models.LocationModel) client.AgentClient {
|
||||||
agentClient := client.CreateAgentClient(client.CreateAgentClientOptions{
|
agentClient := client.CreateAgentClient(client.CreateAgentClientOptions{
|
||||||
SystemPrompt: locationPrompt,
|
SystemPrompt: locationPrompt,
|
||||||
JsonTools: locationTools,
|
JsonTools: locationTools,
|
||||||
@ -165,5 +165,5 @@ func NewLocationAgent(log *log.Logger, locationModel models.LocationModel) (clie
|
|||||||
return "ok", nil
|
return "ok", nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return agentClient, nil
|
return agentClient
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (agent NoteAgent) GetNotes(userId uuid.UUID, imageId uuid.UUID, imageName s
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNoteAgent(log *log.Logger, noteModel models.NoteModel) (NoteAgent, error) {
|
func NewNoteAgent(log *log.Logger, noteModel models.NoteModel) NoteAgent {
|
||||||
client := client.CreateAgentClient(client.CreateAgentClientOptions{
|
client := client.CreateAgentClient(client.CreateAgentClientOptions{
|
||||||
SystemPrompt: noteAgentPrompt,
|
SystemPrompt: noteAgentPrompt,
|
||||||
})
|
})
|
||||||
@ -78,5 +78,5 @@ func NewNoteAgent(log *log.Logger, noteModel models.NoteModel) (NoteAgent, error
|
|||||||
noteModel: noteModel,
|
noteModel: noteModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
return agent, nil
|
return agent
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ type Status struct {
|
|||||||
Ok bool `json:"ok"`
|
Ok bool `json:"ok"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOrchestratorAgent(log *log.Logger, noteAgent NoteAgent, contactAgent client.AgentClient, locationAgent client.AgentClient, eventAgent client.AgentClient, imageName string, imageData []byte) (client.AgentClient, error) {
|
func NewOrchestratorAgent(log *log.Logger, noteAgent NoteAgent, contactAgent client.AgentClient, locationAgent client.AgentClient, eventAgent client.AgentClient, imageName string, imageData []byte) client.AgentClient {
|
||||||
agent := client.CreateAgentClient(client.CreateAgentClientOptions{
|
agent := client.CreateAgentClient(client.CreateAgentClientOptions{
|
||||||
SystemPrompt: orchestratorPrompt,
|
SystemPrompt: orchestratorPrompt,
|
||||||
JsonTools: orchestratorTools,
|
JsonTools: orchestratorTools,
|
||||||
@ -160,5 +160,5 @@ func NewOrchestratorAgent(log *log.Logger, noteAgent NoteAgent, contactAgent cli
|
|||||||
}, errors.New("Finished! Kinda bad return type but...")
|
}, errors.New("Finished! Kinda bad return type but...")
|
||||||
})
|
})
|
||||||
|
|
||||||
return agent, nil
|
return agent
|
||||||
}
|
}
|
||||||
|
@ -54,25 +54,10 @@ func ListenNewImageEvents(db *sql.DB, eventManager *EventManager) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
noteAgent, err := agents.NewNoteAgent(createLogger("Notes 📝"), noteModel)
|
noteAgent := agents.NewNoteAgent(createLogger("Notes 📝"), noteModel)
|
||||||
if err != nil {
|
contactAgent := agents.NewContactAgent(createLogger("Contacts 👥"), contactModel)
|
||||||
panic(err)
|
locationAgent := agents.NewLocationAgent(createLogger("Locations 📍"), locationModel)
|
||||||
}
|
eventAgent := agents.NewEventAgent(createLogger("Events 📅"), eventModel, locationModel)
|
||||||
|
|
||||||
contactAgent, err := agents.NewContactAgent(createLogger("Contacts 👥"), contactModel)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
locationAgent, err := agents.NewLocationAgent(createLogger("Locations 📍"), locationModel)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
eventAgent, err := agents.NewEventAgent(createLogger("Events 📅"), eventModel, locationAgent)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
image, err := imageModel.GetToProcessWithData(ctx, imageId)
|
image, err := imageModel.GetToProcessWithData(ctx, imageId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -85,11 +70,7 @@ func ListenNewImageEvents(db *sql.DB, eventManager *EventManager) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
orchestrator, err := agents.NewOrchestratorAgent(createLogger("Orchestrator 🎼"), noteAgent, contactAgent, locationAgent, eventAgent, image.Image.ImageName, image.Image.Image)
|
orchestrator := agents.NewOrchestratorAgent(createLogger("Orchestrator 🎼"), noteAgent, contactAgent, locationAgent, eventAgent, image.Image.ImageName, image.Image.Image)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = orchestrator.RunAgent(image.UserID, image.ImageID, image.Image.ImageName, image.Image.Image)
|
err = orchestrator.RunAgent(image.UserID, image.ImageID, image.Image.ImageName, image.Image.Image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
databaseEventLog.Error("Orchestrator failed", "error", err)
|
databaseEventLog.Error("Orchestrator failed", "error", err)
|
||||||
|
Reference in New Issue
Block a user