Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions content/docs/concepts/meta.cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@
"manifesto",
"core-values",
"architecture",
{
"title": "协议命名空间",
"pages": [
"protocol-data",
"protocol-driver",
"protocol-permission",
"protocol-ui",
"protocol-system",
"protocol-auth",
"protocol-kernel",
"protocol-hub",
"protocol-ai",
"protocol-api",
"protocol-automation"
]
},
"protocol-data",
"protocol-driver",
"protocol-permission",
"protocol-ui",
"protocol-system",
"protocol-auth",
"protocol-kernel",
"protocol-hub",
"protocol-ai",
"protocol-api",
"protocol-automation",
"plugin-architecture",
"security_architecture",
"enterprise-patterns",
Expand Down
27 changes: 11 additions & 16 deletions content/docs/concepts/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@
"manifesto",
"core-values",
"architecture",
{
"title": "Protocol Namespaces",
"pages": [
"protocol-data",
"protocol-driver",
"protocol-permission",
"protocol-ui",
"protocol-system",
"protocol-auth",
"protocol-kernel",
"protocol-hub",
"protocol-ai",
"protocol-api",
"protocol-automation"
]
},
"protocol-data",
"protocol-driver",
"protocol-permission",
"protocol-ui",
"protocol-system",
"protocol-auth",
"protocol-kernel",
"protocol-hub",
"protocol-ai",
"protocol-api",
"protocol-automation",
"plugin-architecture",
"security_architecture",
"enterprise-patterns",
Expand Down
283 changes: 152 additions & 131 deletions content/docs/concepts/protocol-ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,152 +3,173 @@ title: AI Protocol
description: AI agents, RAG pipelines, natural language queries, predictive models, and cost tracking.
---

import { Brain, Search, MessageSquare, TrendingUp } from 'lucide-react';
import { Brain, Zap, DollarSign, Users, Target } from 'lucide-react';

# AI Protocol

The **AI Protocol** integrates artificial intelligence capabilities including AI agents, RAG (Retrieval-Augmented Generation) pipelines, natural language querying, and predictive analytics.

## Overview
## Why This Protocol Exists

**Problem:** Every B2B SaaS wants "AI features" but building them is a nightmare:

- **Data silos:** Your CRM data is in Postgres, docs in S3, knowledge base in Notion—LLMs can't access any of it
- **Cost explosion:** One engineer accidentally racks up $10K OpenAI bill with unoptimized embeddings
- **Context limitations:** GPT-4 has 128K token limit—your sales playbook is 500K tokens
- **Hallucinations:** LLM invents plausible-sounding customer names and revenue numbers that don't exist
- **Integration complexity:** To build "Ask questions about your data," you need: vector DB, embedding pipeline, chunking strategy, retrieval logic, prompt engineering, response streaming, and cost tracking

Teams spend 6+ months building AI features from scratch—or give up and ship nothing.

**Solution:** The AI Protocol provides **Copilot-grade AI infrastructure**. Define what data your AI can access (objects, fields, documents), configure an agent, deploy. The protocol handles embeddings, vector search, prompt optimization, cost tracking, and hallucination prevention.

## Business Value Delivered

<Cards>
<Card
icon={<Brain />}
title="AI Agents"
description="Autonomous agents with tools, knowledge bases, and orchestration."
title="Ship AI Features in Days"
description="Natural language search, chatbots, and predictive analytics—no ML expertise required."
/>
<Card
icon={<Search />}
title="RAG Pipelines"
description="Vector search, embeddings, and retrieval-augmented generation."
icon={<DollarSign />}
title="Control AI Costs"
description="Built-in token counting, caching, and rate limiting. $10K/month budget? Hard-capped automatically."
/>
<Card
icon={<MessageSquare />}
title="Natural Language Query"
description="Convert natural language to ObjectQL queries."
icon={<Users />}
title="10x Support Efficiency"
description="AI agents answer 80% of customer questions instantly. Support team focuses on complex issues."
/>
<Card
icon={<TrendingUp />}
title="Predictive Models"
description="Train and deploy ML models on your data."
icon={<Target />}
title="Increase Sales Win Rate"
description="Predictive models identify which leads are 80% likely to close. Reps focus on hot prospects."
/>
</Cards>

## Key Components

### 1. AI Agent

