Repository navigation
Code style: agent/ without comments, its tools as methods - #92
Merged
Merged
Conversation
Every # comment in agent/ is gone, into docstrings (Budget's fields, AgentAnswer's, Toolkit's attributes, what READ_PREFIXES and _SECRETS cover) or names (_OVERTIME_SECONDS, _NEAR_TIMEOUT, _SIZE_WORKERS, _checked_zone). The toolkits' tools are methods now, and tools() lists them, instead of seven nested functions in one 150-line tools(). What the model reads is unchanged: every tool's name, description and argument schema, as LangChain builds them, is byte-for-byte the same as on main. Notes about how a tool works inside moved to helpers' docstrings (_require_bucket, _account_block, _matching), since a tool's docstring is the model's. The long functions are split into steps: - S3Toolkit._triggers (complexity 30) is s3_triggers over _pairs_in_bucket / _pairs_for_function, a _LinkChecker that reads each function, policy and listing once, _triggers_summary and _triggers_next. - trigger_findings reads as its findings: _not_allowed, _arrival_findings (_missed_by_upload_kind, _missed_by_case, _nothing_arrived, _runs_against_arrivals); count_arrivals counts a covered file with _count_covered. - runtime.as_tool hands errors to _failed / _aws_error and fills the call in _reported; harness.stream_turn counts with _count_usage and stops by _stop_reason; summarize_health groups with _health_groups. agent/ is off ruff.toml's per-file-ignores and tests/test_style.py's comment allowances. The tests pass on 3.10 and on 3.13, where the agent loop's tests run (1,180 passed); every report renders as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Step 3 of the code style work, for
agent/(after #90 and #91).What changed
Comments. All 133
#comments inagent/are gone. Each one's content now lives in a docstring (Budget's fields,AgentAnswer's,Toolkit's attributes, whatREAD_PREFIXESand_SECRETScover) or in a name (_OVERTIME_SECONDS,_NEAR_TIMEOUT,_SIZE_WORKERS,_checked_zone, ...).Tools are methods. Each toolkit's
tools()used to define seven nested functions in one 150-line body. Now each tool is a method, andtools()just lists them:A tool's docstring is what the model reads, so internal notes that were comments inside
bucket_detailsandfind_filesdidn't go into those docstrings. They moved to small helpers with docstrings of their own:_require_bucket,_account_blockand_matching.Long functions split into steps:
S3Toolkit._triggers: complexity 30, 110 liness3_triggersbuilt on_pairs_in_bucket/_pairs_for_function; a_LinkCheckerdataclass that reads each function, policy and listing once; plus_triggers_summaryand_triggers_nexttrigger_findings: complexity 13_not_allowedand_arrival_findings, which is built from_missed_by_upload_kind,_missed_by_case,_nothing_arrivedand_runs_against_arrivalscount_arrivals: complexity 11_count_coveredfor each file the filter coversruntime.as_tool: complexity 11_asked_for,_failed/_aws_errorand_reportedharness.stream_turn: complexity 12_model_messages,_count_usageand_stop_reasonsummarize_health: complexity 11_health_groupsRule exceptions. Intentional broad excepts carry
# noqa: BLE001: a tool never raises into the agent loop, and a model error becomesanswer.error. Public functions whose parameters really belong to them, and the tools the model calls, carry# noqa: PLR0913.agent/comes offruff.toml'sper-file-ignoresandtests/test_style.py'sCOMMENTS_LEFT.Nothing the model or a user sees changed
mainbefore Code style: docstrings on their own lines, and checks that keep the rules #90, checked for all 14 tools on Python 3.13 with the reallangchain_core. That check also covers Code style: docstrings on their own lines, and checks that keep the rules #90's docstring reshape: LangChain strips the new leading newline.scriptedmodel, andAzureChatOpenAIover a mock transport).check/run.pypasses: ruff, imports, package, rules (0 errors), and pytest with 1,164 passed and 16 skipped.snapshot.py compareshows 319 of 321 outputs identical. The other two are the known traceback line numbers from Code style: docstrings on their own lines, and checks that keep the rules #90. The "lost" names are the two private methodss3_triggersreplaced:S3Toolkit._triggersand_triggers_tool.No CHANGELOG entry: nothing a user sees changes.
🤖 Generated with Claude Code