Context Engineering Toolkit - Practical tools for optimizing AI context management
Project description
English | 简体中文
A practical toolkit for optimizing AI context management, helping solve problems such as content loss in long contexts, insufficient tokens, information redundancy, and context pollution.
Core Features
Context Builder
- Key information prioritization optimization
- Intelligent scene background integration
- Structured content layering
Token Saver
- Automatic duplicate content merging
- Terminology compression
- Content summary generation
Anti-Pollution System
- Error information isolation
- Term consistency checking
- Clear task boundary definition
Tool Coordinator
- Tool boundary definition
- Dynamic call constraints
- Multi-tool collaboration workflow
📦 Installation
pip install ctxtoolkit
🚀 Quick Start
1. Context Building
from ctxtoolkit import ContextBuilder
# Create context builder
builder = ContextBuilder()
# Add core instruction
builder.add_core_instruction(
"Optimize the performance of this Python code",
requirements=[
"Reduce memory usage",
"Improve execution speed",
"Maintain original functionality"
]
)
# Add key information
builder.add_key_info(
"Code functionality", "Processes 1 million user logs"
)
builder.add_key_info(
"Current bottleneck", "Nested loops causing O(n²) complexity"
)
builder.add_key_info(
"Available resources", "8GB RAM, 4-core CPU"
)
# Add supplementary reference
current_code = """
def process_logs(logs):
results = []
for i in range(len(logs)):
for j in range(i+1, len(logs)):
if logs[i]['user_id'] == logs[j]['user_id']:
results.append((logs[i], logs[j]))
return results
"""
builder.add_reference(current_code)
# Generate optimized context
optimized_context = builder.build()
print(optimized_context)
2. Token Saving Example
from ctxtoolkit import TokenSaver
# Create Token saver
saver = TokenSaver()
# Define terminology
saver.add_terminology("R1", "Input format: JSON object containing name(str), age(int), tags(list[str])")
saver.add_terminology("R2", "Output format: Markdown table containing user information and tag statistics")
saver.add_terminology("R3", "Processing rules: Filter age>18, sort by number of tags descending")
# Process user data
user_data = [
'{"name":"Zhang San","age":25,"tags":["Python","AI"]}',
'{"name":"Li Si","age":17,"tags":["Java"]}'
]
# Generate compact context
compact_context = saver.build_compact_context(
"Please process the following user data",
data=user_data,
rules=["R1", "R2", "R3"]
)
print(compact_context)
📁 Project Structure
ctxtoolkit/
├── ctxtoolkit/ # Core package directory
│ ├── __init__.py # Package initialization file
│ ├── context_builder.py # Context builder
│ ├── token_saver.py # Token saver
│ ├── anti_pollution.py # Anti-pollution system
│ └── tool_coordinator.py # Tool coordinator
├── LICENSE
├── MANIFEST.in
├── README.md
└── setup.py
📚 API Documentation
API documentation has been moved to API_DOCUMENTATION.md.
🔧 Development
Install Development Dependencies
pip install -e .[dev]
Run Tests
pytest
Code Style Check
flake8
🤝 Contributing
Contributions are welcome! Feel free to submit Issues and Pull Requests.
📄 License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ctxtoolkit-0.1.1.tar.gz.
File metadata
- Download URL: ctxtoolkit-0.1.1.tar.gz
- Upload date:
- Size: 472.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd44f7d44095e3175109b7e809974f0b16fa794e0ff6d8f99dc12fce0cb7a31a
|
|
| MD5 |
ef82e08bf888c337bc9b615452aa5508
|
|
| BLAKE2b-256 |
9250e242df52502b8f3ceb43020402ea6e050fd4d8fa304308b04c8ad5168982
|
File details
Details for the file ctxtoolkit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ctxtoolkit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b1f07dabb50438058d4fccc7645a663ea466dca3591c8a17fb4efedb5e64567
|
|
| MD5 |
1856c3a20dbe73b8575b2e7ec91f7379
|
|
| BLAKE2b-256 |
0b1c1c343f464c21b87677e7e9c053cf67e7070fdd530194c1dacdb88eda19db
|