Skip to main content

A modular system prompt composition framework for AI assistants

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Prompt Composer

A modular system prompt composition framework that intelligently generates system prompts for AI assistants based on available tools, task complexity, and contextual information.

Language Support

  • Python: pip install system-prompt-composer
  • Node.js: npm install system-prompt-composer (native bindings - no Python required!)

Quick Start

Python

import system_prompt_composer
import json

request = {
    "user_prompt": "Help me analyze this code",
    "mcp_config": {"mcpServers": {...}},
    "session_state": {"tool_call_count": 0}
}

response = system_prompt_composer.compose_system_prompt(json.dumps(request))
result = json.loads(response)
print(result["system_prompt"])

Node.js (Native)

const { composeSystemPrompt } = require('system-prompt-composer');

const request = {
  user_prompt: "Help me analyze this code",
  mcp_config: { mcpServers: {...} },
  session_state: { tool_call_count: 0 }
};

const response = await composeSystemPrompt(request);
console.log(response.system_prompt);

๐Ÿ“– For detailed Node.js documentation, see node/README.md

Project Structure

prompt-composer/
โ”œโ”€โ”€ core/              # Rust core implementation
โ”‚   โ”œโ”€โ”€ lib.rs         # Main library with NAPI bindings
โ”‚   โ”œโ”€โ”€ types.rs       # Type definitions
โ”‚   โ”œโ”€โ”€ composition.rs # Prompt composition logic
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ python/            # Python package (PyO3 bindings)
โ”œโ”€โ”€ node/              # Node.js package (native NAPI-RS bindings)
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ index.js       # Native bindings wrapper
โ”‚   โ””โ”€โ”€ index.d.ts     # TypeScript definitions
โ”œโ”€โ”€ prompts/           # Modular prompt library
โ”‚   โ”œโ”€โ”€ domains/       # Domain-specific prompts
โ”‚   โ””โ”€โ”€ behaviors/     # Behavioral guidance prompts
โ””โ”€โ”€ README.md          # This file

Features

  • ๐Ÿง  Intelligent prompts that adapt to available MCP tools
  • ๐Ÿ“‹ Automatic task planning for complex requests
  • ๐ŸŽฏ Context-aware guidance for different domains (programming, analysis, filesystem, etc.)
  • ๐Ÿ“Š Progress monitoring for multi-step workflows
  • ๐Ÿ”„ Modular design with composable prompt components
  • โšก High performance with Rust core
  • ๐ŸŒ Multi-language support (Python, Node.js)

Installation

Python Package

pip install system-prompt-composer

Node.js Package (Native - No Python Required!)

npm install system-prompt-composer

The Node.js package now uses native Rust bindings via NAPI-RS, eliminating the Python dependency!

API Reference

Core Functions

composeSystemPrompt(request)

Generate an intelligent system prompt based on available tools and context.

Parameters:

  • request.user_prompt (string): The user's request
  • request.mcp_config (object): MCP server configuration with mcpServers
  • request.session_state (object): Current session state including tool_call_count
  • request.domain_hints (array, optional): Domain hints like ["programming", "analysis"]
  • request.task_complexity (string, optional): "Simple", "Complex", or "Auto"

Returns:

{
  system_prompt: "Generated prompt text...",
  source: "native",
  version: "1.1.0",
  // ... additional metadata
}

listAvailableDomains()

Returns array of available domain modules: ["programming", "analysis", "filesystem", "system"]

listAvailableBehaviors()

Returns array of available behavior modules: ["planning", "progress", "reasoning", "tools"]

getStatus()

Returns system status and configuration information.

isAvailable()

Always returns true for native bindings.

Tools Directory Feature

The system-prompt-composer supports tool-specific instruction files to improve how LLMs use MCP tools.

How It Works

When you call composeSystemPrompt() with MCP server configurations, the system automatically looks for corresponding instruction files in prompts/tools/ and includes them in the generated system prompt.

prompts/
โ”œโ”€โ”€ behaviors/          # General AI behaviors 
โ”œโ”€โ”€ domains/           # Domain-specific knowledge
โ”œโ”€โ”€ tools/             # NEW: Tool-specific instructions
โ”‚   โ”œโ”€โ”€ desktop-commander.md
โ”‚   โ”œโ”€โ”€ weather-service.md
โ”‚   โ””โ”€โ”€ [your-mcp-server-name].md
โ””โ”€โ”€ server_patterns.toml

