Apply review feedback: per-mode breaker split, adapter runner classes, docs fixes (#9, #10, #11)#12
Open
kamil-duszynski-dna wants to merge 3 commits into
Open
Apply review feedback: per-mode breaker split, adapter runner classes, docs fixes (#9, #10, #11)#12kamil-duszynski-dna wants to merge 3 commits into
kamil-duszynski-dna wants to merge 3 commits into
Conversation
Address reviewer comments on the core breaker: - Split CircuitBreaker into a base + per-mode strategies (_BudgetGuardBreaker / _LoopKillerBreaker); the public constructor dispatches on `mode`, so each strategy is free of mode branching and the `is None` limit checks disappear. - Make Mode an Enum; replace the hand-rolled mode assertion with coerce_mode (accepts a Mode member or its string value). - Move numeric guards to core/_numbers.py: is_positive_integer (tri-state) and is_non_negative_finite; drop the _describe helper. - Remove the dead `return` after _trip (which is NoReturn). - Rename set_token_snapshot -> set_tokens and TokenMetrics/ExtractedTokens fields input/output -> input_tokens/output_tokens. Tests, README and AGENTS.md updated. mypy --strict clean.
- Clarify the type-check statement: the package (src/) is mypy --strict clean via `python -m mypy`; the test suite isn't held to strict typing, so bare `mypy --strict .` reports errors. - Sort the repository-layout tree (dirs before files, core first) and add the previously-missing core/_numbers.py entry.
Drop the four identically-named with_circuit_breaker functions in favour of
per-adapter OOP runners (the word "with" collided with the keyword and the
duplicated names were a code smell):
- Add CircuitBreakerRunner base (_runner.py): captures the breaker config,
mints a fresh breaker per run, gates the preflight estimator, resolves
on_trip, and implements the context-manager protocol.
- Each adapter exposes a distinct subclass with a unified run() method:
OpenAIAgentsCircuitBreakerRunner, LangChainCircuitBreakerRunner,
ClaudeAgentCircuitBreakerRunner, LangGraphCircuitBreakerRunner.
- Canonical usage is a context manager:
with OpenAIAgentsCircuitBreakerRunner(agent) as safe:
await safe.run(...)
Update adapter exports, tests (incl. context-manager coverage), README and
AGENTS.md. mypy --strict clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses three rounds of reviewer feedback. The branch bundles issues
#9, #10 and #11 as three focused commits.
CircuitBreakerby mode and apply assortedreview notes.
with_circuit_breakerfunctions with per-adapterOOP runner classes.
The package stays
mypy --strictclean and the full suite is green(98 passed).
#9 — Split
CircuitBreakerby mode + review cleanupsCircuitBreaker(mode=...)is nowa constructor that dispatches to internal
_BudgetGuardBreaker/_LoopKillerBreaker. Each strategy is free of mode branching, so theper-method
is Nonelimit checks are gone.Modeis now anEnum(Mode.BUDGET_GUARD/Mode.LOOP_KILLER). Thehand-rolled mode assertion is replaced by
coerce_mode, which still acceptsthe string values (
"budget-guard"/"loop-killer") for ergonomics.core/_numbers.py:is_positive_integer(three-state) and
is_non_negative_finite; the_describehelper is removed.returnafter_trip(which isNoReturn).set_token_snapshot→set_tokens;TokenMetrics/ExtractedTokensfieldsinput/output→input_tokens/output_tokens.#10 — Documentation fixes
python -m mypy/mypy --strict srcare clean, butmypy --strict .reportserrors because the test suite isn't held to strict typing. The wording now says
the package is strict-clean.
corefirst)and added the previously-missing
core/_numbers.pyentry.#11 — Adapter runner classes (drop
with_circuit_breaker)Removed the four identically-named
with_circuit_breakerfunctions (thewithprefix collided with the keyword and the duplicated names were a smell).New base
CircuitBreakerRunner(_runner.py): captures the breakerconfig, mints a fresh breaker per
run, gates the preflight estimator,resolves
on_trip, and implements the context-manager protocol.One distinct subclass per adapter with a unified
run()method:OpenAIAgentsCircuitBreakerRunner,LangChainCircuitBreakerRunner,ClaudeAgentCircuitBreakerRunner,LangGraphCircuitBreakerRunner.Canonical usage is a context manager:
Breaking changes
Pre-1.0; per
AGENTS.mdwe prefer cleaner APIs over compat shims.with_circuit_breaker(...)→<Framework>CircuitBreakerRunner(...)used as acontext manager, with a unified
.run()method.Modeis anEnum(string values still accepted on input).CircuitBreaker.set_token_snapshot→set_tokens.TokenMetrics.input/.output→.input_tokens/.output_tokens.Testing
python -m mypy— clean (20 source files).python -m pytest— 98 passed (includes new context-manager coverage peradapter).