bbagents 0.1.0__tar.gz

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.
Files changed (113) hide show
  1. bbagents-0.1.0/GUIDE.md +210 -0
  2. bbagents-0.1.0/IMPLEMENTATION.md +61 -0
  3. bbagents-0.1.0/INVENTORY.md +75 -0
  4. bbagents-0.1.0/LICENSE +22 -0
  5. bbagents-0.1.0/MANIFEST.in +5 -0
  6. bbagents-0.1.0/MANUSCRIPT_ALIGNMENT.md +61 -0
  7. bbagents-0.1.0/PKG-INFO +80 -0
  8. bbagents-0.1.0/README.md +47 -0
  9. bbagents-0.1.0/RELEASING.md +46 -0
  10. bbagents-0.1.0/demos/README.md +46 -0
  11. bbagents-0.1.0/demos/__init__.py +1 -0
  12. bbagents-0.1.0/demos/autonomous_release_manager.py +642 -0
  13. bbagents-0.1.0/demos/pandemic_response.py +122 -0
  14. bbagents-0.1.0/demos/test_autonomous_release_manager.py +78 -0
  15. bbagents-0.1.0/demos/test_pandemic_response.py +13 -0
  16. bbagents-0.1.0/examples/README.md +363 -0
  17. bbagents-0.1.0/examples/__init__.py +1 -0
  18. bbagents-0.1.0/examples/bounded_execution.py +21 -0
  19. bbagents-0.1.0/examples/coding_organization.py +172 -0
  20. bbagents-0.1.0/examples/dependency_vulnerability_audit.py +237 -0
  21. bbagents-0.1.0/examples/durable_checkpoints.py +24 -0
  22. bbagents-0.1.0/examples/governed_memory.py +49 -0
  23. bbagents-0.1.0/examples/heterogeneous_model_organization.py +89 -0
  24. bbagents-0.1.0/examples/isolated_evaluation.py +44 -0
  25. bbagents-0.1.0/examples/langchain_integration.py +136 -0
  26. bbagents-0.1.0/examples/langfuse_tracing.py +37 -0
  27. bbagents-0.1.0/examples/langgraph_integration.py +241 -0
  28. bbagents-0.1.0/examples/langgraph_intervention.py +129 -0
  29. bbagents-0.1.0/examples/langsmith_tracing.py +24 -0
  30. bbagents-0.1.0/examples/local_model.py +42 -0
  31. bbagents-0.1.0/examples/model_routing_and_cache.py +154 -0
  32. bbagents-0.1.0/examples/oauth_migration_planner.py +187 -0
  33. bbagents-0.1.0/examples/recoverable_release.py +86 -0
  34. bbagents-0.1.0/examples/recovering_effects.py +50 -0
  35. bbagents-0.1.0/examples/repository_constraint_learning.py +131 -0
  36. bbagents-0.1.0/examples/secure_deployment.py +108 -0
  37. bbagents-0.1.0/examples/task_completion.py +35 -0
  38. bbagents-0.1.0/pyproject.toml +56 -0
  39. bbagents-0.1.0/setup.cfg +4 -0
  40. bbagents-0.1.0/src/bbagents/__init__.py +70 -0
  41. bbagents-0.1.0/src/bbagents/compaction.py +38 -0
  42. bbagents-0.1.0/src/bbagents/context.py +124 -0
  43. bbagents-0.1.0/src/bbagents/core.py +49 -0
  44. bbagents-0.1.0/src/bbagents/decision.py +225 -0
  45. bbagents-0.1.0/src/bbagents/evaluation.py +114 -0
  46. bbagents-0.1.0/src/bbagents/execution.py +216 -0
  47. bbagents-0.1.0/src/bbagents/experiments.py +172 -0
  48. bbagents-0.1.0/src/bbagents/governed_memory.py +85 -0
  49. bbagents-0.1.0/src/bbagents/hooks.py +78 -0
  50. bbagents-0.1.0/src/bbagents/integrations/__init__.py +1 -0
  51. bbagents-0.1.0/src/bbagents/integrations/filesystem_skills.py +101 -0
  52. bbagents-0.1.0/src/bbagents/integrations/langfuse.py +115 -0
  53. bbagents-0.1.0/src/bbagents/integrations/langgraph.py +99 -0
  54. bbagents-0.1.0/src/bbagents/integrations/langsmith.py +117 -0
  55. bbagents-0.1.0/src/bbagents/integrations/ollama.py +85 -0
  56. bbagents-0.1.0/src/bbagents/intervention.py +510 -0
  57. bbagents-0.1.0/src/bbagents/learning.py +55 -0
  58. bbagents-0.1.0/src/bbagents/lifecycle.py +168 -0
  59. bbagents-0.1.0/src/bbagents/memory.py +157 -0
  60. bbagents-0.1.0/src/bbagents/models.py +199 -0
  61. bbagents-0.1.0/src/bbagents/observability.py +216 -0
  62. bbagents-0.1.0/src/bbagents/optimization.py +47 -0
  63. bbagents-0.1.0/src/bbagents/organization.py +40 -0
  64. bbagents-0.1.0/src/bbagents/persistence.py +274 -0
  65. bbagents-0.1.0/src/bbagents/planning.py +278 -0
  66. bbagents-0.1.0/src/bbagents/promotion.py +67 -0
  67. bbagents-0.1.0/src/bbagents/provenance.py +37 -0
  68. bbagents-0.1.0/src/bbagents/py.typed +1 -0
  69. bbagents-0.1.0/src/bbagents/recovery.py +184 -0
  70. bbagents-0.1.0/src/bbagents/reference.py +5 -0
  71. bbagents-0.1.0/src/bbagents/retrieval.py +122 -0
  72. bbagents-0.1.0/src/bbagents/revisions.py +161 -0
  73. bbagents-0.1.0/src/bbagents/runtime.py +218 -0
  74. bbagents-0.1.0/src/bbagents/safety.py +85 -0
  75. bbagents-0.1.0/src/bbagents/skills.py +57 -0
  76. bbagents-0.1.0/src/bbagents/tools.py +61 -0
  77. bbagents-0.1.0/src/bbagents.egg-info/PKG-INFO +80 -0
  78. bbagents-0.1.0/src/bbagents.egg-info/SOURCES.txt +111 -0
  79. bbagents-0.1.0/src/bbagents.egg-info/dependency_links.txt +1 -0
  80. bbagents-0.1.0/src/bbagents.egg-info/requires.txt +20 -0
  81. bbagents-0.1.0/src/bbagents.egg-info/top_level.txt +1 -0
  82. bbagents-0.1.0/tests/test_coding_organization_example.py +45 -0
  83. bbagents-0.1.0/tests/test_decision.py +132 -0
  84. bbagents-0.1.0/tests/test_dependency_vulnerability_audit_example.py +31 -0
  85. bbagents-0.1.0/tests/test_durable_intervention.py +49 -0
  86. bbagents-0.1.0/tests/test_evaluation.py +45 -0
  87. bbagents-0.1.0/tests/test_example_smoke.py +36 -0
  88. bbagents-0.1.0/tests/test_execution.py +80 -0
  89. bbagents-0.1.0/tests/test_experiments.py +127 -0
  90. bbagents-0.1.0/tests/test_framework_contracts.py +155 -0
  91. bbagents-0.1.0/tests/test_governance.py +153 -0
  92. bbagents-0.1.0/tests/test_heterogeneous_model_organization_example.py +12 -0
  93. bbagents-0.1.0/tests/test_intervention.py +221 -0
  94. bbagents-0.1.0/tests/test_langfuse_integration.py +115 -0
  95. bbagents-0.1.0/tests/test_langgraph_integration_example.py +19 -0
  96. bbagents-0.1.0/tests/test_langgraph_intervention_example.py +13 -0
  97. bbagents-0.1.0/tests/test_langsmith_integration.py +118 -0
  98. bbagents-0.1.0/tests/test_lifecycle.py +106 -0
  99. bbagents-0.1.0/tests/test_memory_learning.py +67 -0
  100. bbagents-0.1.0/tests/test_model_routing_and_cache_example.py +22 -0
  101. bbagents-0.1.0/tests/test_models.py +74 -0
  102. bbagents-0.1.0/tests/test_oauth_migration_example.py +22 -0
  103. bbagents-0.1.0/tests/test_ollama.py +58 -0
  104. bbagents-0.1.0/tests/test_optimization.py +10 -0
  105. bbagents-0.1.0/tests/test_persistence.py +54 -0
  106. bbagents-0.1.0/tests/test_planning.py +117 -0
  107. bbagents-0.1.0/tests/test_readme_example.py +71 -0
  108. bbagents-0.1.0/tests/test_recovery.py +107 -0
  109. bbagents-0.1.0/tests/test_repository_constraint_learning_example.py +31 -0
  110. bbagents-0.1.0/tests/test_retrieval.py +80 -0
  111. bbagents-0.1.0/tests/test_runtime_safety.py +44 -0
  112. bbagents-0.1.0/tests/test_secure_deployment_example.py +38 -0
  113. bbagents-0.1.0/tests/test_skills.py +27 -0