Creating Tool Instructions

Create a markdown file named after your MCP server:

# My Custom Tool Instructions

You have access to my-custom-tool with these capabilities:
- Function 1: description and best practices
- Function 2: common usage patterns

## Best Practices
- Specific guidance for effective tool usage
- Error handling approaches
- Performance considerations

Updated API Response

Tool instructions are automatically included and tracked:

{
  system_prompt: "...",
  applied_modules: [
    "planning",
    "tool:desktop-commander",  // Tool instructions included
    "tool:weather-service"
  ],
  recognized_tools: [...],
  complexity_assessment: "simple"
}

The getStatus() function now also returns available tools:

{
  available: true,
  domains: ["analysis", "filesystem", "programming"],
  behaviors: ["planning", "progress", "reasoning"], 
  tools: ["desktop-commander", "weather-service"],  // NEW
  version: "1.0.3"
}

Benefits

  • Better Tool Usage: LLMs get specific guidance for each tool
  • Developer Control: Customize instructions for your MCP tools
  • Automatic Integration: Just add markdown files - no code changes
  • Graceful Fallback: Missing tool files are safely ignored

Architecture

Native Node.js Architecture (NEW):

Node.js โ†’ NAPI-RS โ†’ Rust Core

Python Architecture:

Python โ†’ PyO3 โ†’ Rust Core  

Key Benefits of Native Bindings:

  • โœ… No Python dependency for Node.js users
  • โœ… Native performance - direct Rust execution
  • โœ… Simple deployment - just npm install
  • โœ… Better error handling
  • โœ… Cross-platform binary distribution
  • โœ… Smaller bundle size

Development

Building Native Node.js Package

cd node/
npm install
npm run build        # Build release binaries
npm run build:debug  # Build debug binaries
npm test            # Run tests

Python Development

cd python/
pip install -e .

Rust Core Development

cargo build --release
cargo test
cargo build --features nodejs  # For Node.js bindings
cargo build --features python  # For Python bindings

Publishing

Node.js (npm)

cd node/
npm run build       # Build native binaries
npm publish --access public

Python (PyPI)

cd python/
pip install build twine
python -m build
twine upload dist/*

Contributing

Contributions welcome! The project uses:

  • Rust for the core prompt composition engine
  • NAPI-RS for Node.js native bindings
  • PyO3 for Python bindings
  • Modular prompts in the prompts/ directory

License

MIT License - see LICENSE file for details.

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

system_prompt_composer-1.0.4.tar.gz (63.0 kB view details)

Uploaded Source

Built Distributions

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

system_prompt_composer-1.0.4-cp312-cp312-manylinux_2_34_x86_64.whl (555.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

system_prompt_composer-1.0.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.whl (18.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.5+ x86-64

File details

Details for the file system_prompt_composer-1.0.4.tar.gz.

File metadata

File hashes

Hashes for system_prompt_composer-1.0.4.tar.gz
Algorithm Hash digest
SHA256 9e94bd90abd33b82fa6b16b95bdc07df6f886afa5cd08806b0e6b8fdfff01d47
MD5 20172f42bb88d0de5390d0776664afd8
BLAKE2b-256 1415d3a0b4df330b4ad2095be8b989ac8fdaa312a6e43c0c8bb6faae5d46966f

See more details on using hashes here.

File details

Details for the file system_prompt_composer-1.0.4-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for system_prompt_composer-1.0.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 56b1b1fd11bd2c444aadc3188c3f94a5cf540fca1d51c8a23b1cdb31ed29fa82
MD5 14f8edbd4c9fbc80464911370bdfdc72
BLAKE2b-256 e77dd7d9a632b54830e43ac7bc8df985de478ea114a6880c37d03b90e13fafcf

See more details on using hashes here.

File details

Details for the file system_prompt_composer-1.0.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for system_prompt_composer-1.0.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b5a9678da0f62dc257fe751784a10c1ae7067ed1be834a0d9aa768e0b6adab99
MD5 066e30913cbf5d4a1fe9b37ccd705354
BLAKE2b-256 61ba4300a1becc8d81f8866021ca9cc16b5289764dae317a90e8a3a0ca483702

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