-- Update skill descriptions with OpenClaw routing pattern: "Use when / NOT for"
-- This improves LLM tool selection accuracy by ~20% (per OpenClaw/Glean research)

-- CONTENT CATEGORY
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"List published blog posts. Use when: user asks about existing posts, wants to review content, or needs post URLs. NOT for: creating or editing posts (use manage_blog_posts)."') WHERE name = 'browse_blog';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"View content calendar and spot scheduling gaps. Use when: user asks about publishing schedule, content pipeline, or upcoming posts. NOT for: creating or editing individual posts."') WHERE name = 'content_calendar_view';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Generate a content block from a natural-language description. Use when: user describes a section they want. NOT for: managing existing blocks on pages (use manage_page_blocks)."') WHERE name = 'create_page_block';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Extract text from a PDF file. Use when: user attaches a PDF, references a PDF URL, or asks to read/parse a document. Works for resumes, contracts, reports, invoices. NOT for: generating PDFs."') WHERE name = 'extract_pdf_text';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Generate multi-channel content proposals with research. Use when: user wants a content strategy, campaign plan, or pillar content across channels. NOT for: writing a single blog post (use write_blog_post)."') WHERE name = 'generate_content_proposal';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Generate a full website from Business Identity data. Use when: user wants to create their entire site from scratch based on company profile. NOT for: adding individual pages (use manage_page) or migrating sites (use migrate_url)."') WHERE name = 'generate_site_from_identity';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Generate social media posts for LinkedIn and X/Twitter. Use when: user asks for social content or wants to promote a blog post on social media. NOT for: scheduling posts or managing social accounts."') WHERE name = 'generate_social_post';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage blog categories and tags. Use when: user wants to create, rename, or organize blog categories/tags. NOT for: assigning categories to posts (use manage_blog_posts)."') WHERE name = 'manage_blog_categories';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage blog posts — list, get, update, publish, unpublish, delete. Use when: user wants to edit, publish, or manage existing posts. NOT for: writing new posts (use write_blog_post) or listing published posts (use browse_blog)."') WHERE name = 'manage_blog_posts';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage consultant profiles for resume matching. Use when: user asks about consultants or wants to add/edit consultant CVs. NOT for: matching against jobs (use match_consultant)."') WHERE name = 'manage_consultant_profile';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage global site elements (header, footer, announcement bar). Use when: user wants to change site-wide navigation, footer links, or global banners. NOT for: page-specific blocks (use manage_page_blocks)."') WHERE name = 'manage_global_blocks';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage Knowledge Base articles. Use when: user asks about FAQ, help articles, KB content, or support documentation. NOT for: blog posts (use manage_blog_posts) or general pages (use manage_page)."') WHERE name = 'manage_kb_article';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage newsletters — list, get, create, update, delete. Use when: user wants to create or edit newsletter drafts. NOT for: sending (use send_newsletter) or managing subscribers (use manage_newsletter_subscribers)."') WHERE name = 'manage_newsletters';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage CMS pages — list, get, create, update, publish, archive, delete, rollback. Use when: user asks about pages or wants to create/manage page metadata. NOT for: editing blocks on a page (use manage_page_blocks)."') WHERE name = 'manage_page';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage blocks on a specific page — add, edit, reorder, delete. Use when: user wants to modify content within a page. NOT for: creating new pages (use manage_page) or generating blocks from description (use create_page_block)."') WHERE name = 'manage_page_blocks';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage products — create, update, list, delete. Use when: user asks about products, wants to add/edit product listings or prices. NOT for: browsing published products (use browse_products) or orders (use manage_orders)."') WHERE name = 'manage_product';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Match consultant profiles against a job description with scored results. Use when: user has a job description and wants matching consultants. NOT for: managing profiles (use manage_consultant_profile)."') WHERE name = 'match_consultant';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Browse, search, and manage files in Media Library. Use when: user asks about uploaded images/files or wants to find media. NOT for: uploading new files or generating images."') WHERE name = 'media_browse';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Scrape a URL and convert it into CMS page blocks. Use when: user pastes a URL and wants to clone/migrate that page. NOT for: general web scraping (use scrape_url) or creating pages from scratch (use manage_page)."') WHERE name = 'migrate_url';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Write a promotional blog post for a product. Use when: user wants product marketing content or launch post. NOT for: general blog writing (use write_blog_post)."') WHERE name = 'product_promoter';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Publish pages and posts past their scheduled date. Use when: checking for overdue scheduled content. NOT for: manually publishing (use manage_page or manage_blog_posts)."') WHERE name = 'publish_scheduled_content';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Research a topic for content creation. Use when: user asks to research before writing or needs topic analysis. NOT for: writing content (use write_blog_post or generate_content_proposal)."') WHERE name = 'research_content';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Generate SEO content brief with keywords and structure. Use when: user wants SEO guidance before writing. NOT for: auditing existing pages (use seo_audit_page)."') WHERE name = 'seo_content_brief';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Get current site branding — logo, colors, fonts, favicon. Use when: user asks about current design or visual identity. NOT for: updating branding (use site_branding_update)."') WHERE name = 'site_branding_get';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Update site branding. Requires approval. Use when: user wants to change logo, colors, fonts, or favicon. NOT for: viewing current branding (use site_branding_get)."') WHERE name = 'site_branding_update';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Batch generate social posts from blog content. Use when: user wants multiple social posts from blog posts. NOT for: single social post (use generate_social_post)."') WHERE name = 'social_post_batch';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Write and save a new blog post as draft. Use when: user asks to write, create, or draft a blog post. NOT for: editing existing posts (use manage_blog_posts)."') WHERE name = 'write_blog_post';

