Skip to main content

Universal Context Transformation Engine - Transform questions into perfect, portable contexts

Project description

mycontext

Transform any question into perfect context - use it anywhere

PyPI Python License: MIT Tests codecov

What is mycontext?

mycontext is the universal context transformation engine for AI applications.

The Problem: Raw questions and unstructured prompts lead to inconsistent AI behavior, context rot, and wasted tokens.

The Solution: Transform questions into perfect, portable contexts that work with ANY AI system.

from mycontext.templates.free import QuestionAnalyzer

# Step 1: Transform raw question into perfect context
question = "Should I invest in solar panels?"
analyzer = QuestionAnalyzer()

# This creates a structured, optimized context
context = analyzer.build_context(
    question=question,
    context="Home: 2000 sqft, California, $200/month bill",
    depth="comprehensive"
)

# Step 2: Use this context ANYWHERE!

# Option A: LangGraph
langgraph_agent.invoke(context.to_langchain())

# Option B: CrewAI  
crew.kickoff(context=context.to_dict())

# Option C: Direct OpenAI
openai.chat.completions.create(messages=context.to_messages())

# Option D: Any framework via JSON
requests.post(api_url, json=context.to_json())

# Option E: Even humans can read it!
print(context.to_markdown())

One transformation โ†’ Infinite uses

Why mycontext?

๐ŸŽฏ The Core Insight

Your questions need transformation, not just prompting.

โŒ Old Way: Raw Question โ†’ LLM
   "Should I invest in solar panels?"
   โ†’ Inconsistent, shallow responses

โœ… New Way: Raw Question โ†’ mycontext โ†’ Perfect Context โ†’ LLM
   "Should I invest in solar panels?"
   โ†’ Structured analysis framework
   โ†’ Decision criteria
   โ†’ Evidence requirements
   โ†’ Financial calculations
   โ†’ Risk assessment
   = Consistent, thorough, high-quality responses

๐Ÿ’ก What Makes mycontext Unique?

  1. Universal Transformation Engine

    • Input: Raw questions/tasks
    • Process: Research-backed templates + RAG + optimization
    • Output: Perfect, portable contexts
  2. Works with EVERYTHING

    • โœ… LangGraph, CrewAI, AutoGen (agent frameworks)
    • โœ… LangChain, LlamaIndex, Haystack (RAG frameworks)
    • โœ… OpenAI, Anthropic, Google (direct LLM APIs)
    • โœ… OpenCE (context engineering backends)
    • โœ… Custom APIs, internal tools
    • โœ… Even human analysts!
  3. Research-Backed Templates

    • Based on "Context Engineering" book (IBM Zurich Research)
    • Cognitive tools from scientific research
    • Not hand-crafted prompts - engineered systems
  4. Three User Levels

    • General users: Use templates (no coding)
    • Professionals: Customize patterns (light Python)
    • Developers: Build production systems (full SDK)
  5. API-Ready Architecture

    • Universal export formats (JSON, messages, markdown)
    • RESTful API coming soon
    • Cloud platform in development

๐Ÿš€ Quick Start

Installation

# Core SDK
pip install mycontext

# With OpenAI
pip install mycontext[openai]

# With all providers (OpenAI, Anthropic, Google)
pip install mycontext[all]

30-Second Example

from mycontext.templates.free import QuestionAnalyzer

# Transform question into perfect context
analyzer = QuestionAnalyzer()
context = analyzer.build_context(
    question="Should I invest in solar panels?",
    context="California home, $200/mo electric bill"
)

# Use it anywhere!
# โ†’ Export for OpenAI
messages = context.to_messages()

# โ†’ Export for LangGraph
langchain_format = context.to_langchain()

# โ†’ Export as JSON for API
json_data = context.to_json()

# โ†’ Show to humans
print(context.to_markdown())

That's it! One transformation โ†’ Use anywhere.

๐ŸŽฏ Core Features

1. Universal Context Transformation

Transform raw questions into structured, optimized contexts:

from mycontext import Context, Guidance, Directive

# Build a perfect context
context = Context(
    guidance=Guidance(
        role="Expert Financial Advisor",
        rules=[
            "Provide evidence-based analysis",
            "Consider risk factors",
            "Include calculations"
        ],
        style="analytical, balanced"
    ),
    directive=Directive("Should I invest in solar panels?")
)

# Export to any format
context.to_messages()      # โ†’ OpenAI, Anthropic, Google
context.to_langchain()     # โ†’ LangChain, LangGraph
context.to_json()          # โ†’ APIs, databases
context.to_markdown()      # โ†’ Humans, documentation

2. Research-Backed Templates

Pre-built cognitive tools from the "Context Engineering" book:

from mycontext.templates.free import (
    QuestionAnalyzer,        # Systematic question analysis
    StepByStepReasoner,      # Methodical problem solving
    CodeReviewer,            # Expert code review
    ConceptExplainer,        # Clear explanations
    ContentOutliner          # Structured content planning
)