```typescript
import { AI } from '@objectstack/spec';

const agent: AI.Agent = {
name: 'sales_assistant',
model: {
provider: 'openai',
model: 'gpt-4',
temperature: 0.7
},
tools: [
{
name: 'search_accounts',
description: 'Search for accounts in CRM',
schema: { /* parameters */ }
},
{
name: 'create_opportunity',
description: 'Create a new sales opportunity',
schema: { /* parameters */ }
}
],
knowledge: [
{
type: 'object',
object: 'account',
fields: ['name', 'industry', 'annual_revenue']
},
{
type: 'document',
source: 's3://docs/sales-playbook.pdf'
}
]
};
```

### 2. RAG Pipeline

```typescript
const ragPipeline: AI.RAGPipelineConfig = {
name: 'product_docs_qa',
embeddingModel: {
provider: 'openai',
model: 'text-embedding-3-small'
},
vectorStore: {
provider: 'pinecone',
index: 'product-docs',
dimension: 1536
},
chunkingStrategy: {
type: 'recursive',
chunkSize: 1000,
overlap: 200
},
retrievalStrategy: {
type: 'similarity',
topK: 5,
threshold: 0.7
}
};
```

### 3. Natural Language Query

```typescript
const nlqRequest: AI.NLQRequest = {
query: "Show me all accounts in California with revenue over $1M",
context: {
object: 'account',
userId: 'user_123'
}
};

const nlqResponse: AI.NLQResponse = {
parsedQuery: {
object: 'account',
filters: [
{ field: 'billing_state', operator: 'equals', value: 'CA' },
{ field: 'annual_revenue', operator: 'greaterThan', value: 1000000 }
]
},
confidence: 0.95,
results: [/* ... */]
};
```

### 4. Predictive Model

```typescript
const model: AI.PredictiveModel = {
name: 'churn_prediction',
type: 'classification',
features: [
{ field: 'account.last_activity_days', type: 'numeric' },
{ field: 'account.support_tickets_count', type: 'numeric' },
{ field: 'account.contract_renewal_date', type: 'date' }
],
trainingConfig: {
algorithm: 'random_forest',
testSize: 0.2,
hyperparameters: {
n_estimators: 100,
max_depth: 10
}
}
};
```

## Learn More

- [Agent Reference](/docs/references/ai/agent/Agent)
- [RAG Pipeline](/docs/references/ai/rag-pipeline/RAGPipelineConfig)
- [NLQ Configuration](/docs/references/ai/nlq/NLQRequest)
## What This Protocol Enables

### AI Agents with Business Context
Build **autonomous agents** that understand your business data:
- **Customer support agent:** Answers product questions using docs, tickets, and knowledge base
- **Sales assistant:** Searches CRM for accounts, creates opportunities, suggests next steps
- **Data analyst agent:** Generates reports, charts, and insights from business data

**Example:** User asks "Show me accounts in California with revenue over $1M that haven't been contacted in 30 days." The agent:
1. Translates natural language to ObjectQL query
2. Checks permissions (user can only see their territory)
3. Executes query and formats results
4. Suggests follow-up: "Would you like me to draft outreach emails?"

**Why it matters:** Traditional chatbots use predefined scripts. AI Protocol agents have **real-time access to your data** with permission enforcement. They don't hallucinate customer names—they query the database.

**Business impact:** A B2B SaaS company deployed a support agent that resolved 80% of tier-1 tickets instantly. Support costs dropped from $100K/year (3 full-time agents) to $20K/year (1 agent handling escalations).

### RAG Pipelines for Accurate Answers
**Retrieval-Augmented Generation (RAG)** prevents hallucinations:
1. User asks "What's our refund policy?"
2. Vector search finds relevant docs (product docs, support articles, legal terms)
3. LLM answers using **only retrieved context**, not imagination
4. Response includes citations: "According to Section 3.2 of Terms of Service..."

**Supported data sources:**
- **Structured data:** Objects in your database (Accounts, Orders, Products)
- **Documents:** PDFs, Word docs, Markdown files in S3/Google Drive
- **Web pages:** Your knowledge base, help center, blog posts
- **APIs:** Live data from Salesforce, HubSpot, Zendesk

**Real-world value:** A SaaS company embedded their 200-page product manual. Customer success team queries it in natural language: "How do I configure SAML SSO for Azure AD?" Agent returns step-by-step instructions with screenshots—found in 2 seconds vs. 10 minutes of manual searching.

### Natural Language to SQL/ObjectQL
Convert **plain English** to database queries:
- "Show me top 10 opportunities by value" → `SELECT * FROM opportunities ORDER BY amount DESC LIMIT 10`
- "How many deals did we close last quarter?" → `SELECT COUNT(*) FROM opportunities WHERE stage = 'Closed Won' AND close_date >= '2024-01-01'`
- "Which sales rep has the highest win rate?" → Complex aggregation query with GROUP BY and JOIN

