Metadata-Version: 2.4
Name: coreason_construct
Version: 0.2.0
Summary: coreason-construct
License: # The Prosperity Public License 3.0.0
         
         Contributor: CoReason, Inc.
         
         Source Code: https://github.com/CoReason-AI/coreason_construct
         
         ## Purpose
         
         This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
         
         ## Agreement
         
         In order to receive this license, you have to agree to its rules.  Those rules are both obligations under that agreement and conditions to your license.  Don't do anything with this software that triggers a rule you can't or won't follow.
         
         ## Notices
         
         Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
         
         ## Commercial Trial
         
         Limit your use of this software for commercial purposes to a thirty-day trial period.  If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
         
         ## Contributions Back
         
         Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
         
         ## Personal Uses
         
         Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
         
         ## Noncommercial Organizations
         
         Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
         
         ## Defense
         
         Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
         
         ## Copyright
         
         The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
         
         ## Patent
         
         The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
         
         ## Reliability
         
         The contributor can't revoke this license.
         
         ## Excuse
         
         You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
         
         ## No Liability
         
         ***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
License-File: LICENSE
License-File: NOTICE
Author: Gowtham A Rao
Author-email: gowtham.rao@coreason.ai
Requires-Python: >=3.11
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Dist: instructor (>=1.0.0,<2.0.0)
Requires-Dist: jinja2 (>=3.1.0,<4.0.0)
Requires-Dist: loguru (>=0.7.2,<0.8.0)
Requires-Dist: pydantic (>=2.0.0,<3.0.0)
Project-URL: Documentation, https://github.com/CoReason-AI/coreason-construct
Project-URL: Homepage, https://github.com/CoReason-AI/coreason-construct
Project-URL: Repository, https://github.com/CoReason-AI/coreason-construct
Description-Content-Type: text/markdown

# coreason-construct

**The Standard Library for Cognitive Architecture.**

[![CI/CD](https://github.com/CoReason-AI/coreason-construct/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/CoReason-AI/coreason-construct/actions/workflows/ci-cd.yml)
[![Docker](https://github.com/CoReason-AI/coreason-construct/actions/workflows/docker.yml/badge.svg)](https://github.com/CoReason-AI/coreason-construct/actions/workflows/docker.yml)
[![PyPI version](https://badge.fury.io/py/coreason_construct.svg)](https://badge.fury.io/py/coreason_construct)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/coreason_construct.svg)](https://pypi.org/project/coreason_construct/)
[![License](https://img.shields.io/badge/license-Prosperity%20Public%20License%203.0-blue.svg)](LICENSE)
[![codecov](https://codecov.io/gh/CoReason-AI/coreason-construct/branch/main/graph/badge.svg)](https://codecov.io/gh/CoReason-AI/coreason-construct)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/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.

## 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

```sh
pip install coreason-construct
```

Or with Poetry:

```sh
poetry add coreason-construct
```

### Quick Start

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

```python
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:

*   [Usage Guide](docs/usage.md): Detailed explanation of components and the Weaver.
*   [Vignette](docs/vignette.md): A narrative example of using coreason-construct.
*   [Product Requirements Document](docs/PRD.md): The full PRD for this library.

## License

Proprietary and Dual-Licensed. See [LICENSE](LICENSE) for details.

