diff --git a/backend/agents/event_location_agent.go b/backend/agents/event_location_agent.go deleted file mode 100644 index 68a07b0..0000000 --- a/backend/agents/event_location_agent.go +++ /dev/null @@ -1,267 +0,0 @@ -package agents - -import ( - "context" - "encoding/json" - "os" - "screenmark/screenmark/.gen/haystack/haystack/model" - "screenmark/screenmark/agents/client" - "screenmark/screenmark/models" - "time" - - "github.com/charmbracelet/log" - "github.com/google/uuid" -) - -// This prompt is probably shit. -const eventLocationPrompt = ` -You are an agent that extracts events, locations, and organizers from an image. Your primary tasks are to identify and create locations and organizers before creating events. Follow these steps: - -Identify and Create Locations: - -Check if the image contains a location. -If a location is found, check if it exists in the listLocations. -If the location does not exist, create it first. -Always reuse existing locations from listLocations to avoid duplicates. - -Identify and Create Events: - -Check if the image contains an event. An event should have a name and a date. -If an event is found, ensure you have a location (from step 1) and an organizer (from step 2) before creating the event. -Events must have an associated location and organizer. Do not create an event without these. -If possible, return a start time and an end time as ISO datetime strings. -Handling Images Without Events or Locations: - -It is possible that the image does not contain an event or a location. In such cases, do not create an event. -Always prioritize the creation of locations and organizers before events. Ensure that all events have an associated location and organizer. -` - -// TODO: this should be read directly from a file on load. -const eventLocationTools = ` -[ - { - "type": "function", - "function": { - "name": "createLocation", - "description": "Creates a location. No not use if you think an existing location is suitable!", - "parameters": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "address": { - "type": "string" - } - }, - "required": ["name"] - } - } - }, - { - "type": "function", - "function": { - "name": "listLocations", - "description": "Lists the locations available", - "parameters": { - "type": "object", - "properties": {} - } - } - }, - { - "type": "function", - "function": { - "name": "createEvent", - "description": "Creates a new event", - "parameters": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "startDateTime": { - "type": "string", - "description": "The start time as an ISO string" - }, - "endDateTime": { - "type": "string", - "description": "The end time as an ISO string" - }, - "locationId": { - "type": "string", - "description": "The ID of the location, available by listLocations" - }, - "organizerName": { - "type": "string", - "description": "The name of the organizer" - } - }, - "required": ["name"] - } - } - }, - { - "type": "function", - "function": { - "name": "finish", - "description": "Nothing else to do. call this function.", - "parameters": {} - } - } -] -` - -type EventLocationAgent struct { - client client.AgentClient - - eventModel models.EventModel - locationModel models.LocationModel - contactModel models.ContactModel - - toolHandler client.ToolsHandlers -} - -// TODO make these private - -type ListLocationArguments struct{} -type ListOrganizerArguments struct{} - -type CreateLocationArguments struct { - Name string `json:"name"` - Address *string `json:"address,omitempty"` - Coordinates *string `json:"coordinates,omitempty"` -} - -type CreateOrganizerArguments struct { - Name string `json:"name"` - PhoneNumber *string `json:"phoneNumber,omitempty"` - Email *string `json:"email,omitempty"` -} - -type AttachImageLocationArguments struct { - LocationId string `json:"locationId"` -} - -type CreateEventArguments struct { - Name string `json:"name"` - StartDateTime string `json:"startDateTime"` - EndDateTime string `json:"endDateTime"` - LocationId string `json:"locationId"` - OrganizerName string `json:"organizerName"` -} - -func NewLocationEventAgent(locationModel models.LocationModel, eventModel models.EventModel, contactModel models.ContactModel) (EventLocationAgent, error) { - agentClient, err := client.CreateAgentClient(log.NewWithOptions(os.Stdout, log.Options{ - ReportTimestamp: true, - TimeFormat: time.Kitchen, - Prefix: "Location & Events 📅", - })) - if err != nil { - return EventLocationAgent{}, err - } - - agent := EventLocationAgent{ - client: agentClient, - locationModel: locationModel, - eventModel: eventModel, - contactModel: contactModel, - } - - agentClient.ToolHandler.AddTool("listLocations", - func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) { - return agent.locationModel.List(context.Background(), info.UserId) - }, - ) - - agentClient.ToolHandler.AddTool("createLocation", - func(info client.ToolHandlerInfo, _args string, call client.ToolCall) (any, error) { - args := CreateLocationArguments{} - err := json.Unmarshal([]byte(_args), &args) - if err != nil { - return model.Locations{}, err - } - - ctx := context.Background() - - location, err := agent.locationModel.Save(ctx, info.UserId, model.Locations{ - Name: args.Name, - Address: args.Address, - }) - - if err != nil { - return location, err - } - - _, err = agent.locationModel.SaveToImage(ctx, info.ImageId, location.ID) - - return location, err - }, - ) - - agentClient.ToolHandler.AddTool("createEvent", - func(info client.ToolHandlerInfo, _args string, call client.ToolCall) (any, error) { - args := CreateEventArguments{} - err := json.Unmarshal([]byte(_args), &args) - if err != nil { - return model.Locations{}, err - } - - ctx := context.Background() - - layout := "2006-01-02T15:04:05Z" - - startTime, err := time.Parse(layout, args.StartDateTime) - if err != nil { - return model.Events{}, err - } - - endTime, err := time.Parse(layout, args.EndDateTime) - if err != nil { - return model.Events{}, err - } - - event, err := agent.eventModel.Save(ctx, info.UserId, model.Events{ - Name: args.Name, - StartDateTime: &startTime, - EndDateTime: &endTime, - }) - - if err != nil { - return event, err - } - - organizer, err := agent.contactModel.Save(ctx, info.UserId, model.Contacts{ - Name: args.Name, - }) - - if err != nil { - return event, err - } - - _, err = agent.eventModel.SaveToImage(ctx, info.ImageId, event.ID) - if err != nil { - return event, err - } - - _, err = agent.contactModel.SaveToImage(ctx, info.ImageId, organizer.ID) - if err != nil { - return event, err - } - - locationId, err := uuid.Parse(args.LocationId) - if err != nil { - return event, err - } - - event, err = agent.eventModel.UpdateLocation(ctx, event.ID, locationId) - if err != nil { - return event, err - } - - return agent.eventModel.UpdateOrganizer(ctx, event.ID, organizer.ID) - }, - ) - - return agent, nil -} diff --git a/backend/agents/orchestrator.go b/backend/agents/orchestrator.go index 8cede86..7c4caca 100644 --- a/backend/agents/orchestrator.go +++ b/backend/agents/orchestrator.go @@ -2,7 +2,6 @@ package agents import ( "errors" - "fmt" "os" "screenmark/screenmark/agents/client" "time"