ai newsMi., 25. Nov.
EilmeldungCan Claude’s storage webhooks miss an hour-long outage?

Tool Use in Agentic AI: Designing Tools Your Agent Won’t Misuse

Table of Contents What Is a Unified Customer Profile? Why Each Channel Gives You a Different Identity The Data Model Identity Resolution: Linking the Same Person Building the Single Customer View Syncing Data to Your CRM Giving AI Agents Access Through Tool Calling Pitfalls to Avoid Conclusion What

dev.toSonntag 07:04 · 22.11.5 Min. Lesezeit
Bild: dev.to

Without it, you get duplicate contacts, repeated questions ("What's your order number?" asked three times), and broadcasts that hit the same person on three channels.

Note: A unified profile is not a bigger contact table. It is a graph: one person node connected to many channel identities.

The core problem is that every platform identifies users differently, and none of them hands you a universal ID.

Keep three concepts separate: the person, their channel identities, and the events that happen to them.

CREATE TABLE customers ( id UUID PRIMARY KEY DEFAULT gen_random_uuid ( ), full_name TEXT, email TEXT UNIQUE, phone_e164 TEXT UNIQUE, attributes JSONB DEFAULT '{}', created_at TIMESTAMPTZ DEFAULT now ( ), merged_into UUID REFERENCES customers ( id ) ); CREATE TABLE channel_identities ( id UUID PRIMARY KEY DEFAULT gen_random_uuid ( ), customer_id UUID NOT NULL REFERENCES customers ( id ), channel TEXT NOT NULL CHECK ( channel IN ( 'whatsapp', 'instagram', 'telegram' ) ), external_id TEXT NOT NULL, verified BOOLEAN DEFAULT false, opted_in BOOLEAN DEFAULT false, last_seen_at TIMESTAMPTZ, UNIQUE ( channel, external_id ) ); CREATE TABLE events ( id BIGSERIAL PRIMARY KEY, customer_id UUID NOT NULL REFERENCES customers ( id ), channel TEXT NOT NULL, type TEXT NOT NULL, -- message_in, message_out, order, tag_added payload JSONB, occurred_at TIMESTAMPTZ DEFAULT now ( ) ); Enter fullscreen mode Exit fullscreen mode Why This Shape Works UNIQUE (channel, external_id) guarantees one identity row per platform account. merged_into lets you merge duplicates without deleting history. events is append-only, so the omnichannel customer profile is always reconstructable. Tip: Store phone numbers in E.164 format ( +8801XXXXXXXXX ) from day one. Matching 017... against +8801... is a classic source of silent duplicates.

Identity resolution is the process of deciding that two identities belong to the same human. For messaging, keep it conservative: a wrong merge (two people combined) is much worse than a missed merge.

Only auto-merge when you have a verified shared key:

When someone on Instagram or Telegram says "my WhatsApp number is...", don't merge on the spot. Verify first:

import secrets, time PENDING = { } # use Redis with a TTL in production def start_link ( customer_id: str, phone_e164: str ) -> str: code = f "{secrets.randbelow(10**6):06d}" PENDING [ ( customer_id, phone_e164 ) ] = ( code, time. time ( ) + 600 ) send_whatsapp ( phone_e164, f "Your verification code is {code}" ) return "Code sent. Please reply with it here." def confirm_link ( customer_id: str, phone_e164: str, code: str ) -> bool: entry = PENDING. get ( ( customer_id, phone_e164 ) ) if not entry or entry [ 1 ] < time. time ( ) or entry [ 0 ]!= code: return False merge_customers ( customer_id, find_customer_by_phone ( phone_e164 ) ) return True Enter fullscreen mode Exit fullscreen mode Merging Without Losing Data def merge_customers ( source_id, target_id ): with db. transaction ( ): db. execute ( "UPDATE channel_identities SET customer_id=%s WHERE customer_id=%s", ( target_id, source_id ) ) db. execute ( "UPDATE events SET customer_id=%s WHERE customer_id=%s", ( target_id, source_id ) ) db. execute ( "UPDATE customers SET merged_into=%s WHERE id=%s", ( target_id, source_id ) ) Enter fullscreen mode Exit fullscreen mode Warning: Never use display name alone as a matching key. "Ahmed Khan" is not a unique identifier.

With identities linked, the single customer view is one query:

SELECT c. id, c. full_name, c. email, jsonb_agg ( DISTINCT jsonb_build_object ( 'channel', ci. channel, 'opted_in', ci. opted_in, 'last_seen', ci. last_seen_at ) ) AS channels, ( SELECT jsonb_agg ( e ORDER BY e. occurred_at DESC ) FROM ( SELECT type, channel, occurred_at FROM events WHERE customer_id = c. id ORDER BY occurred_at DESC LIMIT 20 ) e ) AS recent_activity FROM customers c JOIN channel_identities ci ON ci. customer_id = c. id WHERE c. id = $1 AND c. merged_into IS NULL GROUP BY c. id; Enter fullscreen mode Exit fullscreen mode This is the object your inbox, your automations, and your reports should all read from. Treat it as the single source of truth for unified customer data.

Most teams need to sync data to a CRM (HubSpot, Salesforce, Zoho, or a custom one). Two rules keep it sane:

def push_to_crm ( customer ): payload = { "external_id": str ( customer [ "id" ] ), "email": customer [ "email" ], "phone": customer [ "phone_e164" ], "properties": { "channels": ",". join ( c [ "channel" ] for c in customer [ "channels" ] ) }, } crm_client. upsert_contact ( payload ) # idempotent upsert, never blind insert Enter fullscreen mode Exit fullscreen mode Use idempotent upserts and a retry queue. Webhooks arrive twice, and CRMs rate-limit.

Once you have a unified profile, the best consumer of it is an AI agent that answers customers on any channel with full context. This is where AI tool calling (also called function calling in AI ) comes in: the model doesn't query your database directly. It calls AI agent tools that you define, and you control what each tool can do.

Here is how AI agents use tools in this setup:

Good AI agent tool design is mostly about limiting blast radius. Following LLM function calling best practices:

{ "name": "get_customer_profile", "description": "Returns the current customer's name, linked channels, open orders, and last 5 interactions. Read-only.", "input_schema": { "type": "object", "properties": { "include_orders": { "type": "boolean", "default": true } }, "required": [ ] } } Enter fullscreen mode Exit fullscreen mode Notice there is no customer_id parameter. The server adds it. That one decision removes a whole class of tool calling in AI agents security problems.

Note: For anything that changes data (updating an email, requesting a link to another channel), use a separate write tool that triggers a confirmation step instead of acting immediately.

A single customer profile across WhatsApp, Instagram, and Telegram comes down to a few decisions:

If you'd rather not build all of this from scratch, platforms like Botsailor are built for omnichannel automation across WhatsApp, Instagram, and Telegram, and are worth a look as a customer data solution if you want a unified inbox without owning the plumbing.

What's your biggest challenge when linking users across channels? Drop a comment below, share this with a teammate who's fighting duplicate contacts, and follow for more posts on agentic AI and omnichannel automation.

Quelle: dev.to (dev.to). Original öffnen