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
93 changes: 78 additions & 15 deletions kalibr/cli/prompt_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@

1. pip install kalibr huggingface_hub

2. kalibr auth --agent --email <YOUR_EMAIL>
2. kalibr signup <YOUR_EMAIL>
(Creates your Kalibr account. Credentials saved to .env immediately.)

3. Source credentials into shell:
- If ~/.zshrc exists: append KALIBR_API_KEY and KALIBR_TENANT_ID exports
- Else if ~/.bashrc exists: append to ~/.bashrc
- Run: source ~/.zshrc (or ~/.bashrc)
export $(grep -v '^#' .env | xargs)
To persist across sessions, append to ~/.zshrc:
grep 'KALIBR_API_KEY\\|KALIBR_TENANT_ID' .env >> ~/.zshrc
source ~/.zshrc

4. openclaw plugin install kalibr && openclaw plugin configure kalibr
4. openclaw plugins install @kalibr/openclaw
openclaw config set plugins.entries.kalibr.config.apiKey "$KALIBR_API_KEY"
openclaw config set plugins.entries.kalibr.config.tenantId "$KALIBR_TENANT_ID"
openclaw config set plugins.entries.kalibr.config.enableRouting true
openclaw gateway restart

5. Create ~/clawd workspace scaffold:
- ~/clawd/SOUL.md — ask the user: "What does your agent do in one sentence?"
Expand All @@ -41,11 +47,62 @@
- ~/clawd/AGENTS.md — write a routing table:
# AGENTS.md\\n\\n## Routing Table\\n\\n| Task Type | Load | Route |\\n|-----------|------|-------|\\n| code_generation / code_review / system_design | high | Sonnet → GPT-4o |\\n| research / outreach_generation | medium | Llama → DeepSeek |\\n| web_scraping / classification / summarization / data_pipeline | low | DeepSeek → Llama |

6. Create ~/clawd/kalibr-integration/ directory and download pipeline files:
- https://raw.githubusercontent.com/kalibr-ai/kalibr-sdk-python/main/examples/kalibr_pipeline.py
- https://raw.githubusercontent.com/kalibr-ai/kalibr-sdk-python/main/examples/kalibr_taxonomy.py
- https://raw.githubusercontent.com/kalibr-ai/kalibr-sdk-python/main/examples/kalibr_eval.py
- Create an empty ~/clawd/kalibr-integration/__init__.py
6. Create ~/clawd/kalibr-integration/ directory and write these files:

Create ~/clawd/kalibr-integration/__init__.py (empty file)