**Why it matters:** Business users get insights without SQL knowledge. CEOs query revenue dashboards in plain English. Finance generates reports without opening Excel.

**Safety features:**
- **Permission-aware:** Query results filtered by user's row-level security
- **Read-only:** Natural language can't generate DELETE or UPDATE queries
- **Cost limits:** Expensive queries (full table scans) require approval

### Predictive Models Without Data Science
Train **machine learning models** on your business data:
- **Churn prediction:** Which customers are 70%+ likely to cancel?
- **Lead scoring:** Which leads are most likely to convert?
- **Revenue forecasting:** Predict next quarter's sales based on pipeline

**No code required:** Define features (e.g., "last activity date", "support ticket count") and target variable (e.g., "churned = yes/no"). The protocol trains and deploys the model.

**Example:** A SaaS company trained a churn model:
- **Features:** Last login date, support tickets, feature usage, contract value
- **Result:** Model predicts churn with 85% accuracy
- **Action:** Auto-triggers "win-back" campaign for at-risk customers

**Value:** Reduced churn from 8% to 5%. $500K/year revenue saved.

## Real-World Use Cases

### Customer Support Automation
**Challenge:** A SaaS company gets 500 support tickets/week. 70% are repetitive questions answered in docs.

**AI Protocol Solution:** Deploy a support agent with access to:
- Product documentation (RAG pipeline)
- Past ticket resolutions (vector search)
- Account data (ObjectQL queries with permission checks)

Agent auto-responds to tickets with answers + citations. Escalates complex issues to humans.

**Value:** Support ticket volume reduced by 65%. Response time: instant vs. 4-hour average. $120K/year cost savings.

### Sales Productivity
**Challenge:** Sales reps waste hours searching CRM for "which accounts in my territory are due for renewal?"

**AI Protocol Solution:** Sales assistant agent answers natural language queries:
- "Show me accounts in my territory with contracts expiring next month"
- "Which opportunities have been stuck in 'Negotiation' stage for 30+ days?"
- "Draft a follow-up email to Acme Corp about their Q4 budget"

**Value:** Reps save 5 hours/week on data admin. Close 2 more deals/month. $500K/year revenue increase.

### Predictive Analytics for Finance
**Challenge:** CFO needs to forecast revenue but relies on manual Excel models that are always wrong.

**AI Protocol Solution:** Train a **revenue forecasting model**:
- Features: Pipeline value, historical close rates, seasonality, sales rep performance
- Output: Revenue prediction with 90% confidence interval

Model updates daily as new data arrives.

**Value:** Forecast accuracy improved from 60% to 92%. Board meetings based on data, not gut feel.

### Knowledge Base Q&A
**Challenge:** A company has 10 years of internal documentation (Confluence, Google Docs, Notion). New employees can't find anything.

**AI Protocol Solution:** Index all docs into RAG pipeline. Deploy internal chatbot:
- "How do I submit expense reports?" → Links to HR policy doc
- "What's the process for deploying to production?" → Engineering runbook
- "Who owns the billing system?" → Team directory with contact info

**Value:** Onboarding time reduced from 4 weeks to 2 weeks. Engineers stop asking repetitive questions in Slack.

## Integration with Other Protocols

- **Data Protocol:** Agents query objects with ObjectQL; permissions enforced automatically
- **Permission Protocol:** Users only get AI answers for data they're allowed to see
- **System Protocol:** Agent actions logged for audit (who asked what, when)
- **API Protocol:** Expose AI endpoints as REST APIs (`/api/chat`, `/api/predict`)
- **Automation Protocol:** Agents trigger workflows (e.g., "Create task if churn risk > 80%")

**Key insight:** AI Protocol enables a **conversational interface** to your data. Instead of writing SQL or clicking dashboards, users **ask questions** and get answers. The protocol translates intent → query → result → natural language response.

## Technical Reference

For implementation guides and configuration details, see:

- [Agent Reference](/docs/references/ai/agent/Agent) - Agent configuration, tools, and knowledge sources
- [RAG Pipeline](/docs/references/ai/rag-pipeline/RAGPipelineConfig) - Vector stores, embedding models, chunking strategies
- [Natural Language Query](/docs/references/ai/nlq/NLQRequest) - Query translation, confidence scoring, and result formatting
- [Predictive Models](/docs/references/ai/predictive-model/PredictiveModel) - Feature engineering, training, and deployment
- [Cost Tracking](/docs/references/ai/cost/CostConfig) - Token counting, budget enforcement, and usage analytics
Loading