Skip to main content

coreason-construct

The Standard Library for Cognitive Architecture.

CI/CD Docker PyPI version PyPI - Python Version License codecov Ruff pre-commit

Executive Summary

coreason-construct is the Standard Library for Cognitive Architecture.

It replaces ad-hoc prompt engineering with Type-Driven Generation. It integrates instructor to patch LLM clients, linking Pydantic schemas directly to the model's logits.

However, structure alone is not enough. The package provides a strictly typed library of Cognitive Components—Roles, Contexts, Logic Primitives, and Data Banks—that are assembled by the Weaver. The Weaver not only enforces output schema but also manages Dependency Resolution (context injection) and Token Optimization before the request is sent.

Service Mode (New in v0.5.0)

coreason-construct can now act as a Prompt Compilation Microservice (Service C). This service exposes endpoints to:

  • Compile (/v1/compile): Weave components into a final configuration, handling context injection and token optimization on the server side.
  • Optimize (/v1/optimize): Compress raw text using token-aware strategies (e.g., middle-out pruning).

Refer to the Usage Guide for API details.

Functional Philosophy: The Assembler Pattern

"Prompts are not written; they are assembled. Outputs are not strings; they are Objects."

A Prompt is an object composed of:

  1. Identity (Who): The Role and its biases.
  2. Environment (Where): The regulatory and data context.
  3. Mode (How): The active reasoning style (e.g., "Six Hats", "Socratic").
  4. Data (Evidence): Few-shot examples and negative constraints.
  5. Task (What): The Structured Primitive (e.g., CohortLogic, Extract).
  6. Output (Type): The specific Pydantic model the LLM must populate.

Getting Started

Prerequisites

  • Python 3.12+
  • Poetry (for development)

Installation

pip install coreason-construct

Or with Poetry:

poetry add coreason-construct

Quick Start

Assemble a prompt for Adverse Event extraction using a standardized Role and Few-Shot Data.

from coreason_construct import Weaver
from coreason_construct.roles.library import SafetyScientist
from coreason_construct.data.library import AE_Examples
from coreason_construct.primitives.extract import ExtractionPrimitive
from coreason_construct.schemas.clinical import AdverseEvent

# 1. Initialize the Weaver
weaver = Weaver()

# 2. Add Components
# Automatically injects dependencies (e.g., HIPAA & GxP Contexts for SafetyScientist)
weaver.add(SafetyScientist)
# Injects Few-Shot examples for robust extraction
weaver.add(AE_Examples)

# 3. Add the Task (Primitive)
extractor = ExtractionPrimitive(
    name="AE_Extractor",
    schema=AdverseEvent
)
weaver.add(extractor)

# 4. Build the Prompt Configuration
user_input = "Patient reported mild nausea after taking the study drug."
config = weaver.build(user_input)

# The 'config' object is now ready to be sent to an LLM via instructor
print(config.system_message)
# Output includes:
# - Safety Scientist Persona
# - HIPAA/GxP Constraints
# - Few-Shot Examples (formatted JSON)
# - Extraction Instructions

Documentation

For more detailed information, please refer to the documentation:

License

Proprietary and Dual-Licensed. See LICENSE for details.

Metadata

Release files for coreason-construct 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coreason-construct 0.5.0
File Size Uploaded
coreason_construct-0.5.0.tar.gz 19.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coreason-construct 0.5.0
File Interpreter ABI Platform
coreason_construct-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.2 kB

Release files / coreason_construct-0.5.0.tar.gz

Download URL coreason_construct-0.5.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0cab949ad205a1f6804938d3289c1f698e8ef127e36c1a15f13b171d5536426e
BLAKE2b-256 checksum
How to use checksums
33ef870b1974f958434d5fba6649a77c3044fcc4dd5d6bc7606e6fffddbe5f57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 31, 2026.

Transparency log

Release files / coreason_construct-0.5.0-py3-none-any.whl

Download URL coreason_construct-0.5.0-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8e75ab2e90228907185e491aa7dc4c8ae03422875877ad06ace2bfa9f2789ac
BLAKE2b-256 checksum
How to use checksums
58647f744f2cdeffbee390f808060637c997b411345b868cb9dc3fb49ab84461
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page