一键导入
ktx-ai-data-agents-context-layer
Use ktx to give AI agents accurate data warehouse querying through semantic layers, metrics, and business knowledge via MCP
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use ktx to give AI agents accurate data warehouse querying through semantic layers, metrics, and business knowledge via MCP
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Train and deploy Qwen-AgentWorld, a native language world model that simulates agentic environments across 7 domains (MCP, Search, Terminal, SWE, Android, Web, OS) for agent training and evaluation.
Build and orchestrate collaborative multi-agent teams using HiClaw's Manager-Workers architecture on Matrix with Kubernetes-native control.
Set up and manage collaborative multi-agent teams using HiClaw, a Kubernetes-native platform with Matrix rooms for human-in-the-loop AI coordination
Build and orchestrate collaborative multi-agent teams using HiClaw's Manager-Workers architecture with Matrix rooms, MCP servers, and Kubernetes-native deployment.
Deploy and orchestrate collaborative multi-agent teams using HiClaw's Manager-Workers architecture on Docker or Kubernetes with Matrix rooms for human oversight
Use Agent Apprenticeship to train AI agents through real-world tasks, reusable experience, and ecosystem learning signals
| name | ktx-ai-data-agents-context-layer |
| description | Use ktx to give AI agents accurate data warehouse querying through semantic layers, metrics, and business knowledge via MCP |
| triggers | ["set up ktx for data agent querying","configure ktx semantic layer for warehouse","use ktx to query data with approved metrics","integrate ktx with Claude Code for analytics","build context in ktx from dbt and warehouse","search ktx semantic layer and wiki","configure ktx MCP server for agents","ingest warehouse metadata into ktx"] |
Skill by ara.so — AI Agent Skills collection.
ktx is a self-improving context layer that teaches AI agents how to query data warehouses accurately using approved metric definitions, joinable columns, and business knowledge. It ingests metadata from dbt, LookML, Looker, Metabase, Notion, and raw warehouse tables, then exposes this context through CLI and MCP tools for AI agents to use.
npm install -g @kaelio/ktx
npm install --save-dev @kaelio/ktx
ktx setup
The setup wizard:
my-project/
├── ktx.yaml # Project configuration
├── semantic-layer/<connection-id>/ # YAML semantic sources
├── wiki/global/ # Shared business context
├── wiki/user/<user-id>/ # User-scoped notes
├── raw-sources/<connection-id>/ # Ingest artifacts and reports
└── .ktx/ # Local state and secrets (git-ignored)
version: 1
llm:
provider: anthropic
model: claude-sonnet-4-6
embeddings:
provider: openai
model: text-embedding-3-small
connections:
warehouse:
type: postgresql
host: localhost
port: 5432
database: analytics
schema: public
user: readonly_user
ssl: true
context_sources:
dbt_main:
type: dbt
path: ./dbt
connection: warehouse
looker_main:
type: looker
project_id: my_project
connection: warehouse
# LLM Provider
export ANTHROPIC_API_KEY=sk-ant-...
# or
export GOOGLE_VERTEX_PROJECT_ID=my-project
export GOOGLE_VERTEX_LOCATION=us-central1
# Embeddings Provider
export OPENAI_API_KEY=sk-...
# Database credentials (if not in ktx.yaml)
export WAREHOUSE_PASSWORD=...
export SNOWFLAKE_ACCOUNT=...
export BIGQUERY_CREDENTIALS_PATH=/path/to/service-account.json
ktx status
Example output:
ktx project: /home/user/analytics
Project ready: yes
LLM ready: yes (claude-sonnet-4-6)
Embeddings ready: yes (text-embedding-3-small)
Databases configured: yes (warehouse)
Context sources configured: yes (dbt_main)
ktx context built: yes
Agent integration ready: yes (codex:project)
Ingest metadata from all configured sources:
ktx ingest
Ingest from specific connection:
ktx ingest --connection warehouse
Force re-ingestion:
ktx ingest --force
ktx sl "revenue"
ktx sl "monthly active users"
ktx sl "customer churn rate"
Returns metric definitions, measures, dimensions, and their SQL.
ktx wiki "refund policy"
ktx wiki "how to calculate ARR"
ktx wiki "data quality issues"
Returns relevant wiki pages from global and user-scoped knowledge.
Start the MCP server for AI agent clients:
ktx mcp start
With custom project directory:
ktx mcp start --project-dir /path/to/project
The MCP server exposes tools for agents:
ktx_search_semantic_layer — search metrics and dimensionsktx_search_wiki — search business knowledgektx_get_metric — fetch full metric definitionktx_list_connections — list available data sourcesFrom your project directory, tell Claude Code:
Run npx skills add Kaelio/ktx --skill ktx and use the ktx skill to install and configure ktx in this project.
ktx auto-detects and integrates with Codex projects. After ktx setup, the MCP server is registered in .codex/mcp.json.
Add to your Cursor MCP settings:
{
"mcpServers": {
"ktx": {
"command": "ktx",
"args": ["mcp", "start", "--project-dir", "/absolute/path/to/project"]
}
}
}
# Create project directory
mkdir my-analytics-project
cd my-analytics-project
# Initialize ktx
ktx setup
# Follow prompts to:
# 1. Configure LLM (Anthropic, Google Vertex, or AI Gateway)
# 2. Configure embeddings (OpenAI, Google, or AI Gateway)
# 3. Add warehouse connection (PostgreSQL, Snowflake, BigQuery, etc.)
# 4. Add context sources (dbt, Looker, Metabase, Notion)
# 5. Build initial context
# Verify setup
ktx status
# Start MCP server for agents
ktx mcp start
// ktx.yaml
connections:
warehouse:
type: postgresql
host: localhost
database: analytics
context_sources:
dbt_main:
type: dbt
path: ./dbt // Path to dbt project with manifest.json
connection: warehouse
# Ingest dbt metadata
ktx ingest --connection warehouse
# ktx.yaml
context_sources:
looker_main:
type: looker
project_id: my_project
connection: warehouse
# ktx will parse LookML files for views, explores, dimensions, measures
import { exec } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);
async function searchMetrics(query: string): Promise<string> {
const { stdout } = await execAsync(`ktx sl "${query}"`);
return stdout;
}
async function searchWiki(query: string): Promise<string> {
const { stdout } = await execAsync(`ktx wiki "${query}"`);
return stdout;
}
// Example usage
const revenueMetrics = await searchMetrics('revenue');
const refundPolicy = await searchWiki('refund policy');
ktx auto-generates semantic sources, but you can also define them manually:
# semantic-layer/warehouse/revenue.yaml
version: 1
sources:
- name: monthly_revenue
description: Total revenue by month
base_table: analytics.fact_orders
dimensions:
- name: month
type: time
sql: "DATE_TRUNC('month', order_date)"
measures:
- name: revenue
type: sum
sql: "amount"
description: Sum of all order amounts
metrics:
- name: total_revenue
type: simple
measure: revenue
description: Total revenue across all orders
Create markdown files in wiki/global/:
# wiki/global/refund-policy.md
---
title: Refund Policy
tags: [policy, finance]
---
# Refund Policy
Customers can request refunds within 30 days of purchase.
Refunds are processed within 5-7 business days.
## Revenue Impact
Refunds are subtracted from gross revenue to calculate net revenue.
See the `net_revenue` metric in the semantic layer.
ktx ingests and indexes these for semantic search.
# ktx.yaml
connections:
prod_warehouse:
type: snowflake
account: xy12345.us-east-1
warehouse: COMPUTE_WH
database: ANALYTICS_PROD
schema: PUBLIC
dev_warehouse:
type: postgresql
host: localhost
database: analytics_dev
context_sources:
dbt_prod:
type: dbt
path: ./dbt
connection: prod_warehouse
dbt_dev:
type: dbt
path: ./dbt
connection: dev_warehouse
# Ingest from specific warehouse
ktx ingest --connection prod_warehouse
ktx ingest --connection dev_warehouse
# Re-run setup wizard
ktx setup
# Or manually create ktx.yaml
touch ktx.yaml
Ensure API keys are set:
export ANTHROPIC_API_KEY=sk-ant-...
# or
export GOOGLE_VERTEX_PROJECT_ID=my-project
export GOOGLE_VERTEX_LOCATION=us-central1
ktx status
Add at least one context source in ktx.yaml:
context_sources:
dbt_main:
type: dbt
path: ./dbt
connection: warehouse
Check credentials and network access:
# Test PostgreSQL connection
psql -h localhost -U readonly_user -d analytics
# Test Snowflake connection
snowsql -a xy12345.us-east-1 -u readonly_user -d ANALYTICS
# ktx uses read-only operations only
Ensure project is properly configured:
ktx status
# All checks should be "yes"
# If agent integration shows "no", re-run setup
ktx setup
Limit table sampling:
# ktx.yaml
connections:
warehouse:
type: postgresql
# ... connection details
sample_limit: 100 # Limit rows sampled per table
skip_tables:
- logs_*
- temp_*
Rebuild embeddings:
ktx ingest --force
Verify embeddings provider is configured:
export OPENAI_API_KEY=sk-...
ktx status
Ensure MCP server is running:
ktx mcp start --project-dir /absolute/path/to/project
For Codex/Claude Code, verify .codex/mcp.json or equivalent config exists.
# ktx.yaml
llm:
provider: ai_gateway
endpoint: https://gateway.example.com/v1
model: claude-sonnet-4
export AI_GATEWAY_API_KEY=...
from ktx_sl import SemanticLayerEngine
engine = SemanticLayerEngine(project_dir="/path/to/project")
# Query metrics
results = engine.query_metric(
metric_name="total_revenue",
dimensions=["month"],
filters={"year": 2024}
)
export KTX_TELEMETRY_DISABLED=1
Or in ktx.yaml:
telemetry:
enabled: false
ktx ingest regularly or after schema changes