claw-integration-design
Bot/Agent Integration Design (Claw)
This skill provides guidelines and patterns for integrating web applications (SaaS/internal tools/products) with external bots and agent systems (e.g., OpenAI tool-calling, LangChain, OpenClaw). The goal is to allow agents to securely connect, read, and write data without turning the application itself into a bot.
Phase 1: Host Application Analysis
Adapt the integration to the project's existing domain model.
- Analyze the Application: Review
schema.prisma,models/, OpenAPI specs, or route definitions to understand the core resources (e.g.,orders,products,leads). - Select Exposure Targets: Decide which specific entities the agent actually needs access to for the task at hand.
Core Architectural Concepts
When building agent integrations based on your discovery, implement these foundational concepts:
1. Multi-Tenant Context
All read/write operations MUST be scoped to a specific tenant/workspace:
- Rule: Always require
tenant_id,org_id, orworkspace_idin requests (via header, path, or body).
2. Domain-Specific Resource Model
Design endpoints that match the discovered entities exactly. Agents should write data directly to where it belongs:
- Do NOT use a generic
/itemsendpoint unless the application itself is a generic CMS. - Do: Use specific, pluralized endpoints based on the domain (e.g.,
/v1/invoices,/v1/leads,/v1/candidates).
Authentication and Authorization
Authentication Methods
- MVP Validation: Use API Keys passed via the
Authorization: Bearer <API_KEY>header. - Production Standard: Use OAuth2 (Authorization Code + PKCE) for integrations with third-party agent providers.
Scope / Permission Model (CRITICAL)
You MUST enforce a granular scope model based on the discovered resources using the {action}:{resource} pattern. Do not give agents root access.
Standard Scopes (Generic Examples):
read:{resource}: Read access to a specific resource (e.g.,read:invoices).write:{resource}: Access to create/update resources (e.g.,write:leads).admin:audit: Access to read audit logs.
High-Risk Scopes:
- Rule: Isolate riskier operations behind specific scopes, default off.
write:{resource}:delete: Permission to delete items (e.g.,write:invoices:delete).write:{resource}:bulk: Permission for bulk modifications.
Standard HTTP Guidelines
Enforce these standards on all agent-facing endpoints:
- Base Path:
/v1(e.g.,https://<domain>/v1) - Content-Type:
application/json - Rate Limiting: Implement rate limits (e.g., 60 req/min per key/token).
- Idempotency: Require an
Idempotency-Keyheader (UUID) for allPOST(create) endpoints. - Agent Traceability: Suggest headers like
X-Agent-Name(e.g.,openclaw,langchain) andX-Trace-Idfor log correlation.
Standard API Endpoints
When setting up the API, implement these minimal required endpoints dynamically based on Phase 1 discovery.
1. Health and Meta
GET /v1/health: Returns{ "status": "ok", "version": "0.1.0" }.GET /v1/openapi.json: Serve the OpenAPI spec so agents can auto-generate tools.
2. Exposed Resources (CRUD)
For every entity you decided to expose in Phase 1 (e.g., invoices):
- List:
GET /v1/{resource}?tenant_id=...&status=open(Scope:read:{resource}) - Read:
GET /v1/{resource}/{id}(Scope:read:{resource}) - Create:
POST /v1/{resource}(Scope:write:{resource}, requireIdempotency-Key) - Update:
PATCH /v1/{resource}/{id}(Scope:write:{resource}) - Delete:
DELETE /v1/{resource}/{id}(Requires specialized scopewrite:{resource}:delete)
3. Search (Crucial for Agents)
- Endpoint:
GET /v1/search?tenant_id=...&q=...&types={resource1},{resource2} - MVP: SQL Full-Text Search (PostgreSQL
tsvector, SQLite FTS5). - V2 — Semantic Search: Use embedding models (e.g.,
text-embedding-3-smallfrom OpenAI, ornomic-embed-textlocally) to generate vectors, stored in a vector DB:- Managed: Pinecone, Weaviate, Qdrant Cloud
- Self-hosted / Postgres-native:
pgvectorextension (lowest ops overhead for most projects) - Endpoint:
POST /v1/semantic-search { text, types, limit, threshold } - When to use V2: When keyword search fails for paraphrased queries or conceptually similar content.
See
references/oauth2-flow.mdfor auth setup andassets/tools-manifest-template.jsonfor a ready-to-use manifest.
4. Links (Relationships)
If the domain model is highly relational (e.g., an invoice belongs to a customer):
- Endpoint:
POST /v1/links - Scope:
write:links - Payload:
tenant_id,from_id,to_id,relation(e.g.,belongs_to).
5. Audit Logging
- Endpoint:
GET /v1/audit - Scope:
admin:audit - Keep a detailed log of actor (
agent_name), action (e.g.,create_invoice), target, andtrace_id.
Standard Error Formatting
Always return errors in this consistent format for predictability:
{
"error": {
"code": "insufficient_scope",
"message": "write:invoices scope required",
"details": { "required": ["write:invoices"] }
}
}
Common codes: unauthorized, insufficient_scope, not_found, validation_error, rate_limited, conflict, internal_error.
Agent Manifest (tools.json)
When requested to build a tool manifest for an agent framework, use the ready-to-use template at:
assets/tools-manifest-template.json
The template includes definitions for search_[RESOURCE_NAME]s, create_[RESOURCE_NAME], update_[RESOURCE_NAME], and create_link. Replace <your-domain> with the actual API base URL.
Key manifest conventions:
- Use
"type": "bearer"for auth - Always include
tenant_idas a required field in every tool'sinput_schema - Keep
descriptionfields agent-friendly — they guide LLM tool selection
Internal Data Tracking
Every record/capture created by an agent MUST trace back to its origin. Add these fields to database schemas:
source: Should indicateagent(vshuman).agent_name: Identifying name of the bot.trace_id: For request correlation.metadata: Flexible JSON column for arbitrary agent state/data.
More from fatih-developer/fth-skills
task-decomposer
Break down large, complex, or ambiguous tasks into independent subtasks with dependency maps, execution order, and success criteria. Plan first, then execute step by step. Triggers on 'how should I do this', 'where do I start', 'plan the project', 'break it down', 'implement' or whenever a task involves multiple phases.
24context-compressor
Compress long conversation histories, large code files, research results, and documents by 70% without losing critical information. Triggers when context window fills up, when summarizing previous steps in multi-step tasks, before loading large files into context, or on 'summarize', 'compress', 'reduce context', 'save tokens'.
18multi-brain-debate
Two-round debate protocol where perspectives challenge each other before consensus. Round 1 presents independent positions, Round 2 allows counter-arguments and rebuttals. Produces battle-tested decisions for high-stakes choices.
17multi-brain-score
Confidence scoring overlay for multi-brain decisions. Each perspective rates its own confidence (1-10) with justification. Consensus uses scores as weights, flags low-confidence areas, and surfaces uncertainty explicitly.
15checkpoint-guardian
Automatic risk assessment before every critical action in agentic workflows. Detects irreversible operations (file deletion, database writes, deployments, payments), classifies risk level, and requires confirmation before proceeding. Triggers on destructive keywords like deploy, delete, send, publish, update database, process payment.
14parallel-planner
Analyze multi-step tasks to identify which steps can run in parallel, build dependency graphs, detect conflicts (write-write, read-write, resource contention), and produce optimized execution plans. Triggers on 3+ independent steps, 'speed up', 'run simultaneously', 'parallelize', 'optimize' or any task where sequential execution wastes time.
14