Tools for developing and optimizing side effect free background agents
Project description
Weak Incentives
Tools for developing and optimizing side effect free background agents. The library ships prompt composition primitives, structured tool metadata, and optional provider adapters so you can scaffold deterministic automation flows quickly. All commands below assume Astral's uv CLI.
For Library Users
Installation
uv add weakincentives- Add
uv add "weakincentives[openai]"(oruv sync --extra openaiwhen cloning the repo) to enable the OpenAI adapter helpers.
Key Features
- Fully typed prompt composition primitives (
Prompt,Section,TextSection,Tool,ToolResult) for assembling deterministic Markdown prompts with attached tool metadata. - Stdlib-only dataclass serde utilities (
parse,dump,clone,schema) for Pydantic-like ergonomics without third-party dependencies. - Optional OpenAI adapter that gates imports behind a friendly error and returns the SDK client when the extra is present.
- Quiet-by-default package with minimal runtime dependencies so background agents stay lean and predictable.
Quickstart
from dataclasses import dataclass
from weakincentives.prompts import (
Prompt,
TextSection,
Tool,
ToolResult,
parse_output,
)
@dataclass
class ResearchGuidance:
topic: str
@dataclass
class SourceLookup:
source_id: str
@dataclass
class SourceDetails:
source_id: str
title: str
@dataclass
class ResearchSummary:
summary: str
citations: list[str]
def lookup_source(params: SourceLookup) -> ToolResult[SourceDetails]:
details = SourceDetails(source_id=params.source_id, title="Ada Lovelace Archive")
return ToolResult(message=f"Loaded {details.title}", payload=details)
catalog_tool = Tool[SourceLookup, SourceDetails](
name="catalog_lookup",
description="Look up a primary source identifier and return structured details.",
handler=lookup_source,
)
research_section = TextSection[ResearchGuidance](
title="Task",
body=(
"Research ${topic}. Use the `catalog_lookup` tool for citations and return"
" a JSON summary with citations."
),
tools=[catalog_tool],
)
prompt = Prompt[ResearchSummary](
name="research_run",
sections=[research_section],
)
rendered = prompt.render(ResearchGuidance(topic="Ada Lovelace"))
print(rendered.text)
print([tool.name for tool in rendered.tools])
reply = """```json
{
"summary": "Ada Lovelace pioneered computing...",
"citations": ["catalog_lookup:ada-archive"]
}
```"""
parsed = parse_output(reply, rendered)
print(parsed.summary)
print(parsed.citations)
Optional Extras
Use the OpenAI helpers once the extra is installed:
from weakincentives.adapters import OpenAIAdapter
adapter = OpenAIAdapter(model="gpt-4o-mini", client_kwargs={"api_key": "sk-..."})
If the dependency is missing, the adapter raises a runtime error with installation guidance.
For Library Developers
Environment Setup
- Install Python 3.14 (pyenv users can run
pyenv install 3.14.0). - Install
uv. - Sync the virtualenv and optional git hooks:
uv sync ./install-hooks.sh # optional – wires git hooks that call make check
- Use
uv run ...when invoking ad-hoc scripts so everything stays inside the managed environment.
Development Workflow
make format/make format-check— run Ruff formatters.make lint/make lint-fix— lint with Ruff.make typecheck— execute Ty with warnings promoted to errors.make test— run pytest viabuild/run_pytest.pywith--cov-fail-under=100.make bandit,make deptry,make pip-audit— security, dependency, and vulnerability audits.make check— aggregate the quiet quality gate; run this before every commit (git hooks enforce it).
Project Layout
src/weakincentives/— package root for the Python module.src/weakincentives/prompts/— prompt, section, and tool primitives.src/weakincentives/adapters/— optional provider integrations.tests/— pytest suites covering prompts, tools, and adapters.specs/— design docs; seespecs/PROMPTS.mdfor prompt requirements.build/— thin wrappers that keep CLI tools quiet insideuv.hooks/— symlink-friendly git hooks (install via./install-hooks.sh).
Release Notes
Version numbers come from git tags named vX.Y.Z. Tag the repository manually before pushing a release.
More Documentation
AGENTS.md captures the full agent handbook, workflows, and TDD expectations. ROADMAP.md and specs/ document upcoming work and prompt requirements.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file weakincentives-0.2.0.tar.gz.
File metadata
- Download URL: weakincentives-0.2.0.tar.gz
- Upload date:
- Size: 103.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f6283d2efe46ad4624bad5a152b930daa14ad7482a13bbfdb0ce99567e2c0ad
|
|
| MD5 |
f522cc747adc677206554e75a8de4b69
|
|
| BLAKE2b-256 |
f3307008d1f49dd77ab147ccebb3fc71ae6203f1f1abc0818546924442441721
|
Provenance
The following attestation bundles were made for weakincentives-0.2.0.tar.gz:
Publisher:
release.yml on weakincentives/weakincentives
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
weakincentives-0.2.0.tar.gz -
Subject digest:
9f6283d2efe46ad4624bad5a152b930daa14ad7482a13bbfdb0ce99567e2c0ad - Sigstore transparency entry: 653662968
- Sigstore integration time:
-
Permalink:
weakincentives/weakincentives@8ed1410606e9c4e26d1412e744391870b72a2f07 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/weakincentives
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8ed1410606e9c4e26d1412e744391870b72a2f07 -
Trigger Event:
release
-
Statement type:
File details
Details for the file weakincentives-0.2.0-py3-none-any.whl.
File metadata
- Download URL: weakincentives-0.2.0-py3-none-any.whl
- Upload date:
- Size: 36.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeec28c92f73488d966083a67c85cb98d5597d949b4a522529a26bf76a968d0d
|
|
| MD5 |
6b6061f41e9d89e771651eb478d24744
|
|
| BLAKE2b-256 |
d97b69ec8d55780a7a6304c71024e75f0049e2d32d8c7bd6f2cb1e33c2f4fbda
|
Provenance
The following attestation bundles were made for weakincentives-0.2.0-py3-none-any.whl:
Publisher:
release.yml on weakincentives/weakincentives
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
weakincentives-0.2.0-py3-none-any.whl -
Subject digest:
eeec28c92f73488d966083a67c85cb98d5597d949b4a522529a26bf76a968d0d - Sigstore transparency entry: 653662978
- Sigstore integration time:
-
Permalink:
weakincentives/weakincentives@8ed1410606e9c4e26d1412e744391870b72a2f07 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/weakincentives
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8ed1410606e9c4e26d1412e744391870b72a2f07 -
Trigger Event:
release
-
Statement type: