pennsieve-ai-utils
Shared utilities for the Pennsieve AI Co-Scientist stages:
pennsieve-ai-scoutpennsieve-ai-hypothesizepennsieve-ai-analyzepennsieve-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, public Discover file list/download | scout, hypothesize, analyze, write |
pennsieve_ai_utils.backend |
VP_LLM_BACKEND selection (governor, bedrock, anthropic) and the per-backend Agent SDK environment |
all stages |
pennsieve_ai_utils.pricing |
Dated list-price table and summarize_usage, used to price usage.jsonl by token count at Bedrock rates |
write, run report |
pennsieve_ai_utils.bedrock_proxy |
Local signing proxy that holds the AWS credentials so stage containers never see them (local/Bedrock runs only) | workflow supervisor |
pennsieve_ai_utils.run_report |
Reads a run folder and builds one self-contained report.html, including what each stage set aside |
write, operators |
pennsieve_ai_utils.workflow |
Local four-stage supervisor, handoff gates, review bundles, report subcommand (python -m pennsieve_ai_utils.workflow) |
operators |
Everything from backend, pricing, bedrock_proxy, run_report and the
local parts of workflow is for running the pipeline off-platform. On the
Pennsieve platform the default backend is governor and that path is
unchanged; the supervisor, the signing proxy and the MCP sidecar do not run
there.
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_versionenables 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 VP_LLM_BACKEND setting chooses where model requests go.
| Value | Where requests go | What you must set |
|---|---|---|
governor |
Requests go to the Pennsieve LLM governor. This is the default, and it is what the platform uses. | The platform sets LLM_GOVERNOR_FUNCTION_NAME. Offline tests set PENNSIEVE_LLM_MOCK=1 instead. |
bedrock |
Requests go straight to Amazon Bedrock. They use your own AWS login. | Set AWS_REGION. Set AWS_PROFILE or AWS access keys. |
anthropic |
Requests go straight to the Anthropic API. | Set ANTHROPIC_API_KEY. |
Use bedrock and anthropic only for local testing. On these two settings,
there is no list of approved models and no spending limit. Name the model for
every role yourself, with VP_MODEL_REASONING, VP_MODEL_SYNTHESIS and
VP_MODEL_BULK. At startup, the client sends a tiny test request to each model.
It stops with an error if your account cannot use one of them. Write model
names in the Bedrock form. The client changes them to the Anthropic API form
when needed. For more about the governor, see
LLM access on compute nodes.
Set VP_LOG_LLM_IO=1 to save every model request and every response, word for
word. Each stage writes them to llm-io.<stage>.jsonl in its output folder. A
line is written as soon as each request finishes. Failed requests are saved
too. The workflow supervisor turns this on for local runs. These files contain
the full prompts. The prompts include text from papers and datasets. Read the
files before you share them.
Each line in usage.jsonl records the number of tokens in and out. It also
records the tokens read from and written to the prompt cache, and the backend.
It does not record a dollar cost. A report can work out the cost later, using
current prices.
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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pennsieve_ai_utils-0.2.2.tar.gz | 102.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pennsieve_ai_utils-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 192.5 kB
Release files / pennsieve_ai_utils-0.2.2.tar.gz
| Download URL | pennsieve_ai_utils-0.2.2.tar.gz |
|---|---|
| Size | 102.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e982ff980be65bafc41bb5db2128e922af9f08ab619ec0aefe48535f89849cdd
|
|
BLAKE2b-256 checksum How to use checksums |
5833e17849678190d8f96ce6e0ac01323c72efead55ee340196be1eda471a160
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 21, 2026.
Transparency logRelease files / pennsieve_ai_utils-0.2.2-py3-none-any.whl
| Download URL | pennsieve_ai_utils-0.2.2-py3-none-any.whl |
|---|---|
| Size | 90.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2b3a2fa9de99b40d81b19f102c910afa45797c280ae9370bf1d00bcad417aa0
|
|
BLAKE2b-256 checksum How to use checksums |
e1cae943d55eab2702d69df4cf8547ddcb1e7bb30d59d1a011ede516a4568b4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 21, 2026.
Transparency logSecurity for pennsieve-ai-utils 0.2.2
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.
Attestation for pennsieve_ai_utils-0.2.2.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 Oct 21, 2026.
Transparency logA 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.