weakincentives 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of weakincentives might be problematic. Click here for more details.

@@ -1,231 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: weakincentives
3
- Version: 0.3.0
4
- Summary: Tools for developing and optimizing side effect free background agents
5
- Project-URL: Homepage, https://weakincentives.com/
6
- Project-URL: Documentation, https://github.com/weakincentives/weakincentives#readme
7
- Project-URL: Repository, https://github.com/weakincentives/weakincentives
8
- Project-URL: Issue Tracker, https://github.com/weakincentives/weakincentives/issues
9
- Author-email: Andrei Savu <andrei@weakincentives.com>
10
- License: Apache-2.0
11
- License-File: LICENSE
12
- Keywords: agents,ai,background-agents,optimization,side-effect-free,weak-incentives
13
- Classifier: Development Status :: 3 - Alpha
14
- Classifier: Intended Audience :: Developers
15
- Classifier: Intended Audience :: Science/Research
16
- Classifier: License :: OSI Approved :: Apache Software License
17
- Classifier: Operating System :: OS Independent
18
- Classifier: Programming Language :: Python :: 3
19
- Classifier: Programming Language :: Python :: 3.12
20
- Classifier: Programming Language :: Python :: 3.13
21
- Classifier: Programming Language :: Python :: 3.14
22
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
- Classifier: Typing :: Typed
25
- Requires-Python: >=3.12
26
- Provides-Extra: litellm
27
- Requires-Dist: litellm>=1.79.0; extra == 'litellm'
28
- Provides-Extra: openai
29
- Requires-Dist: openai>=2.6.1; extra == 'openai'
30
- Description-Content-Type: text/markdown
31
-
32
- # Weak Incentives
33
-
34
- **Lean, typed building blocks for side-effect-free background agents.**
35
- Compose deterministic prompts, run typed tools, and parse strict JSON replies without
36
- heavy dependencies. Optional adapters snap in when you need a model provider.
37
-
38
- ## Highlights
39
-
40
- - Namespaced prompt trees with deterministic Markdown renders, placeholder
41
- verification, and tool-aware versioning metadata.
42
- - Stdlib-only dataclass serde (`parse`, `dump`, `clone`, `schema`) keeps request and
43
- response types honest end-to-end.
44
- - Session state container and event bus collect prompt and tool telemetry for
45
- downstream automation.
46
- - Built-in planning and virtual filesystem tool suites give agents durable plans and
47
- sandboxed edits backed by reducers and selectors.
48
- - Optional OpenAI and LiteLLM adapters integrate structured output parsing, tool
49
- orchestration, and telemetry hooks.
50
-
51
- ## Requirements
52
-
53
- - Python 3.12+ (the repository pins 3.14 in `.python-version` for development)
54
- - [`uv`](https://github.com/astral-sh/uv) CLI
55
-
56
- ## Install
57
-
58
- ```bash
59
- uv add weakincentives
60
- # optional provider adapters
61
- uv add "weakincentives[openai]"
62
- uv add "weakincentives[litellm]"
63
- # cloning the repo? use: uv sync --extra openai --extra litellm
64
- ```
65
-
66
- ## Quickstart
67
-
68
- ````python
69
- from dataclasses import dataclass
70
- from weakincentives import (
71
- MarkdownSection,
72
- Prompt,
73
- Tool,
74
- ToolResult,
75
- parse_structured_output,
76
- )
77
-
78
- @dataclass
79
- class ResearchGuidance:
80
- topic: str
81
-
82
- @dataclass
83
- class SourceLookup:
84
- source_id: str
85
-
86
- @dataclass
87
- class SourceDetails:
88
- source_id: str
89
- title: str
90
-
91
- @dataclass
92
- class ResearchSummary:
93
- summary: str
94
- citations: list[str]
95
-
96
- def lookup_source(params: SourceLookup) -> ToolResult[SourceDetails]:
97
- details = SourceDetails(source_id=params.source_id, title="Ada Lovelace Archive")
98
- return ToolResult(message=f"Loaded {details.title}", value=details)
99
-
100
- catalog_tool = Tool[SourceLookup, SourceDetails](
101
- name="catalog_lookup",
102
- description="Look up a primary source identifier and return details.",
103
- handler=lookup_source,
104
- )
105
-
106
- task_section = MarkdownSection[ResearchGuidance](
107
- title="Task",
108
- template=(
109
- "Research ${topic}. Use `catalog_lookup` for citations and reply with a "
110
- "JSON summary."
111
- ),
112
- key="research.task",
113
- tools=[catalog_tool],
114
- )
115
-
116
- prompt = Prompt[ResearchSummary](
117
- ns="examples/research",
118
- key="research.run",
119
- name="research_prompt",
120
- sections=[task_section],
121
- )
122
-
123
- rendered = prompt.render(ResearchGuidance(topic="Ada Lovelace"))
124
- print(rendered.text)
125
- print([tool.name for tool in rendered.tools])
126
-
127
- reply = """```json
128
- {
129
- "summary": "Ada Lovelace pioneered computing...",
130
- "citations": ["catalog_lookup:ada-archive"]
131
- }
132
- ```"""
133
- result = parse_structured_output(reply, rendered)
134
- print(result.summary)
135
- print(result.citations)
136
- ````
137
-
138
- The rendered prompt text stays deterministic, tool metadata travels with the prompt,
139
- and `parse_structured_output` enforces your dataclass contract.
140
-
141
- ## Sessions and Built-in Tools
142
-
143
- Session state turns prompt output and tool calls into durable data. Built-in planning
144
- and virtual filesystem sections register reducers on the provided session.
145
-
146
- ```python
147
- from weakincentives.session import Session, select_latest
148
- from weakincentives.tools import (
149
- PlanningToolsSection,
150
- Plan,
151
- VfsToolsSection,
152
- VirtualFileSystem,
153
- )
154
-
155
- session = Session()
156
- planning_section = PlanningToolsSection(session=session)
157
- vfs_section = VfsToolsSection(session=session)
158
-
159
- prompt = Prompt[ResearchSummary](
160
- ns="examples/research",
161
- key="research.session",
162
- sections=[task_section, planning_section, vfs_section],
163
- )
164
-
165
- active_plan = select_latest(session, Plan)
166
- vfs_snapshot = select_latest(session, VirtualFileSystem)
167
- ```
168
-
169
- Use `session.select_all(...)` or the helpers in `weakincentives.session` to drive UI
170
- state, persistence, or audits after each adapter run.
171
-
172
- ## Adapter Integrations
173
-
174
- Adapters stay optional and only load their dependencies when you import them.
175
-
176
- ```python
177
- from weakincentives.adapters.openai import OpenAIAdapter
178
- from weakincentives.events import InProcessEventBus
179
- from weakincentives.session import Session
180
- from weakincentives.tools import Plan
181
-
182
- bus = InProcessEventBus()
183
- session = Session(bus=bus)
184
-
185
- adapter = OpenAIAdapter(
186
- model="gpt-4o-mini",
187
- client_kwargs={"api_key": "sk-..."},
188
- )
189
-
190
- response = adapter.evaluate(
191
- prompt,
192
- ResearchGuidance(topic="Ada Lovelace"),
193
- bus=bus,
194
- )
195
-
196
- plan_history = session.select_all(Plan)
197
- ```
198
-
199
- `InProcessEventBus` publishes `ToolInvoked` and `PromptExecuted` events for the
200
- session (or any other subscriber) to consume.
201
-
202
- ## Development Setup
203
-
204
- 1. Install Python 3.14 (for example with `pyenv install 3.14.0`).
205
-
206
- 1. Install `uv`, then bootstrap the environment and hooks:
207
-
208
- ```bash
209
- uv sync
210
- ./install-hooks.sh
211
- ```
212
-
213
- 1. Run checks with `uv run` so everything shares the managed virtualenv:
214
-
215
- - `make format` / `make format-check`
216
- - `make lint` / `make lint-fix`
217
- - `make typecheck` (Ty + Pyright, warnings fail the build)
218
- - `make test` (pytest via `build/run_pytest.py`, 100% coverage enforced)
219
- - `make check` (aggregates the quiet checks above plus Bandit, Deptry, pip-audit,
220
- and markdown linting)
221
-
222
- ## Documentation
223
-
224
- - `AGENTS.md` — operational handbook and contributor workflow.
225
- - `specs/` — design docs for prompts, planning tools, and adapters.
226
- - `ROADMAP.md` — upcoming feature sketches.
227
- - `docs/api/` — API reference material.
228
-
229
- ## License
230
-
231
- Apache 2.0 • Status: Alpha (APIs may change between releases)