@@ -0,0 +1,210 @@
1
+ # BrilBerry Agents (`bbagents`)
2
+
3
+ BrilBerry Agents is a provider-neutral reference toolkit for modeling and enforcing
4
+ the plans, policies, memory, learning, and organizational structure of agent systems.
5
+ It can run independently or complement orchestration frameworks such as LangGraph
6
+ and integration frameworks such as LangChain.
7
+
8
+ The package turns the conceptual Python examples from *Agent Engineering* into
9
+ small, typed, executable components. It deliberately has no model-provider or
10
+ storage dependency.
11
+
12
+ The package is an alpha reference implementation. Its stable boundary is the set of
13
+ typed values and protocols; production applications should supply their own model,
14
+ storage, sandbox, and telemetry adapters.
15
+
16
+ ## Install for development
17
+
18
+ ```console
19
+ python -m pip install -e '.[dev]'
20
+ pytest
21
+ ```
22
+
23
+ Python 3.11 or newer is required.
24
+
25
+ ## Where it fits
26
+
27
+ `bbagents` is not intended to replace LangChain or LangGraph. LangChain supplies a
28
+ broad ecosystem of model, tool, retriever, and provider integrations. LangGraph
29
+ supplies durable, stateful orchestration, checkpointing, streaming, and
30
+ human-in-the-loop execution. `bbagents` supplies the application-level plans,
31
+ policies, bounded context, versioned state, memory records, learning procedures,
32
+ roles, and governance rules that can run inside those systems.
33
+
34
+ These primitives can be composed into an application-specific **agent harness**:
35
+ the layer that assembles context, constrains actions, applies policy, and captures
36
+ feedback around a model. `bbagents` does not impose a universal harness or own the
37
+ outer execution loop; applications and orchestration frameworks retain that role.
38
+
39
+ The [manuscript alignment audit](MANUSCRIPT_ALIGNMENT.md) maps the current book to
40
+ implemented contracts and records production concerns still owned by applications.
41
+
42
+ For small deterministic workflows, the package can run by itself. In a larger
43
+ application, LangGraph can own the outer execution loop while graph nodes use
44
+ `bbagents` primitives. LangChain models and tools can be connected through narrow
45
+ adapters without making them required dependencies.
46
+
47
+ ## Minimal example
48
+
49
+ ```python
50
+ from bbagents import AgentState, FunctionTool, Observation, Plan, PlanStep, ToolCall, ToolRegistry
51
+ from bbagents.observability import InMemoryTrace
52
+ from bbagents.reference import PlanningAgent
53
+
54
+ tools = ToolRegistry([
55
+ FunctionTool(
56
+ "inspect",
57
+ "Inspect a named component",
58
+ lambda component: Observation("inspect", f"inspected {component}"),
59
+ )
60
+ ])
61
+
62
+ state = AgentState("Inspect authentication", Plan(
63
+ "Inspect authentication",
64
+ [PlanStep("inspect", "Inspect authentication")],
65
+ ))
66
+
67
+ agent = PlanningAgent(
68
+ tools,
69
+ lambda state, step: [ToolCall("inspect", {"component": "authentication"})],
70
+ trace=InMemoryTrace(),
71
+ )
72
+ agent.run(state)
73
+ assert state.completed
74
+ ```
75
+
76
+ The root namespace is intentionally limited to the common planning, action, tool,
77
+ and decision contracts. Import specialised components from their module, such as
78
+ `bbagents.intervention`, `bbagents.models`, `bbagents.safety`, or
79
+ `bbagents.observability`.
80
+
81
+ ## Examples
82
+
83
+ Runnable examples include:
84
+
85
+ - [`langgraph_integration.py`](examples/langgraph_integration.py), which lets
86
+ LangGraph own orchestration and checkpointing while graph nodes use `bbagents`;
87
+ - [`langgraph_intervention.py`](examples/langgraph_intervention.py), which pauses a
88
+ governed action through LangGraph and resumes it with a typed human response;
89
+ - [`coding_organization.py`](examples/coding_organization.py), which coordinates
90
+ persistent roles under ownership, dependency, and governance rules;
91
+ - [`dependency_vulnerability_audit.py`](examples/dependency_vulnerability_audit.py),
92
+ which turns repository and advisory evidence into verified remediation steps;
93
+ - [`model_routing_and_cache.py`](examples/model_routing_and_cache.py), which routes
94
+ workloads under quality and latency constraints and caches stable results;
95
+ - [`secure_deployment.py`](examples/secure_deployment.py), which separates action
96
+ proposals, capabilities, approval, and side effects;
97
+ - [`repository_constraint_learning.py`](examples/repository_constraint_learning.py),
98
+ which separates retained experience from validated behavioral change;
99
+ - [`oauth_migration_planner.py`](examples/oauth_migration_planner.py), which
100
+ demonstrates dependent planning, evidence accumulation, and tracing;
101
+ - [`langchain_integration.py`](examples/langchain_integration.py), which adapts
102
+ LangChain models and tools without transferring ownership of the agent loop.
103
+ - [`langfuse_tracing.py`](examples/langfuse_tracing.py), which runs locally by
104
+ default and publishes nested traces to Langfuse when configured;
105
+ - [`langsmith_tracing.py`](examples/langsmith_tracing.py), which publishes the
106
+ same trace hierarchy to LangSmith as an alternative integration.
107
+
108
+ The [`examples/README.md`](examples/README.md) explains the goals and architectural
109
+ boundaries of each example.
110
+
111
+ ## Modules and manuscript provenance
112
+
113
+ | Module | Adapted concepts |
114
+ |---|---|
115
+ | `core` | Provider-neutral models and observations (Chapters 6–8) |
116
+ | `tools` | Tool schemas, registries, and deterministic invocation (Chapter 4) |
117
+ | `planning` | Explicit plans, dependencies, execution, and traces (Chapter 7) |
118
+ | `runtime` | First-class actions, policy checks, results, and retries (Chapter 8) |
119
+ | `decision` | Structured model proposals with bounded context, validation, and traces (Chapters 2, 5, 7) |
120
+ | `skills` | Versioned authored guidance, progressive discovery/loading, and provenance (Chapters 3, 8, 13) |
121
+ | `evaluation` | Separate response, transcript, and environment evidence; graders and repeated-trial reports (Chapter 5) |
122
+ | `models` | Role-scoped heterogeneous model selection and independent review (Chapters 6, 12) |
123
+ | `intervention` | Human-intervention requests, explicit delegation, and action gating (Chapters 8, 13) |
124
+ | `context` | Budgeted context views, state projection, and summarization contracts (Chapters 2, 3, 9) |
125
+ | `retrieval` | Provider-neutral evidence retrieval and context augmentation (Chapter 3) |
126
+ | `memory` | Episodic/semantic/procedural records and retrieval (Chapter 9) |
127
+ | `learning` | Experience, generalization, validation, and promotion (Chapter 10) |
128
+ | `organization` | Roles, messages, delegation, and governance (Chapters 6, 11) |
129
+ | `optimization` | Model cost estimates, routing constraints, and caching (Chapter 12) |
130
+ | `safety` | Trust, capabilities, approvals, and audit decisions (Chapter 13) |
131
+ | `observability` | Structured traces and evaluations (Chapter 5) |
132
+ | `persistence` | Versioned state snapshots and optimistic concurrency contracts (Chapters 8-11) |
133
+
134
+ ## Adaptation policy
135
+
136
+ The manuscript contains more than 120 Python fences. Many are pseudocode fragments,
137
+ provider examples, alternative versions of the same class, or deliberately incomplete
138
+ interfaces. The library does not concatenate them. It makes these adaptations:
139
+
140
+ - Repeated names such as `Action`, `Runtime`, `MemoryManager`, and `Policy` are merged
141
+ into one responsibility-specific implementation.
142
+ - Values shared between chapters use a single canonical definition.
143
+ - Model-generated planning is represented by injected callables. This keeps model
144
+ providers optional and leaves the deterministic loop testable.
145
+ - Model calls can use `DecisionRuntime`: applications adapt their provider to the
146
+ `LanguageModel` or `DecisionModel` protocol while the library applies explicit
147
+ output schemas, bounded context, validation, retries, and traces. Provider
148
+ adapters may return model identity, token usage, and request metadata.
149
+ - `ModelCatalog` and `ModelSelector` make heterogeneous routing explicit. The
150
+ optimization module retains a small compatibility wrapper but does not own a
151
+ second routing policy.
152
+ - Agent profiles name their permitted model identities. Applications retain control
153
+ of the selection policy, and can exclude a generator's model when assigning an
154
+ independent reviewer.
155
+ - Authored skills use `SkillDescriptor`, `Skill`, and the application-implemented
156
+ `SkillSource` protocol. Discovery can expose descriptions before loading an exact
157
+ version. Resource references remain opaque and required tools confer no authority.
158
+ - Evaluation uses `TrialEvidence` to keep answers, transcripts, and environment
159
+ outcomes separate. Applications provide graders and isolated trial execution;
160
+ `report_trials` distinguishes observed any-success and all-success counts without
161
+ assuming independent runs. Missing evidence is distinct from failure or success.
162
+ - Context summaries retain their original `summary_sources` for provenance and
163
+ review. Only `Context.content` is rendered to the model by the decision adapter.
164
+ - Storage examples include in-memory state and an optional JSON file-backed state
165
+ store. Corrupt or incompatible state files are treated as absent checkpoints;
166
+ vector databases, embeddings, and production stores remain adapters.
167
+ - Context selection, state persistence, and policy evaluation have explicit typed
168
+ contracts. Applications retain ownership of domain state, storage encoding,
169
+ summaries, and policy semantics.
170
+ - Human intervention is represented as typed, expiring requests, versioned
171
+ responses, explicit delegation, and action-runtime pending states. Identity
172
+ verification, UI, notification, and workflow suspension remain application
173
+ adapters.
174
+ - State, intervention, and memory records use stable identity and optimistic
175
+ concurrency. Applications retain ownership of database choice and encoding.
176
+ - Trace events carry portable run/span context and can be redacted before delivery
177
+ to in-memory or external tracing backends. Langfuse and LangSmith remain optional
178
+ adapters rather than framework dependencies.
179
+ - `Provenance` labels observations, memory, retrieved evidence, context, and
180
+ intervention requests with a source identity and trust level. Applications decide
181
+ how those labels affect their policies.
182
+ - The optional `bbagents[langgraph]` integration maps a stored intervention request
183
+ to LangGraph's durable interrupt and resume flow without requiring applications to
184
+ encode or validate intervention payloads themselves.
185
+ - Retrieval is a narrow evidence-to-context boundary. Applications supply document
186
+ loading, chunking, embeddings, vector stores, rerankers, and orchestration.
187
+ - Browser, computer-use, shell, filesystem, LangGraph, and vendor SDK examples are
188
+ omitted because they require external runtimes or create unsafe defaults.
189
+ - Prompt strings and chapter-specific OAuth/coding-agent examples remain examples,
190
+ not library behavior.
191
+ - Optimization and organizational data models are included, while speculative
192
+ scheduling and distributed execution are left to application runtimes.
193
+
194
+ ## Design constraints
195
+
196
+ The [implementation notes](IMPLEMENTATION.md) describe production contracts and
197
+ migration from the original synchronous reference runtimes. New modules cover
198
+ transactional persistence, bounded execution, effect recovery, task lifecycle,
199
+ governed memory/skills/procedure promotion, and isolated evaluation experiments.
200
+ The root API stays small; import these features from their responsibility modules.
201
+
202
+ - Standard library only at runtime.
203
+ - Default-deny capability policy when safety controls are used.
204
+ - Deterministic code owns loops, retries, policy checks, and state transitions.
205
+ - Probabilistic model behavior enters through narrow injected interfaces.
206
+ - No hidden global registries or network calls.
207
+ - No orchestration, checkpointing, or hosted tracing runtime: applications may use
208
+ LangGraph, Langfuse, LangSmith, or another platform directly. The default tracing
209
+ example runs locally and exports to Langfuse when configured; optional Langfuse
210
+ and LangSmith adapters translate planning events into nested hosted traces.
@@ -0,0 +1,61 @@
1
+ # Production contract implementation
2
+
3
+ Each phase is tested, committed, and pushed before the next phase starts.
4
+
5
+ 1. Persistence: implemented SQLite transactional checkpoints and failure-safe file
6
+ replacement. FileStateStore remains a single-writer reference backend.
7
+ 2. Deadlines and retries: implemented cooperative async deadlines, allowlisted
8
+ subprocess cancellation, typed failures and conservative retry policy.
9
+ 3. Recovery and idempotency: implemented durable intent, action/state binding,
10
+ leases, reconciliation, confirmed result reuse, and current-policy checks.
11
+ 4. Task lifecycle and enforcement: implemented persisted acceptance/progress state,
12
+ evidence completion policy, measured budgets, and bounded traced hooks.
13
+ 5. Skills, memory, and learning governance: implemented reviewed filesystem skills,
14
+ scope-bound access before ranking, revision history, promotion and rollback.
15
+ 6. Evaluation execution and compaction checks: implemented versioned datasets,
16
+ isolated fixture lifecycle, configuration binding, calibration records, empirical
17
+ variability, opt-in Wilson intervals and structured continuation probes.
18
+ 7. Cross-domain demonstrations: implemented durable release and pandemic-response
19
+ fixtures using shared approval, execution journal and completion contracts.
20
+ Added optional Ollama decisions and offline transport tests.
21
+
22
+ ## Migration notes
23
+
24
+ - Existing StateStore implementations and call sites remain valid. Use
25
+ `SQLiteStateStore` for concurrent local checkpoint updates. JSON codecs work as
26
+ with FileStateStore; database corruption is surfaced rather than reset silently.
27
+ - Run `PYTHONPATH=src python examples/durable_checkpoints.py` for a restart and
28
+ stale-writer example.
29
+ - Use `execution.AsyncActionRuntime` for bounded execution. Cancellation is
30
+ cooperative for Python handlers and propagates to the caller; subprocess children
31
+ are killed and reaped. Neither guarantees reversal of external effects. Legacy
32
+ synchronous ActionRuntime remains available and does not enforce deadlines.
33
+ - `SafeRetryPolicy` retries confirmed transient failures only when `retry_safe`
34
+ is explicitly set. An idempotency key alone does not prove a provider honors it.
35
+ - `RecoverableActionRuntime` requires stable execution IDs and JSON-compatible
36
+ action metadata/results. Uncertain outcomes and expired leases require an
37
+ application reconciler. A NOT_EXECUTED answer must rule out a late side effect;
38
+ the journal cannot discover this on its own. It never promises exactly-once.
39
+ - TaskLifecycle persists progress but does not schedule work. Hosts measure/report
40
+ time and spend and check budgets before dispatch. Domain completion rules implement
41
+ CompletionPolicy. HookRunner exposes before-model/action/result/completion boundaries;
42
+ AsyncActionRuntime wires action/result hooks and TaskLifecycle wires completion.
43
+ Only observational after-result hooks may fail open. Callbacks must honor cancellation.
44
+ - Install `[skills]` for YAML parsing. FilesystemSkillSource accepts a trusted
45
+ digest manifest and policy; discovery is lazy and resources need separate access.
46
+ It never executes scripts. Keep manifests outside agent-writable storage.
47
+ - RevisionRepository binds trusted identity/scope and retains candidate/activation
48
+ history. ScopedMemoryStore ranks only authorized scoped items. ProcedurePromoter
49
+ requires validation evidence; rejected proposals never replace the active version.
50
+ Use separate namespaces for memory and procedures. The reference aggregate is
51
+ intended for small local stores, not large distributed corpora.
52
+ - run_dataset requires a fresh context-managed environment per trial; hosts provide
53
+ actual isolation/reset. Runner identity/configuration mismatches fail loudly after
54
+ cleanup. Held-out cases are excluded by default. success_interval returns nothing
55
+ unless independent Bernoulli trials are explicitly justified; repeated task runs
56
+ are often correlated. CompactionGrader consumes observed continuation behavior,
57
+ not the summary's claims about itself.
58
+ - StateInterventionStore preserves approval lifecycle over StateStore; approved
59
+ requests can be revoked or expire after restart. Release publication remains a
60
+ simulated transactional index. `--model NAME` opts into an installed Ollama model;
61
+ no model download or real publication occurs implicitly.
@@ -0,0 +1,75 @@
1
+ # Manuscript snippet inventory
2
+
3
+ The current manuscript contains 102 Python code fences (audited 2026-10-21).
4
+ Chapter-local sketches are adapted into portable contracts rather than copied
5
+ verbatim. See [MANUSCRIPT_ALIGNMENT.md](MANUSCRIPT_ALIGNMENT.md) for the current
6
+ coverage and explicit production limitations.
7
+
8
+ | Chapter | Fences | Library disposition |
9
+ |---|---:|---|
10
+ | 2 - Models | 2 | `core`, `decision`; provider-neutral proposal boundary |
11
+ | 3 - Retrieval | 2 | `retrieval`, `context`; progressive loading and summary provenance |
12
+ | 4 — Tools | 20 | `tools`; vendor-specific calling loops omitted |
13
+ | 5 — Observability | 6 | `observability`, `evaluation`; optional Langfuse and LangSmith trace adapters included |
14
+ | 6 — Multi-agent systems | 8 | `core`, `models`, `organization`; application-owned coordination |
15
+ | 7 — Planning | 4 | `planning`; provider prompts and LangGraph wiring remain application code |
16
+ | 8 — Harnesses and runtimes | 16 | `runtime`, `safety`, `skills`; application harness composes contracts |
17
+ | 9 — Memory | 14 | `memory`; external vector and embedding providers represented by injection points |
18
+ | 10 — Learning | 8 | `learning`; model-driven generalization represented by an injected callable |
19
+ | 11 — Organizations | 6 | `organization`; domain-specific department examples omitted |
20
+ | 12 — Optimization | 7 | `models`, `optimization`; speculative/distributed schedulers omitted |
21
+ | 13 — Safety | 9 | `safety`; OS sandbox implementation and incident integrations omitted |
22
+ | 14 — Languages | 0 | Architectural discussion; no language runtime |
23
+
24
+ ## Reconciled definitions
25
+
26
+ - Chapter-local `Observation` definitions became `core.Observation`; memory safety uses
27
+ the separate and more specific `memory.MemoryRecord`.
28
+ - Tool calls and registries from Chapters 4 and 7 became `tools.ToolCall` and
29
+ `tools.ToolRegistry`.
30
+ - The several `Action` and `Runtime` sketches in Chapter 8 became `runtime.Action`,
31
+ `runtime.ActionResult`, and `runtime.ActionRuntime`.
32
+ - The abstract and concrete memory-manager sketches became `memory.MemoryStore`, a
33
+ deliberately small reference backend with replaceable embedding behavior.
34
+ - Repeated `Generalizer`, `Validator`, and `LearningRuntime` sketches became generic
35
+ callables plus `learning.LearningRuntime`.
36
+ - Context-window and stateful-execution concepts are represented by `context`:
37
+ applications project their own state while the library applies a budget and an
38
+ optional injected summarizer.
39
+ - The language-model decision boundary is represented by `decision`: a provider
40
+ adapter receives a typed task and bounded context, while validation and tracing
41
+ remain deterministic runtime behavior.
42
+ - Chapter 6 heterogeneous specialization is represented by `models`: organizational
43
+ agent profiles constrain model identity, while application policies select from
44
+ those models and can require reviewer independence.
45
+ - Runtime and safety concepts also include `intervention`: applications supply an
46
+ authenticated human interface and identity resolver while the library preserves
47
+ portable requests, responses, delegation, and pending action state.
48
+ - Chapter 3 retrieval concepts are represented by `retrieval.Retriever` and
49
+ `RetrievalAugmenter`, which normalize evidence and pass it through the shared
50
+ context budget without selecting a document store or embedding provider.
51
+ - Durable execution boundaries are represented by `persistence.StateStore` and its
52
+ versioned `StateSnapshot`; production encodings and backends remain application
53
+ adapters.
54
+ - Policy decisions have a generic, contextual `safety.Policy` protocol; the existing
55
+ capability policy remains the action-runtime implementation.
56
+ - Trace events carry portable run and span correlation identifiers without coupling
57
+ the package to a trace backend.
58
+ - Chapter 11 and Chapter 13 both define `Policy`; these were separated into
59
+ `organization.GovernancePolicy` and `safety.CapabilityPolicy` because they enforce
60
+ different boundaries.
61
+
62
+ ## Deliberate omissions
63
+
64
+ The seven production-contract phases now add `execution`, `recovery`, `hooks`,
65
+ `lifecycle`, `revisions`, `governed_memory`, `promotion`, `experiments`, and
66
+ `compaction`, plus filesystem-skill and local Ollama adapters. The implementation
67
+ and migration details are in [IMPLEMENTATION.md](IMPLEMENTATION.md). These are
68
+ portable adaptations, not new chapter-local snippets or a separate orchestrator.
69
+
70
+ The following snippets are educational integration examples rather than portable
71
+ library code: OpenAI/Anthropic/LangGraph calls, shell and repository mutation, browser
72
+ and computer use, deployment commands, concrete vector databases, distributed
73
+ coordination, and chapter-specific case studies. Including them would introduce
74
+ vendor coupling, unsafe defaults, or false production guarantees. The package exposes
75
+ interfaces where applications can add those integrations explicitly.
bbagents-0.1.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BrilBerry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,5 @@
1
+ include GUIDE.md INVENTORY.md MANUSCRIPT_ALIGNMENT.md IMPLEMENTATION.md
2
+ include RELEASING.md
3
+ recursive-include examples *.py *.md
4
+ recursive-include demos *.py *.md
5
+ recursive-include tests *.py
@@ -0,0 +1,61 @@
1
+ # Manuscript alignment audit
2
+
3
+ Audited against the local manuscript on 2026-10-21, including the harness, skills,
4
+ and evaluation revision in `c7c1bd8`. Subsequent chapter changes through `2f8c240`
5
+ predominantly concern figure formats and print presentation. Chapter-local Python
6
+ sketches illustrate architecture; the package does not promise identical classes
7
+ or production implementations of every sketch.
8
+
9
+ | Book concepts | Library support and disposition |
10
+ |---|---|
11
+ | Chapters 1-2: model/runtime separation | `core`, `decision`, `runtime`: typed proposals, schema validation, policy-controlled effects. |
12
+ | Chapter 3: retrieval, progressive loading, compaction | `retrieval`, `context`, `skills`: bounded assembly, attributable evidence, lazy skill-source protocol. Summaries retain source items separately from model-facing text. |
13
+ | Chapter 4: tools and protocols | `tools`: injectable deterministic invocation; provider APIs, MCP connections, and code-execution sandboxes remain adapters. |
14
+ | Chapter 5: observable execution and evaluation | `observability` plus optional tracing adapters; `evaluation` records configuration, response, transcript, actual outcome, duration, and cost. Graders can return insufficient evidence. Repeated-trial reporting separates any success from all successes. |
15
+ | Chapter 6: heterogeneous specialization | `models` catalog/selector, role-scoped candidates, independent reviewer exclusion; application owns coordination. |
16
+ | Chapter 7: explicit plans | `planning`: dependencies, cycle rejection, evidence, one-step executor; `reference` supplies the local synchronous runner. |
17
+ | Chapter 8: harness composition and skills | Existing primitives compose into application harnesses. `skills` adds version, owner, scope, provenance, resource references, and discovery/loading contracts. No universal harness or second graph scheduler is added. |
18
+ | Chapter 9: memory | `memory`, `governed_memory`, `revisions`, `provenance`, `persistence`: scoped access, versioned records, retrieval, checkpoints, history and rollback. Domain consolidation remains application-defined. |
19
+ | Chapter 10: runtime learning | `learning` and `promotion`: generalization, validation, versioned promotion evidence, activation history and rollback. Applications supply evaluation and promotion authority. |
20
+ | Chapter 11: organizations | `organization`, `safety`, `intervention`: typed roles, messages, governance and delegated approval; transport and scheduling remain adapters. |
21
+ | Chapter 12: optimization | `models`, `optimization`, `context`: selection constraints, caching, context budget. Distributed scheduling and speculative execution remain outside the library. |
22
+ | Chapter 13: safety | Capabilities, intervention fingerprints/expiry, provenance, trace redaction. Skills remain guidance and do not grant tool authority. Authentication, tenant isolation, OS restrictions, and configuration review must be supplied by the host. |
23
+ | Chapter 14: languages | Discussion and illustrative syntax; no language implementation is implied. |
24
+
25
+ ## Remaining implementation boundaries
26
+
27
+ The seven implementation phases are complete; see [IMPLEMENTATION.md](IMPLEMENTATION.md).
28
+ The following deployment responsibilities and reference-backend limitations remain:
29
+
30
+ - AsyncActionRuntime enforces cooperative deadlines; SubprocessAdapter kills and
31
+ reaps direct child processes. The legacy synchronous dispatcher does not enforce
32
+ deadlines. External side effects and descendants require application controls;
33
+ timeouts produce uncertain outcomes that must be reconciled before replay.
34
+ - ExecutionJournal and RecoverableActionRuntime now persist intent and confirmed
35
+ results, bind action/state fingerprints, protect live claims, and recheck current
36
+ authorization. Reconciler implementations establish external status; an unknown
37
+ result blocks replay, and no exactly-once guarantee is inferred from a journal.
38
+ - TaskLifecycle now persists task progress, acceptance evidence and measured budgets.
39
+ HookRunner provides bounded traced boundaries; application/orchestrator code owns
40
+ scheduling, budget measurement and recovery against the actual environment.
41
+ - FilesystemSkillSource parses reviewed SKILL.md files with optional PyYAML, verifies
42
+ scope, digest and path containment, and authorizes resources separately. Hosts
43
+ supply trusted manifests and identity; scripts remain subject to execution policy.
44
+ - Dataset trials now have isolated fixture lifecycle, held-out selection, configuration
45
+ checks, calibration reports and empirical variability. Wilson intervals require
46
+ an explicit independence assumption. Hosts still implement environment isolation
47
+ and supply representative datasets, human labels and domain graders. Unknown
48
+ grades count as trials without demonstrated success in the empirical rate.
49
+ - ScopedMemoryStore and RevisionRepository enforce host-defined access before
50
+ ranking and retain revision/activation history. ProcedurePromoter records validation
51
+ and rollback. Provenance labels still require trustworthy host assignment;
52
+ source records alone cannot prove summary fidelity.
53
+ - SQLiteStateStore now supplies transactional version checks across competing
54
+ writers. FileStateStore uses unique temporary files and failure cleanup, but
55
+ remains a single-writer reference backend.
56
+
57
+ These boundaries apply to both the release-manager and pandemic-response fixture.
58
+ The release demo persists approvals/state and reconciles its simulated index.
59
+ Release-note generation is deterministic by default; `--model` opts into an installed
60
+ local Ollama model. The adapter is tested with an offline transport; a live model
61
+ service and real package-index publication are not required or exercised by CI.
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.4
2
+ Name: bbagents
3
+ Version: 0.1.0
4
+ Summary: Provider-neutral building blocks for reliable AI agents
5
+ Author: BrilBerry
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/Brilberry/bbagents
8
+ Project-URL: Book, https://press.brilberry.com
9
+ Keywords: agents,ai,planning,tools,memory
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest>=8; extra == "dev"
20
+ Requires-Dist: ruff>=0.5; extra == "dev"
21
+ Requires-Dist: mypy>=1.10; extra == "dev"
22
+ Provides-Extra: langchain
23
+ Requires-Dist: langchain-core<2.0,>=1.0; extra == "langchain"
24
+ Provides-Extra: langgraph
25
+ Requires-Dist: langgraph<2.0,>=1.0; extra == "langgraph"
26
+ Provides-Extra: langfuse
27
+ Requires-Dist: langfuse>=4.0; extra == "langfuse"
28
+ Provides-Extra: langsmith
29
+ Requires-Dist: langsmith>=0.1.95; extra == "langsmith"
30
+ Provides-Extra: skills
31
+ Requires-Dist: PyYAML<7,>=6; extra == "skills"
32
+ Dynamic: license-file
33
+
34
+ # bbagents
35
+
36
+ Python building blocks for agent systems: tools, planning, model selection, memory,
37
+ human approval, tracing, and evaluation. Works with LangGraph or your own runtime.
38
+
39
+ Companion code for *Agentic AI: Architecture, Theory, and Practice*.
40
+ [Buy the book](https://press.brilberry.com).
41
+
42
+ <a href="https://press.brilberry.com">
43
+ <img src="assets/book-cover.png" alt="Agentic AI: Architecture, Theory, and Practice by Marco Dinacci" width="240" height="360">
44
+ </a>
45
+
46
+ Requires Python 3.11+.
47
+
48
+ ```sh
49
+ pip install -e '.[dev]'
50
+ pytest
51
+ ```
52
+
53
+ ## Complete application example
54
+
55
+ [Agent Stranded](https://github.com/Brilberry/agentstranded) is a more complete
56
+ example: an autonomous survival game using bbagents planning, tools, memory,
57
+ skills, communication, and tracing, with an optional local LLM. Its code,
58
+ documentation, and run instructions live in that separate repository.
59
+
60
+ ## Features
61
+
62
+ The previous README's approval/recovery example is preserved as
63
+ [recoverable_release.py](examples/recoverable_release.py).
64
+
65
+ - Typed tools, dependency-checked plans, structured model decisions and validation.
66
+ - Per-agent model selection, routing constraints, cost estimates and caching.
67
+ - Capability policies, human intervention, explicit delegation and LangGraph interrupts.
68
+ - Bounded async execution, retry policies, execution journals and effect reconciliation.
69
+ - Versioned checkpoints, SQLite persistence, task budgets and completion gates.
70
+ - Budgeted context, summarization contracts and provider-neutral retrieval (RAG).
71
+ - Scoped, revisioned memory and skills; evaluated and approved procedure promotion.
72
+ - Roles, messages, delegation and organizational governance.
73
+ - Structured traces, isolated evaluation trials and compaction-continuation checks.
74
+ - Optional Ollama, LangChain, LangGraph, LangSmith and Langfuse integrations.
75
+
76
+ No mandatory runtime dependencies. Applications own domain behavior and adapters.
77
+
78
+ See [examples](examples/), [demos](demos/) and the [guide](GUIDE.md).
79
+
80
+ Maintainers: see [release instructions](RELEASING.md) for publishing to PyPI.
@@ -0,0 +1,47 @@
1
+ # bbagents
2
+
3
+ Python building blocks for agent systems: tools, planning, model selection, memory,
4
+ human approval, tracing, and evaluation. Works with LangGraph or your own runtime.
5
+
6
+ Companion code for *Agentic AI: Architecture, Theory, and Practice*.
7
+ [Buy the book](https://press.brilberry.com).
8
+
9
+ <a href="https://press.brilberry.com">
10
+ <img src="assets/book-cover.png" alt="Agentic AI: Architecture, Theory, and Practice by Marco Dinacci" width="240" height="360">
11
+ </a>
12
+
13
+ Requires Python 3.11+.
14
+
15
+ ```sh
16
+ pip install -e '.[dev]'
17
+ pytest
18
+ ```
19
+
20
+ ## Complete application example
21
+
22
+ [Agent Stranded](https://github.com/Brilberry/agentstranded) is a more complete
23
+ example: an autonomous survival game using bbagents planning, tools, memory,
24
+ skills, communication, and tracing, with an optional local LLM. Its code,
25
+ documentation, and run instructions live in that separate repository.
26
+
27
+ ## Features
28
+
29
+ The previous README's approval/recovery example is preserved as
30
+ [recoverable_release.py](examples/recoverable_release.py).
31
+
32
+ - Typed tools, dependency-checked plans, structured model decisions and validation.
33
+ - Per-agent model selection, routing constraints, cost estimates and caching.
34
+ - Capability policies, human intervention, explicit delegation and LangGraph interrupts.
35
+ - Bounded async execution, retry policies, execution journals and effect reconciliation.
36
+ - Versioned checkpoints, SQLite persistence, task budgets and completion gates.
37
+ - Budgeted context, summarization contracts and provider-neutral retrieval (RAG).
38
+ - Scoped, revisioned memory and skills; evaluated and approved procedure promotion.
39
+ - Roles, messages, delegation and organizational governance.
40
+ - Structured traces, isolated evaluation trials and compaction-continuation checks.
41
+ - Optional Ollama, LangChain, LangGraph, LangSmith and Langfuse integrations.
42
+
43
+ No mandatory runtime dependencies. Applications own domain behavior and adapters.
44
+
45
+ See [examples](examples/), [demos](demos/) and the [guide](GUIDE.md).
46
+
47
+ Maintainers: see [release instructions](RELEASING.md) for publishing to PyPI.
@@ -0,0 +1,46 @@
1
+ # Publishing bbagents
2
+
3
+ The `publish.yml` workflow publishes to PyPI only when a GitHub release is
4
+ published. Ordinary pushes, tags alone, and draft releases do not upload anything.
5
+
6
+ ## One-time configuration
7
+
8
+ Configure PyPI Trusted Publishing for owner `Brilberry`, repository `bbagents`,
9
+ workflow `publish.yml`, and GitHub environment `pypi`. Create that environment in
10
+ GitHub settings; a required reviewer is recommended. No PyPI API token is needed.
11
+
12
+ ## Release
13
+
14
+ 1. Set the new version in `pyproject.toml`, commit, push, and check CI passes.
15
+ 2. Create a GitHub release targeting that commit with tag `vVERSION` (for example,
16
+ `v0.1.0` for the current version). Review its changes, then publish the release.
17
+ 3. Watch the **Publish to PyPI** workflow. Approve the `pypi` environment deployment
18
+ if required. It checks the tag/version, runs tests, lint and typing checks,
19
+ builds the wheel and source distribution, checks metadata, and smoke-tests the
20
+ installed wheel before uploading through Trusted Publishing.
21
+ 4. Verify https://pypi.org/project/bbagents/ and install in a fresh environment:
22
+
23
+ ```sh
24
+ python -m pip install bbagents==0.1.0
25
+ python -c "from bbagents import Plan, PlanStep"
26
+ ```
27
+
28
+ Use a new version for each release: published distribution filenames cannot be
29
+ reused. Do not attempt to replace a published release with different contents.
30
+ GitHub prereleases also trigger publishing; use a PEP 440 prerelease version such
31
+ as `0.2.0rc1` and tag `v0.2.0rc1` when that is intentional.
32
+
33
+ ## Local package checks (no upload)
34
+
35
+ With the development environment activated:
36
+
37
+ ```sh
38
+ python -m pip install build twine
39
+ python -m build
40
+ python -m twine check --strict dist/*
41
+ ```
42
+
43
+ Build from a clean checkout/output directory so old distributions are not mixed
44
+ into a new release. The CI job starts with an empty build directory.
45
+
46
+ See [PyPI Trusted Publishing](https://docs.pypi.org/trusted-publishers/using-a-publisher/).