feat(event-agent): update events function

This commit is contained in:
2025-04-17 18:19:54 +01:00
parent 2b7206c29e
commit 150a43a5dc

View File

@ -17,40 +17,32 @@ const eventPrompt = `
**Primary Goal:** To analyze images, identify potential events (like meetings, appointments, conferences, invitations), extract key details (name, date/time, location description), check against existing events, retrieve location identifiers if applicable, create new event entries when necessary, and signal completion using the 'finish' tool.
**Input:** You will be given an image that may contain information about an event, including details like name, date, time, and location.
**Core Workflow:**
1. **Image Analysis & Detail Extraction:**
* Carefully scan the image to identify potential event information.
* Extract key details: Event Name/Title, Start Date/Time, End Date/Time (if specified), and any Location Description mentioned.
* **If NO identifiable event information (Name and/or Date/Time) is found, proceed directly to Step 6 (call finish).** A location alone is not sufficient to trigger event creation.
2. **Duplicate Check (Mandatory if Event Found):**
* If potential event details were found, you **must** call the listEvents tool first to check for duplicates. **Generate only the listEvents tool call structure.**
**Duplicate Check (Mandatory if Event Found):**
* If potential event details were found, you **must** call the listEvents tool first to check for duplicates. **Generate only the listEvents tool call structure.**
* Once you receive the list, compare the extracted event details (Name, Start Date/Time primarily) against the existing events.
* **If a matching event already exists, proceed directly to Step 6 (call finish).**
3. **Location ID Retrieval (Conditional):**
* If the event is identified as *new* (Step 2) AND a *location description* was extracted (Step 1):
**Location ID Retrieval (Conditional):**
* If the event is identified as *new* AND a *location description* was extracted.
* Call the getEventLocationId tool, providing the extracted location description. **Generate only the getEventLocationId tool call structure.**
* Await the result containing the locationId. If the tool fails or doesn't return a locationId, proceed to Step 4 but omit the locationId.
4. **Create New Event (Conditional):**
* If the event was identified as *new* (Step 2):
**Create Event:**
* If the event was identified as *new*:
* Prepare the parameters for the createEvent tool using the extracted details (Name, Start Date/Time, End Date/Time).
* If a locationId was successfully retrieved in Step 3, include it.
* Call the createEvent tool. **Generate only the createEvent tool call structure.**
* If you identify the event as *duplicate*, meaning you think an event in listEvents is the same as the event on this image.
* Call the updateEvent tool so this image is also linked to that event. If you find any new information you can update it using this tool too.
5. **Handling Multiple Events:**
* If the image contains multiple distinct events, ideally process them one by one following steps 1-4 (or 1-2 then 6) for each before finishing. (Current structure implies one event per image interaction leading to finish).
**Handling Multiple Events:**
* If the image contains multiple distinct events, ideally process them one by one.
* Do this until there are no more events on this image
6. **Task Completion / No Action Needed:**
**Task Completion / No Action Needed:**
* Call the finish tool **only** when one of the following conditions is met:
* No identifiable event information was found in the initial image analysis (Step 1).
* The listEvents check confirmed the identified event already exists (Step 2).
* You have successfully called createEvent for a new event (Step 4).
* **Generate only the finish tool call structure.**
* No identifiable event information was found in the initial image analysis.
* The listEvents check confirmed the identified event already exists.
* You have successfully called createEvent for a new event.
**Available Tools:**
@ -103,6 +95,24 @@ const eventTools = `
}
}
},
{
"type": "function",
"function": {
"name": "updateEvent",
"description": "Updates an existing event record identified by its eventId. Use this tool when listEvents indicates a match for the event details found in the current input.",
"parameters": {
"type": "object",
"properties": {
"eventId": {
"type": "string",
"description": "The UUID of the existing event"
}
},
"required": ["eventId"]
}
}
},
{
"type": "function",
"function": {
@ -142,7 +152,7 @@ type createEventArguments struct {
OrganizerName *string `json:"organizerName"`
LocationID *string `json:"locationId"`
}
type linkEventArguments struct {
type updateEventArguments struct {
EventID string `json:"eventId"`
}
@ -207,8 +217,8 @@ func NewEventAgent(log *log.Logger, eventsModel models.EventModel, locationModel
return events, nil
})
agentClient.ToolHandler.AddTool("linkEvent", func(info client.ToolHandlerInfo, _args string, call client.ToolCall) (any, error) {
args := linkEventArguments{}
agentClient.ToolHandler.AddTool("updateEvent", func(info client.ToolHandlerInfo, _args string, call client.ToolCall) (any, error) {
args := updateEventArguments{}
err := json.Unmarshal([]byte(_args), &args)
if err != nil {
return "", err