Create ~/clawd/kalibr-integration/kalibr_pipeline.py with this content:
"""
OPENCLAW_PIPELINE_FILE = '''"""Kalibr pipeline integration — classify and route tasks."""
import os
from kalibr import Router


def classify_and_route(task: str, context: dict = None) -> dict:
"""Classify a task and route it through Kalibr."""
goal_id = classify_task(task)
router = Router(goal=goal_id, paths=get_paths_for_goal(goal_id))
result = router.completion(messages=[{"role": "user", "content": task}])
return {"goal": goal_id, "result": result.choices[0].message.content}


def classify_task(task: str) -> str:
"""Classify a task string to a Kalibr goal_id."""
t = task.lower()
if any(w in t for w in ["scrape", "extract from url", "fetch page"]): return "web_scraping"
if any(w in t for w in ["enrich", "fill in", "lookup missing"]): return "data_enrichment"
if any(w in t for w in ["score lead", "lead score", "rate prospect"]): return "lead_scoring"
if any(w in t for w in ["classify", "categorize", "label"]): return "classification"
if any(w in t for w in ["summarize", "summary", "tldr"]): return "summarization"
if any(w in t for w in ["pipeline", "transform data", "process rows"]): return "data_pipeline"
if any(w in t for w in ["research", "investigate", "analyze market"]): return "research"
if any(w in t for w in ["draft email", "cold email", "outreach", "write message"]): return "outreach_generation"
if any(w in t for w in ["write code", "implement", "build function", "create script"]): return "code_generation"
if any(w in t for w in ["review code", "code review", "check this code"]): return "code_review"
if any(w in t for w in ["design system", "architecture", "system design"]): return "system_design"
return "research"


def get_paths_for_goal(goal_id: str) -> list:
"""Return default model paths for a goal_id."""
paths = {
"web_scraping": ["deepseek-chat", "meta-llama/Llama-3.3-70B-Instruct", "mistralai/Mixtral-8x7B-Instruct-v0.1", "gpt-4o-mini"],
"data_enrichment": ["deepseek-chat", "meta-llama/Llama-3.3-70B-Instruct", "Qwen/Qwen2.5-72B-Instruct", "gpt-4o-mini"],
"lead_scoring": ["deepseek-chat", "meta-llama/Llama-3.3-70B-Instruct", "mistralai/Mixtral-8x7B-Instruct-v0.1", "gpt-4o-mini"],
"classification": ["deepseek-chat", "meta-llama/Llama-3.3-70B-Instruct", "Qwen/Qwen2.5-72B-Instruct", "gpt-4o-mini"],
"summarization": ["deepseek-chat", "meta-llama/Llama-3.3-70B-Instruct", "mistralai/Mixtral-8x7B-Instruct-v0.1", "claude-haiku-3-5-20241022"],
"data_pipeline": ["deepseek-chat", "meta-llama/Llama-3.3-70B-Instruct", "Qwen/Qwen2.5-72B-Instruct", "gpt-4o-mini"],
"research": ["meta-llama/Llama-3.3-70B-Instruct", "deepseek-chat", "deepseek-reasoner", "claude-sonnet-4-20250514"],
"outreach_generation": ["meta-llama/Llama-3.3-70B-Instruct", "deepseek-chat", "mistralai/Mixtral-8x22B-Instruct-v0.1", "claude-sonnet-4-20250514"],
"code_generation": ["claude-sonnet-4-20250514", "gpt-4o", "o3-mini", "deepseek-reasoner"],
"code_review": ["claude-sonnet-4-20250514", "gpt-4o", "deepseek-reasoner", "o3-mini"],
"system_design": ["claude-sonnet-4-20250514", "deepseek-reasoner", "gpt-4o", "o3-mini"],
"agent_orchestration": ["claude-sonnet-4-20250514", "gpt-4o", "deepseek-reasoner", "o3-mini"],
}
return paths.get(goal_id, paths["research"])
'''

OPENCLAW_PROMPT_TEXT_PART2 = """\

7. kalibr init && kalibr verify

Expand All @@ -57,11 +114,17 @@
9. Report done:
- Print: "✅ Kalibr + OpenClaw setup complete."
- Print: "Dashboard: https://dashboard.kalibr.systems"
- Print the claim email confirmation URL returned by `kalibr auth --agent`
- Print the claim_url returned by kalibr signup (the human uses it to access the dashboard)
- Ask: "Do you have any provider API keys to add? (OPENAI_API_KEY, ANTHROPIC_API_KEY, DEEPSEEK_API_KEY, HF_TOKEN)"
If yes, append them to ~/.zshrc and source it.
"""

OPENCLAW_FULL_PROMPT = (
OPENCLAW_PROMPT_TEXT
+ OPENCLAW_PIPELINE_FILE
+ OPENCLAW_PROMPT_TEXT_PART2
)


def prompt(
openclaw: bool = typer.Option(
Expand All @@ -82,12 +145,12 @@ def prompt(
"""
if openclaw:
if email:
text = OPENCLAW_PROMPT_TEXT.replace(
"kalibr auth --agent --email <YOUR_EMAIL>",
f"kalibr auth --agent --email {email}",
text = OPENCLAW_FULL_PROMPT.replace(
"kalibr signup <YOUR_EMAIL>",
f"kalibr signup {email}",
)
else:
text = OPENCLAW_PROMPT_TEXT
text = OPENCLAW_FULL_PROMPT
else:
text = PROMPT_TEXT

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "kalibr"
version = "1.9.7"
version = "1.9.8"
description = "Outcome-aware LLM routing for production AI agents. Routes between models, tools, and parameters based on real success signals using Thompson Sampling. Automatic fallback, cost optimization, and continuous learning — no redeploy required."
authors = [{name = "Kalibr Team", email = "support@kalibr.systems"}]
readme = "README.md"
Expand Down
Loading