From 70d4411270994c881baf3ffc3fe46e574ce16b45 Mon Sep 17 00:00:00 2001 From: John Costa Date: Sat, 12 Apr 2025 07:29:29 +0100 Subject: [PATCH] feat(contact-agent): linking to existing instead of creating new ones --- backend/agents/client/client.go | 3 +++ backend/agents/contact_agent.go | 45 ++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/backend/agents/client/client.go b/backend/agents/client/client.go index bbe0279..6be9f96 100644 --- a/backend/agents/client/client.go +++ b/backend/agents/client/client.go @@ -209,6 +209,9 @@ func (client AgentClient) Process(info ToolHandlerInfo, req *AgentRequestBody) e toolResponse := client.ToolHandler.Handle(info, toolCall) + client.Log.SetLevel(log.DebugLevel) + client.Log.Debugf("Response: %s", toolResponse.Content) + req.Chat.AddToolResponse(toolResponse) } diff --git a/backend/agents/contact_agent.go b/backend/agents/contact_agent.go index 2f1df79..2e41c21 100644 --- a/backend/agents/contact_agent.go +++ b/backend/agents/contact_agent.go @@ -20,7 +20,8 @@ You can use tools to achieve your task. You should use listContacts to make sure that you don't create duplicate contacts. -Call createContact when you see there is a new contact on this image. +Call createContact when you see there is a new contact on this image. Do not create duplicate contacts. +Or call linkContact when you think this image contains an existing contact. Call finish if you dont think theres anything else to do. ` @@ -65,6 +66,23 @@ const contactTools = ` "required": ["name"] } } + }, + { + "type": "function", + "function": { + "name": "linkContact", + "description": "Links an existing contact with this image", + "parameters": { + "type": "object", + "properties": { + "contactId": { + "type": "string", + "description": "The UUID of the existing contact" + } + }, + "required": ["contactId"] + } + } }, { "type": "function", @@ -94,6 +112,9 @@ type createContactsArguments struct { Address *string `json:"address"` Email *string `json:"email"` } +type linkContactArguments struct { + ContactID string `json:"contactId"` +} // Yeah this is just a copy of the other one. func (agent ContactAgent) GetContacts(userId uuid.UUID, imageId uuid.UUID, imageName string, imageData []byte) error { @@ -178,5 +199,27 @@ func NewContactAgent(contactModel models.ContactModel) (ContactAgent, error) { return contact, nil }) + agentClient.ToolHandler.AddTool("linkContact", func(info client.ToolHandlerInfo, _args string, call client.ToolCall) (any, error) { + args := linkContactArguments{} + err := json.Unmarshal([]byte(_args), &args) + if err != nil { + return "", err + } + + ctx := context.Background() + + contactUuid, err := uuid.Parse(args.ContactID) + if err != nil { + return "", err + } + + _, err = agent.contactModel.SaveToImage(ctx, info.ImageId, contactUuid) + if err != nil { + return "", err + } + + return "Saved", nil + }) + return agent, nil }