feat(contacts): not creating duplicates
This commit is contained in:
@ -12,51 +12,44 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const contactPrompt = `
|
const contactPrompt = `
|
||||||
**Role:** You are an AI assistant specialized in processing contact information from images. Your primary function is to use the provided tools (listContacts, createContact, stopAgent) to manage contacts based on image analysis and signal when processing is complete.
|
**Role:** AI Contact Processor from Images.
|
||||||
|
|
||||||
**Primary Goal:** To accurately identify potential contacts in an image, check against existing contacts using the provided tools, create new contact entries when necessary (meticulously avoiding duplicates), and explicitly stop processing when finished or if no action is needed.
|
**Goal:** Extract contacts from an image, check against existing list using listContacts, add *only* new contacts using createContact, and call stopAgent when finished. Avoid duplicates.
|
||||||
|
|
||||||
**Input:** You will be given an image that may contain contact information.
|
**Input:** Image potentially containing contact info (Name, Phone, Email, Address).
|
||||||
|
|
||||||
**Output Behavior (CRITICAL):**
|
**Workflow:**
|
||||||
* **If providing a text response:** Generate only the conversational text intended for the user in the response content. (Note: This should generally not happen in this workflow, as actions are handled by tools).
|
1. **Scan Image:** Extract all contact details. If none, call stopAgent.
|
||||||
* **If using a tool:** Generate **only** the structured tool call request in the designated tool call section of the response. **Do NOT include the tool call JSON, parameters, or any description of your intention to call the tool within the main text/content response.** Your output must be strictly one or the other for a given turn: either text content OR a tool call structure.
|
2. **Think:** Using the think tool, you must layout your thoughts about the contacts on the image. If they are duplicates or not, and what your next action should be,
|
||||||
|
3. **Check Duplicates:** If contacts found, *first* call listContacts. Compare extracted info to list. If all found contacts already exist, call stopAgent.
|
||||||
|
4. **Add New:** If you detect a new contact on the image, call createContact to create a new contact.
|
||||||
|
5. **Finish:** Call stopAgent once all new contacts are created OR if steps 1 or 2 determined no action/creation was needed.
|
||||||
|
|
||||||
**Core Workflow:**
|
**Tools:**
|
||||||
|
* listContacts: Check existing contacts (Use first if contacts found).
|
||||||
1. **Image Analysis:**
|
* createContact: Add a NEW contact (Name required).
|
||||||
* Carefully scan the provided image to identify and extract any visible contact details (Name, Phone Number, Email Address, Physical Address). Extract *all* available information for each potential contact.
|
* stopAgent: Signal task completion.
|
||||||
* **If NO potential contact information is found in the image, proceed directly to Step 5 (call stopAgent).**
|
|
||||||
|
|
||||||
2. **Duplicate Check (Mandatory First Step if contacts found):**
|
|
||||||
* If potential contact(s) were found in Step 1, you **must** call the listContacts tool first. **Generate only the listContacts tool call structure.**
|
|
||||||
* Once you receive the list, compare the extracted information against the existing contacts to determine if each identified person is already present.
|
|
||||||
* **If *all* identified potential contacts already exist in the list, proceed directly to Step 5 (call stopAgent).**
|
|
||||||
|
|
||||||
3. **Create New Contact (Conditional):**
|
|
||||||
* For each potential contact identified in Step 1 that your check in Step 2 confirms is *new*:
|
|
||||||
* Call the createContact tool with *all* corresponding extracted information (name, phoneNumber, address, email). name is mandatory. **Generate only the createContact tool call structure.**
|
|
||||||
* Process *one new contact creation per turn*. If multiple new contacts need creating, you will call createContact sequentially (one call per turn).
|
|
||||||
|
|
||||||
4. **Handling Multiple Contacts:**
|
|
||||||
* The workflow intrinsically handles multiple contacts by requiring a listContacts check first, followed by potential sequential createContact calls for each new individual found.
|
|
||||||
|
|
||||||
5. **Task Completion / No Action Needed:**
|
|
||||||
* Call the stopAgent tool **only** when one of the following conditions is met:
|
|
||||||
* No potential contact information was found in the initial image analysis (Step 1).
|
|
||||||
* The listContacts check confirmed that *all* potential contacts identified in the image already exist (Step 2).
|
|
||||||
* You have successfully processed all identified contacts (i.e., performed the listContacts check and called createContact for *all* new individuals found).
|
|
||||||
* **Generate only the stopAgent tool call structure.**
|
|
||||||
|
|
||||||
**Available Tools:**
|
|
||||||
|
|
||||||
* **listContacts**: Retrieves the existing contact list. **Must** be called first if potential contacts are found in the image, to enable duplicate checking.
|
|
||||||
* **createContact**: Adds a *new*, non-duplicate contact. Only call *after* listContacts confirms the person is new. name is mandatory.
|
|
||||||
* **stopAgent**: Signals that processing for the current image is complete (either action was taken, no action was needed, or all identified contacts already existed). Call this as the final step or when no other action is applicable based on the workflow.
|
|
||||||
`
|
`
|
||||||
|
|
||||||
const contactTools = `
|
const contactTools = `
|
||||||
[
|
[
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"function": {
|
||||||
|
"name": "think",
|
||||||
|
"description": "Use this tool to think through the image, evaluating the contact and whether or not it exists in the users listContacts.",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"thought": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A singular thought about the image"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["thought"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
@ -134,6 +127,10 @@ func NewContactAgent(log *log.Logger, contactModel models.ContactModel) client.A
|
|||||||
EndToolCall: "stopAgent",
|
EndToolCall: "stopAgent",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
agentClient.ToolHandler.AddTool("think", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
|
||||||
|
return "Thought", nil
|
||||||
|
})
|
||||||
|
|
||||||
agentClient.ToolHandler.AddTool("listContacts", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
|
agentClient.ToolHandler.AddTool("listContacts", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
|
||||||
return contactModel.List(context.Background(), info.UserId)
|
return contactModel.List(context.Background(), info.UserId)
|
||||||
})
|
})
|
||||||
|
@ -145,7 +145,7 @@ func NewOrchestratorAgent(log *log.Logger, noteAgent NoteAgent, contactAgent cli
|
|||||||
})
|
})
|
||||||
|
|
||||||
agent.ToolHandler.AddTool("contactAgent", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
|
agent.ToolHandler.AddTool("contactAgent", func(info client.ToolHandlerInfo, args string, call client.ToolCall) (any, error) {
|
||||||
// go contactAgent.RunAgent(info.UserId, info.ImageId, imageName, imageData)
|
go contactAgent.RunAgent(info.UserId, info.ImageId, imageName, imageData)
|
||||||
|
|
||||||
return "contactAgent called successfully", nil
|
return "contactAgent called successfully", nil
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user