Skip to main content

pennsieve-ai-utils

Shared utilities for the Pennsieve AI Co-Scientist stages:

  1. pennsieve-ai-scout
  2. pennsieve-ai-hypothesize
  3. pennsieve-ai-analyze
  4. pennsieve-ai-write

Each stage used to carry its own copy of the blackboard schema, the governor LLM client, the model-role resolver, the agent helpers and the literature tools. They now import them from here. The package is published to PyPI as pennsieve-ai-utils (same release flow as pennsieve-llm: push a vX.Y.Z tag), so the Pennsieve App Store build of each stage can pip install it without GitHub credentials.

See RUNBOOK.md for local stage supervision, stopping, review bundles and the remaining Pennsieve Test deployment work.

pip install pennsieve-ai-utils

What's here

Module Owns Used by
pennsieve_ai_utils.blackboard Canonical Blackboard JSON contract, schema_version migrations, unknown-field preservation all stages
pennsieve_ai_utils.llm LLMClient: governor transport via pennsieve-llm, role-based model selection, preflight, self-healing on 403/404, usage.jsonl logging all stages
pennsieve_ai_utils.models Role table (reasoning, synthesis, bulk), capability ranking, allow-list discovery, operator pins llm
pennsieve_ai_utils.agents call_json, extract_json, first_text, format_datasets, attack-tag helpers, load_prompt every agent
pennsieve_ai_utils.processor Pennsieve processor env contract (INPUT_DIR/OUTPUT_DIR/run IDs), SIGTERM handling, upstream blackboard loading, output persistence every main.py
pennsieve_ai_utils.tools CrossRef, DataCite, DOI lookup, JATS/Markdown chunkers, Bedrock embeddings + reranker, RAG store reader scout, hypothesize, write
pennsieve_ai_utils.workflow Local four-stage supervisor, handoff gates, review bundles (python -m pennsieve_ai_utils.workflow) operators

Stage-specific science — pipelines, prompts, Discover/DANDI/OpenNeuro inspection, notebook execution, manuscript rendering — stays in each app.

Blackboard contract

from pennsieve_ai_utils import Blackboard

bb = Blackboard.load("blackboard.json")
bb.record_model_assignment(
    stage="hypothesize",
    role="reasoning",
    assignment={"model_id": "us.anthropic.claude-sonnet-4-6"},
)
bb.save("blackboard.json")
  • One superset schema carries fields produced by every stage.
  • schema_version enables explicit migrations; documents without a version are treated as legacy version 0.
  • Unknown fields are preserved at their original object level on a load/save round trip.
  • Model provenance is cumulative by stage (model_assignments[stage][role]) rather than overwritten by the next application.

LLM client

from pennsieve_ai_utils.llm import LLMClient
from pennsieve_ai_utils.agents import call_json

client = LLMClient(stage="hypothesize", roles=("reasoning", "synthesis"))
assignments = client.preflight()          # raises ModelNotAvailable if a floor can't be met
for role, assignment in assignments.items():
    bb.record_model_assignment(stage="hypothesize", role=role, assignment=assignment)

verdict = call_json(client, agent="critic", system=..., user=..., run_id=bb.run_id,
                    model="reasoning")

Agents address models by role, never by vendor tier. The legacy names opus / sonnet / haiku still resolve as aliases of reasoning / synthesis / bulk, and VP_MODEL_<ROLE> pins keep working.

Preflight asks the governor's GET /v1/models for the allow-list first and falls back to tripping a model_not_allowed 403 on older governors. Each assigned model is then verified with a one-token call so an IAM block or a retired Bedrock model fails at startup rather than twenty minutes in.

The client needs LLM_GOVERNOR_FUNCTION_NAME (platform-injected) or PENNSIEVE_LLM_MOCK=1 for offline tests — see LLM access on compute nodes.

Processor helpers

from pennsieve_ai_utils.processor import (
    ProcessorEnv, install_sigterm_handler, load_upstream_blackboard, write_outputs,
)

install_sigterm_handler()
env = ProcessorEnv.from_environ()
bb = load_upstream_blackboard(env.input_dir / "blackboard.json",
                              stage="analyze", upstream="Hypothesize",
                              run_id=env.execution_run_id)
...
write_outputs(bb, env.output_dir, client.usage_log)

These follow the Pennsieve processor contract: read from INPUT_DIR, write to OUTPUT_DIR, exit non-zero on failure.

Releasing

# bump version in pyproject.toml, commit, then:
git tag v0.2.0 && git push origin v0.2.0

.github/workflows/publish-pypi.yml builds and publishes via PyPI Trusted Publishing. One-time setup on pypi.org: add this repository as a trusted publisher for the pennsieve-ai-utils project (GitHub environment pypi). Apps pin pennsieve-ai-utils>=0.2,<0.3 and pick up patch releases on rebuild.

Development

python -m pip install -e ".[dev]"
python -m ruff check src tests
python -m pytest

Metadata

Release files for pennsieve-ai-utils 0.2.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 pennsieve-ai-utils 0.2.0
File Size Uploaded Provenance
pennsieve_ai_utils-0.2.0.tar.gz 55.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pennsieve-ai-utils 0.2.0
File Interpreter ABI Platform
pennsieve_ai_utils-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 106.9 kB

Release files / pennsieve_ai_utils-0.2.0.tar.gz

Download URL pennsieve_ai_utils-0.2.0.tar.gz
Size 55.6 kB
Tags Source
SHA-256 checksum
How to use checksums
27770923d85a49fce33efc6909915ab4fa18d7f513bc94151a31986e90c200f0
BLAKE2b-256 checksum
How to use checksums
c955a3ebfb0f060d6943fb252cf61512bb550f989f6da727303f7a1a54293daf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Release files / pennsieve_ai_utils-0.2.0-py3-none-any.whl

Download URL pennsieve_ai_utils-0.2.0-py3-none-any.whl
Size 51.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4f727b1e27a2c539ec6b837a668dab2535509756848fe029323f36609186676
BLAKE2b-256 checksum
How to use checksums
d25ea91dec75a48b0d8f1630d3ce3ce2d5719c6c48e2fa8fd04346368d80710d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Security for pennsieve-ai-utils 0.2.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pennsieve_ai_utils-0.2.0.tar.gz

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 Sep 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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