# Use like a function - no prompt engineering needed
analyzer = QuestionAnalyzer()
result = analyzer.execute(
    provider="openai",
    question="Should we migrate to microservices?"
)

3. RAG Integration (Knowledge Grounding)

Enrich contexts with relevant knowledge:

from mycontext.intelligence.rag import create_retriever

# Create retriever with semantic chunking
retriever = create_retriever(
    documents=["doc1.pdf", "doc2.md", ...],
    embedder="openai",
    chunk_strategy="semantic",
    vector_store="faiss"
)

# Retrieve and build context
docs = retriever.retrieve("How do we handle auth?", k=3)
knowledge_context = retriever.build_context(docs)

# Add to any context
context = Context(
    guidance=Guidance(role="Expert"),
    knowledge=knowledge_context
)

4. Session Management (Prevents Context Rot)

Multi-turn conversations without unbounded growth:

from mycontext import Session, FileArchive

# Create managed session
session = Session(
    max_tokens=4000,           # Token budget
    pruning_strategy="sliding" # Or "importance", "summary"
)

# Automatically manages context
session.add_user_message("What is context rot?")
session.add_assistant_message("Context rot is...")
session.add_user_message("How to prevent it?")  # Auto-prunes if needed

# Persist to disk
archive = FileArchive("./sessions")
archive.save_session(session, tags=["context-engineering"])

5. Production Utilities

Token optimization, cost tracking, validation:

from mycontext.utils import (
    TokenOptimizer,     # Reduce token usage
    CostTracker,        # Monitor spending
    ContextValidator,   # Validate structure
    StructuredOutput    # Parse responses
)

# Optimize context
optimizer = TokenOptimizer(max_tokens=2000)
optimized = optimizer.optimize(context)

# Track costs
tracker = CostTracker()
tracker.track(result, session_id="user_123")
print(f"Total cost: ${tracker.total_cost()}")

๐Ÿ”Œ Framework Integration

mycontext works with ANY framework or LLM:

# LangGraph
from langgraph.graph import StateGraph
context = my_context.to_langchain()
graph.add_node("agent", lambda s: use_context(context))

# CrewAI
from crewai import Crew
crew = Crew(agents=[...], context=my_context.to_dict())

# Direct OpenAI
import openai
openai.chat.completions.create(messages=my_context.to_messages())

# Custom API
import requests
requests.post(api_url, json=my_context.to_json())

๐Ÿ‘‰ LangGraph Integration Guide


๐Ÿ“š Documentation & Examples


๐Ÿ—บ๏ธ Roadmap

Current (v0.1) โœ…

  • โœ… Core transformation engine
  • โœ… Universal export formats (messages, JSON, markdown, LangChain)
  • โœ… 5 free templates
  • โœ… RAG with semantic chunking & reranking
  • โœ… Session management
  • โœ… Token optimization

Q1 2026 ๐Ÿ”„

  • RESTful API
  • Cloud platform (mycontext.ai)
  • 10 more free templates
  • Advanced RAG features
  • Deep LangGraph/CrewAI integration

Q2-Q3 2026 ๐Ÿ“…

  • 50+ premium templates
  • Visual context builder
  • Team collaboration
  • Enterprise features (SSO, teams)
  • JavaScript/TypeScript SDK

Q4 2026+ ๐ŸŽฏ

  • Template marketplace
  • Multi-language support
  • White-label solutions
  • Self-improving contexts (ML)

๐Ÿค Contributing

We love contributions! See CONTRIBUTING.md for guidelines.

Development Setup

# Clone the repo
git clone https://github.com/mycontext-ai/mycontext.git
cd mycontext

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check .
mypy src/

๐Ÿ“„ License

MIT ยฉ 2026 mycontext


๐ŸŒŸ Show Your Support

If mycontext helps you build better AI applications:


Built with โค๏ธ for anyone building with AI.

Transform your questions. Use them anywhere. Build better AI.

Get Started | Discord | GitHub

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mycontext_ai-0.1.0.tar.gz (83.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mycontext_ai-0.1.0-py3-none-any.whl (100.0 kB view details)

Uploaded Python 3

File details

Details for the file mycontext_ai-0.1.0.tar.gz.

File metadata

  • Download URL: mycontext_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 83.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.6

File hashes

Hashes for mycontext_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 462341f54fad3fc997eaf080767bb9e3ede601bcba2f4abf164e72cd8f9e107d
MD5 70e3afc99fdc4a83b70815fea7cf24db
BLAKE2b-256 832e980627370d73716662d11555f6cbbb34985b5365dcfdc7c27b051945159d

See more details on using hashes here.

File details

Details for the file mycontext_ai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mycontext_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c329caaab2459c8aa24cc82dac91049f8ac4953f8bb598e8e15135d8456a67c6
MD5 a4f6e6f4db4aed247fc94b130945843d
BLAKE2b-256 1632f7caeeb81152a6bc50eababa71c05495743980d8a4d611fe4ae4f5ce74b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page