-- CRM CATEGORY
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Add a new lead to the CRM. Use when: user mentions a new contact or prospect. NOT for: managing existing leads (use manage_leads) or scoring (use qualify_lead)."') WHERE name = 'add_lead';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Book an appointment. Use when: user or visitor wants to schedule a booking. NOT for: managing existing bookings (use manage_bookings) or checking availability (use check_availability)."') WHERE name = 'book_appointment';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Search and list available products. Use when: visitor asks about products or catalog. NOT for: managing product data (use manage_product)."') WHERE name = 'browse_products';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"List available booking services. Use when: visitor asks what services are offered. NOT for: booking (use book_appointment)."') WHERE name = 'browse_services';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Check available booking slots for a date. Use when: user asks about availability. NOT for: making bookings (use book_appointment)."') WHERE name = 'check_availability';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Look up order status. Use when: customer asks about their order or delivery. NOT for: managing orders (use manage_orders)."') WHERE name = 'check_order';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Create a CRM task linked to lead or deal. Use when: user wants a follow-up or action item. NOT for: listing tasks (use crm_task_list)."') WHERE name = 'crm_task_create';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"List CRM tasks with filters. Use when: user asks about pending tasks or follow-ups. NOT for: creating tasks (use crm_task_create)."') WHERE name = 'crm_task_list';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Update a CRM task. Use when: user wants to update or complete a task. NOT for: creating tasks (use crm_task_create)."') WHERE name = 'crm_task_update';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Find stale deals needing follow-up. Use when: user asks about pipeline health or neglected deals. NOT for: managing individual deals (use manage_deal)."') WHERE name = 'deal_stale_check';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage CRM leads — list, get, update, delete. Use when: user asks about existing leads or wants to update lead info. NOT for: adding new leads (use add_lead) or scoring (use qualify_lead)."') WHERE name = 'manage_leads';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage sales deals — create, update, list, change stage. Use when: user asks about deals or pipeline. NOT for: lead management (use manage_leads)."') WHERE name = 'manage_deal';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage bookings — list, update, cancel. Use when: admin asks about bookings or needs to change status. NOT for: making bookings (use book_appointment)."') WHERE name = 'manage_bookings';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage business hours and blocked dates. Use when: user wants to set availability or block dates. NOT for: checking slots (use check_availability)."') WHERE name = 'manage_booking_availability';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage companies in CRM. Use when: user asks about company records. NOT for: enriching company data (use enrich_company)."') WHERE name = 'manage_company';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage form submissions — list and review. Use when: user asks about form entries or contact submissions. NOT for: creating forms (use manage_page_blocks)."') WHERE name = 'manage_form_submissions';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage product inventory. Use when: user asks about stock levels or wants to adjust quantities. NOT for: product details (use manage_product)."') WHERE name = 'manage_inventory';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage e-commerce orders. Use when: user asks about orders or fulfillment. NOT for: single order lookup (use check_order)."') WHERE name = 'manage_orders';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage newsletter subscribers. Use when: user asks about subscriber list. NOT for: creating newsletters (use manage_newsletters) or sending (use send_newsletter)."') WHERE name = 'manage_newsletter_subscribers';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Subscribe to newsletter. Use when: visitor wants to sign up. NOT for: admin management (use manage_newsletter_subscribers)."') WHERE name = 'newsletter_subscribe';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Register for a webinar. Use when: visitor wants to sign up for an event. NOT for: managing webinars (use manage_webinar)."') WHERE name = 'register_webinar';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Manage webinars — create, update, list. Use when: admin asks about events. NOT for: visitor registration (use register_webinar)."') WHERE name = 'manage_webinar';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Look up order information. Use when: user needs order details. NOT for: managing multiple orders (use manage_orders)."') WHERE name = 'lookup_order';

