Skip to main content

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]" (or uv sync --extra openai when 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

  1. Install Python 3.14 (pyenv users can run pyenv install 3.14.0).
  2. Install uv.
  3. Sync the virtualenv and optional git hooks:
    uv sync
    ./install-hooks.sh  # optional – wires git hooks that call make check
    
  4. 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 via build/run_pytest.py with --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; see specs/PROMPTS.md for prompt requirements.
  • build/ — thin wrappers that keep CLI tools quiet inside uv.
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weakincentives-0.2.0.tar.gz (103.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weakincentives-0.2.0-py3-none-any.whl (36.5 kB view details)

Uploaded Python 3

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

Hashes for weakincentives-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9f6283d2efe46ad4624bad5a152b930daa14ad7482a13bbfdb0ce99567e2c0ad
MD5 f522cc747adc677206554e75a8de4b69
BLAKE2b-256 f3307008d1f49dd77ab147ccebb3fc71ae6203f1f1abc0818546924442441721

See more details on using hashes here.

Provenance

The following attestation bundles were made for weakincentives-0.2.0.tar.gz:

Publisher: release.yml on weakincentives/weakincentives

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for weakincentives-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eeec28c92f73488d966083a67c85cb98d5597d949b4a522529a26bf76a968d0d
MD5 6b6061f41e9d89e771651eb478d24744
BLAKE2b-256 d97b69ec8d55780a7a6304c71024e75f0049e2d32d8c7bd6f2cb1e33c2f4fbda

See more details on using hashes here.

Provenance

The following attestation bundles were made for weakincentives-0.2.0-py3-none-any.whl:

Publisher: release.yml on weakincentives/weakincentives

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page