This commit is contained in:
2025-04-18 14:21:23 +01:00
parent 49969b0608
commit 1b1f957e01
3 changed files with 31 additions and 23 deletions

View File

@ -19,17 +19,28 @@ Objective: Identify locations from images/text, manage a saved list (create, upd
Core Logic: Core Logic:
**Handle Image/Text Location (if no query was handled in Step 2):** **Extract Location Details:** Attempt to extract location details (like InputName, InputAddress) from the user's input (image or text).
* If location details (InputName, InputAddress, etc.) were successfully extracted from the input in Step 1: * If no details can be extracted, inform the user and use stopAgent.
* Use listLocations to check if a location matching InputName or InputAddress already exists in the saved list.
* **If *no match*** is found: **Check for Existing Location:** If details *were* extracted:
* Use createLocation, providing the extracted InputName (required) and any other details like InputAddress. * Use listLocations with the extracted InputName and/or InputAddress to search for potentially matching locations already saved in the list.
* If no location details could be extracted from the input, use stopAgent.
**Decide Action based on Search Results:**
* **If listLocations returns one or more likely matches:**
* Identify the *best* match (based on name, address similarity).
* **Crucially:** Call upsertLocation, providing the locationId of that best match. Include the newly extracted InputName (required) and any other extracted details (InputAddress, etc.) to potentially *update* the existing record or simply link the current input to it.
* **If listLocations returns no matches OR no returned location is a confident match:**
* Call upsertLocation providing *only* the newly extracted InputName (required) and any other extracted details (InputAddress, etc.). **Do NOT provide a locationId in this case.** This will create a *new* location entry.
4. **Finalize:** After successfully calling upsertLocation (or determining no action could be taken), use stopAgent.
Tool Usage: Tool Usage:
* listLocations: Check saved locations. Used to find matches for user queries or to detect existing entries before creating/updating. Returns matching location(s) including their locationId.
* createLocation: Save a *new* location. Requires name, can include address, etc. You may also use this to update the information in a location, by providing a locationId obtained from listLocations if you believe this location already exists. * **listLocations**: Searches the saved locations list based on provided criteria (like name or address). Used specifically to check if a location potentially already exists before using upsertLocation. Returns a list of matching locations, *each including its locationId*.
* stopAgent: Signals the end of the agent's processing for the current turn. Call this *after* providing the summary message. * **upsertLocation**: Creates or updates a location in the saved list. Requires name. Can include address, etc.
* **To UPDATE:** If you identified an existing location using listLocations, provide its locationId along with any new/updated details (name, address, etc.).
* **To CREATE:** If no existing location was found (or you are creating intentionally), provide the location details (name, address, etc.) but **omit the locationId**.
* **stopAgent**: Signals the end of the agent's processing for the current turn. Call this *after* completing the location task (create/update/failed extraction).
` `
const replyTool = ` const replyTool = `
@ -68,8 +79,8 @@ const locationTools = `
{ {
"type": "function", "type": "function",
"function": { "function": {
"name": "createLocation", "name": "upsertLocation",
"description": "Creates a new location entry in the user's saved list. Use only after listLocations confirms the location does not already exist.", "description": "Upserts a location. This is used for both creating new locations, and updating existing ones. Providing locationId from an existing ID from listLocations, will make this an update function. Not providing one will create a new location. You must provide a locationId if you think the input is a location that already exists.",
"parameters": { "parameters": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -79,7 +90,7 @@ const locationTools = `
}, },
"locationId": { "locationId": {
"type": "string", "type": "string",
"description": "The UUID of the location. You should only provide this IF you believe the contact already exists, from listLocation." "description": "The UUID of the location. You should only provide this IF you believe the location already exists, from listLocation."
}, },
"address": { "address": {
"type": "string", "type": "string",
@ -114,14 +125,11 @@ func getLocationAgentTools(allowReply bool) string {
} }
type listLocationArguments struct{} type listLocationArguments struct{}
type createLocationArguments struct { type upsertLocationArguments struct {
Name string `json:"name"` Name string `json:"name"`
LocationID *string `json:"locationId"` LocationID *string `json:"locationId"`
Address *string `json:"address"` Address *string `json:"address"`
} }
type updateLocationArguments struct {
LocationID string `json:"locationId"`
}
func NewLocationAgentWithComm(log *log.Logger, locationModel models.LocationModel) client.AgentClient { func NewLocationAgentWithComm(log *log.Logger, locationModel models.LocationModel) client.AgentClient {
client := NewLocationAgent(log, locationModel) client := NewLocationAgent(log, locationModel)
@ -143,8 +151,8 @@ func NewLocationAgent(log *log.Logger, locationModel models.LocationModel) clien
return locationModel.List(context.Background(), info.UserId) return locationModel.List(context.Background(), info.UserId)
}) })
agentClient.ToolHandler.AddTool("createLocation", func(info client.ToolHandlerInfo, _args string, call client.ToolCall) (any, error) { agentClient.ToolHandler.AddTool("upsertLocation", func(info client.ToolHandlerInfo, _args string, call client.ToolCall) (any, error) {
args := createLocationArguments{} args := upsertLocationArguments{}
err := json.Unmarshal([]byte(_args), &args) err := json.Unmarshal([]byte(_args), &args)
if err != nil { if err != nil {
return model.Locations{}, err return model.Locations{}, err

View File

@ -114,7 +114,7 @@ func NewOrchestratorAgent(log *log.Logger, noteAgent NoteAgent, contactAgent cli
}) })
agent.ToolHandler.AddTool("noteAgent", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) { agent.ToolHandler.AddTool("noteAgent", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
go noteAgent.GetNotes(info.UserId, info.ImageId, imageName, imageData) // go noteAgent.GetNotes(info.UserId, info.ImageId, imageName, imageData)
return "noteAgent called successfully", nil return "noteAgent called successfully", nil
}) })
@ -126,13 +126,13 @@ func NewOrchestratorAgent(log *log.Logger, noteAgent NoteAgent, contactAgent cli
}) })
agent.ToolHandler.AddTool("locationAgent", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) { agent.ToolHandler.AddTool("locationAgent", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
go locationAgent.RunAgent(info.UserId, info.ImageId, imageName, imageData) // go locationAgent.RunAgent(info.UserId, info.ImageId, imageName, imageData)
return "locationAgent called successfully", nil return "locationAgent called successfully", nil
}) })
agent.ToolHandler.AddTool("eventAgent", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) { agent.ToolHandler.AddTool("eventAgent", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
go eventAgent.RunAgent(info.UserId, info.ImageId, imageName, imageData) // go eventAgent.RunAgent(info.UserId, info.ImageId, imageName, imageData)
return "eventAgent called successfully", nil return "eventAgent called successfully", nil
}) })

View File

@ -31,8 +31,8 @@ func (m EventModel) List(ctx context.Context, userId uuid.UUID) ([]model.Events,
func (m EventModel) Save(ctx context.Context, userId uuid.UUID, event model.Events) (model.Events, error) { func (m EventModel) Save(ctx context.Context, userId uuid.UUID, event model.Events) (model.Events, error) {
// TODO tx here // TODO tx here
insertEventStmt := Events. insertEventStmt := Events.
INSERT(Events.Name, Events.Description, Events.StartDateTime, Events.EndDateTime, Events.LocationID). INSERT(Events.MutableColumns).
VALUES(event.Name, event.Description, event.StartDateTime, event.EndDateTime, event.LocationID). MODEL(event).
RETURNING(Events.AllColumns) RETURNING(Events.AllColumns)
insertedEvent := model.Events{} insertedEvent := model.Events{}