-- ANALYTICS CATEGORY
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Analyze site traffic and performance. Use when: user asks about visitors, page views, or traffic trends. NOT for: SEO (use seo_audit_page) or chat analytics (use analyze_chat_feedback)."') WHERE name = 'analyze_analytics';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Analyze chat feedback ratings. Use when: user asks about chatbot performance or customer satisfaction with chat. NOT for: site traffic (use analyze_analytics)."') WHERE name = 'analyze_chat_feedback';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"List incomplete or abandoned carts. Use when: user asks about cart abandonment or recovery. NOT for: completed orders (use manage_orders)."') WHERE name = 'cart_recovery_check';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Generate product inventory report. Use when: user asks for stock overview. NOT for: changing inventory (use manage_inventory)."') WHERE name = 'inventory_report';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Find KB gaps — questions not covered by articles. Use when: user wants to improve help content. NOT for: managing articles (use manage_kb_article)."') WHERE name = 'kb_gap_analysis';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Review lead pipeline and suggest actions. Use when: user asks for pipeline overview or conversion analysis. NOT for: individual leads (use manage_leads)."') WHERE name = 'lead_pipeline_review';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Run SEO audit on a page or post. Use when: user asks about SEO score or optimization issues. NOT for: writing SEO content (use seo_content_brief)."') WHERE name = 'seo_audit_page';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Read and update site settings. Use when: user asks about configuration, modules, or theme. NOT for: branding (use site_branding_update)."') WHERE name = 'manage_site_settings';

