Skip to main content

Installation

Get mycontext-ai installed and ready in under a minute.

Requirements

  • Python 3.11+Download Python
  • pip, uv, poetry, or conda as your package manager

Install the SDK

pip install mycontext-ai

This installs the core SDK with all 88 cognitive patterns (open source — no tiers or license keys), the full intelligence layer, quality metrics, and all 13 export formats.

To execute contexts against LLMs, install with LiteLLM — which gives you access to 100+ LLM providers through a single interface:

pip install mycontext-ai litellm

Provider-Specific Extras

Install the official SDK for your preferred provider:

# OpenAI
pip install "mycontext-ai[openai]"

# Anthropic (Claude)
pip install "mycontext-ai[anthropic]"

# Google (Gemini)
pip install "mycontext-ai[google]"

# All providers at once
pip install "mycontext-ai[all]"

What each extra includes

ExtraPackageUse case
openaiopenai>=2.0.0Direct OpenAI API usage
anthropicanthropic>=0.79.0Direct Anthropic API usage
googlegoogle-genai>=1.0.0Direct Google Gemini API usage
tokenstiktoken>=0.7.0Token counting and optimization
allAll of the aboveFull provider support
You don't need provider extras for basic usage

LiteLLM handles routing to all providers. The extras install the provider's own SDK for cases where you need direct API access.

Optional: Structured Output Parsing

Install instructor to enable JSON-mode LLM output with automatic retry on validation failure in the intelligence layer:

pip install instructor

When installed, all intelligence-layer LLM calls (suggest_patterns, generate_context, TemplateIntegratorAgent) use structured function-calling mode (~98% parse success). Without it, the SDK falls back to its Pydantic + regex parser transparently — no code changes needed.

Optional: Accurate Token Counting

For assemble_for_model() token-budget assembly and token-aware context trimming, install tiktoken:

pip install "mycontext-ai[tokens]"
# or directly:
pip install tiktoken

Without tiktoken, the SDK falls back to character-based estimation. Install [all] to get everything at once.

Orchestration Extras

If you're integrating with agent frameworks:

pip install "mycontext-ai[orchestration]"

This includes LangChain, LangGraph, CrewAI, AutoGen, and Semantic Kernel.

Development Install

To contribute to mycontext-ai or develop locally:

git clone https://github.com/SadhiraAI/mycontext.git
cd mycontext
pip install -e ".[dev]"

This installs the SDK in editable mode with pytest, mypy, ruff, black, and other dev tools.

Verify Installation

python -c "import mycontext; print(f'mycontext-ai v{mycontext.__version__} installed successfully')"

Expected output:

mycontext-ai v0.6.0 installed successfully

Command-Line Interface

The package installs a mycontext console script for working with patterns and exporting agent skills — all offline:

mycontext list                                 # list all 88 patterns
mycontext run root_cause_analyzer --generic # print a pre-authored prompt
mycontext skills export all -o ./skills # export progressive-disclosure SKILL.md packages
mycontext mcp # start the local stdio MCP server

The local MCP server requires the optional mcp extra:

pip install "mycontext-ai[mcp]"

See the CLI reference for full details.

Configure Your API Key

Set the API key for your LLM provider as an environment variable:

export OPENAI_API_KEY="sk-..."

Windows (PowerShell):

$env:OPENAI_API_KEY = "sk-..."

Or use a .env file in your project root:

.env
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=AI...
No API key needed for context building

You only need an API key when executing contexts against an LLM (ctx.execute(), smart_execute(), etc.). Building, exporting, and scoring contexts works entirely offline.

What's Included

ComponentDescription
Core SDKContext, Guidance, Directive, Constraints classes
88 Cognitive PatternsAll open source — RootCauseAnalyzer, CodeReviewer, DecisionFramework, and 85 more
CLImycontext console script — list, run, skills export, mcp
Intelligence Layertransform(), suggest_patterns(), smart_execute(), generate_context()
Async Executionctx.aexecute() — non-blocking LLM calls via litellm.acompletion
Token-Budget Assemblyctx.assemble_for_model(model, max_tokens) — tiktoken-accurate trimming
Validated Output ParsingPydantic + instructor structured parsing with automatic retry
Quality Metrics6-dimension context scoring + 5-dimension output evaluation
CAIContext Amplification Index — proves templates produce better output
13 Export FormatsOpenAI, Anthropic, Gemini, LangChain, YAML, JSON, XML, and more
7 IntegrationsLangChain, LlamaIndex, CrewAI, AutoGen, DSPy, Semantic Kernel, Google ADK

Troubleshooting

ModuleNotFoundError: No module named 'mycontext'

Make sure you installed the package (not a directory named mycontext):

pip install mycontext-ai  # ← correct
# NOT: pip install mycontext

Python version errors

mycontext-ai requires Python 3.11+. Check your version:

python --version

If you have multiple Python versions, try:

python3.11 -m pip install mycontext-ai
# or
python3.12 -m pip install mycontext-ai

LiteLLM import errors

If you see errors related to LiteLLM, install it explicitly:

pip install litellm>=1.55.0

Next: Quick Start →