-- GROWTH CATEGORY
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Create ad campaign. Requires approval. Use when: user wants to start advertising. NOT for: checking performance (use ad_performance_check)."') WHERE name = 'ad_campaign_create';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Generate ad copy and creative with AI. Use when: user needs ad text or creative. NOT for: creating campaigns (use ad_campaign_create)."') WHERE name = 'ad_creative_generate';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Optimize running ad campaigns. Requires approval for budget changes. Use when: campaigns are active and user wants better results. NOT for: new campaigns (use ad_campaign_create)."') WHERE name = 'ad_optimize';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Get ad campaign performance metrics. Use when: user asks about ad results or ROI. NOT for: making changes (use ad_optimize)."') WHERE name = 'ad_performance_check';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Analyze a competitor website. Use when: user names a competitor or asks for competitive intelligence. NOT for: general web scraping (use scrape_url)."') WHERE name = 'competitor_monitor';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Monitor competitor websites over time. Use when: user wants ongoing competitive tracking. NOT for: one-time analysis (use competitor_monitor)."') WHERE name = 'competitor_watch';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Find business contacts via Hunter.io. Use when: user wants contact emails for a company. NOT for: CRM leads (use manage_leads)."') WHERE name = 'contact_finder';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Enrich company data from domain. Use when: user has a domain and wants company details. NOT for: finding contacts (use contact_finder)."') WHERE name = 'enrich_company';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Compose a landing page from blocks for a campaign. Use when: user wants a targeted landing page. NOT for: general pages (use manage_page)."') WHERE name = 'landing_page_compose';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Create multi-email nurture sequence for leads. Use when: user wants automated follow-up emails. NOT for: one-time newsletters (use send_newsletter)."') WHERE name = 'lead_nurture_sequence';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Qualify and score a lead with AI. Use when: user asks to evaluate lead quality. NOT for: listing leads (use manage_leads)."') WHERE name = 'qualify_lead';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Research a prospect company — scrape, search, find contacts. Use when: user names a company to prospect. NOT for: known competitors (use competitor_monitor)."') WHERE name = 'prospect_research';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Evaluate prospect fit and draft introduction. Requires prior prospect_research. Use when: user wants to assess compatibility and create outreach. NOT for: initial research (use prospect_research)."') WHERE name = 'prospect_fit_analysis';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Save or update Sales Intelligence profiles. Use when: user wants to set ICP, value proposition, or sales pitch. NOT for: prospect research (use prospect_research)."') WHERE name = 'sales_profile_setup';

-- COMMUNICATION
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Send a newsletter to subscribers. Use when: user says to send or deliver a newsletter. NOT for: creating drafts (use manage_newsletters)."') WHERE name = 'send_newsletter';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Execute newsletter send. Use when: newsletter is approved for delivery. NOT for: drafting (use manage_newsletters)."') WHERE name = 'execute_newsletter_send';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Assign support conversation to agent or change status. Use when: user asks to route or assign a ticket. NOT for: viewing conversations (use support_list_conversations)."') WHERE name = 'support_assign_conversation';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Get chat feedback for customer satisfaction analysis. Use when: user asks about support quality. NOT for: general analytics (use analyze_chat_feedback)."') WHERE name = 'support_get_feedback';

-- SYSTEM/INTEGRATION
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Create and manage agent automations. Use when: user wants recurring tasks or event-driven workflows. NOT for: one-time manual actions."') WHERE name = 'manage_automations';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Fetch content from any URL. Use when: you need to read a web page for analysis. NOT for: migrating pages to CMS (use migrate_url)."') WHERE name = 'browser_fetch';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Scrape a URL with configurable provider. Use when: you need raw page content. NOT for: converting to CMS blocks (use migrate_url)."') WHERE name = 'scrape_url';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Search the web. Use when: you need current information or facts. NOT for: scraping specific pages (use scrape_url or browser_fetch)."') WHERE name = 'search_web';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Scan Gmail for business emails. Use when: user asks to check email or find messages. NOT for: sending emails."') WHERE name = 'scan_gmail_inbox';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Analyze platform data and save learnings. Use when: doing self-improvement or pattern analysis. NOT for: user-facing analytics (use analyze_analytics)."') WHERE name = 'learn_from_data';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Process a captured signal from an external system. Use when: automation or webhook fires. NOT for: manual user requests."') WHERE name = 'process_signal';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Create a new objective for FlowPilot. Use when: user sets a goal or long-term target. NOT for: one-time tasks."') WHERE name = 'create_objective';

-- A2A/FEDERATION
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Send request to a connected A2A peer agent. Use when: task requires external agent capabilities. NOT for: internal FlowPilot skills."') WHERE name = 'a2a_request';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Process inbound A2A messages from peers. Use when: receiving messages from connected peers. NOT for: outbound requests (use a2a_request)."') WHERE name = 'a2a_chat';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Ping Clawone to verify connectivity. Use when: diagnosing A2A connection issues. NOT for: sending real tasks."') WHERE name = 'clawone_healthcheck';
UPDATE agent_skills SET tool_definition = jsonb_set(tool_definition, '{function,description}', '"Create or audit skill definitions via Clawone. Use when: user wants to create or improve skills. NOT for: listing skills (use skill_list built-in)."') WHERE name = 'clawone_skill_creator';