Skip to content

Code style: agent/ without comments, its tools as methods - #92

Merged
utkarsh5026 merged 1 commit into
mainfrom
code-style-agent
Oct 17, 2026
Merged

utkarsh5026 merged 1 commit into
mainfrom
code-style-agent

Conversation

@utkarsh5026

Copy link
Copy Markdown
Owner

Step 3 of the code style work, for agent/ (after #90 and #91).

What changed

Comments. All 133 # comments in agent/ are gone. Each one's content now lives in a docstring (Budget's fields, AgentAnswer's, Toolkit's attributes, what READ_PREFIXES and _SECRETS cover) 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, and tools() just lists them:

def tools(self):
    return [self.find_functions, self.function_health, self.function_errors, ...]

A tool's docstring is what the model reads, so internal notes that were comments inside bucket_details and find_files didn't go into those docstrings. They moved to small helpers with docstrings of their own: _require_bucket, _account_block and _matching.

Long functions split into steps:

Before After
S3Toolkit._triggers: complexity 30, 110 lines s3_triggers built on _pairs_in_bucket / _pairs_for_function; a _LinkChecker dataclass that reads each function, policy and listing once; plus _triggers_summary and _triggers_next
trigger_findings: complexity 13 _not_allowed and _arrival_findings, which is built from _missed_by_upload_kind, _missed_by_case, _nothing_arrived and _runs_against_arrivals
count_arrivals: complexity 11 _count_covered for each file the filter covers
runtime.as_tool: complexity 11 _asked_for, _failed / _aws_error and _reported
harness.stream_turn: complexity 12 _model_messages, _count_usage and _stop_reason
summarize_health: complexity 11 _health_groups

Rule exceptions. Intentional broad excepts carry # noqa: BLE001: a tool never raises into the agent loop, and a model error becomes answer.error. Public functions whose parameters really belong to them, and the tools the model calls, carry # noqa: PLR0913.

agent/ comes off ruff.toml's per-file-ignores and tests/test_style.py's COMMENTS_LEFT.

Nothing the model or a user sees changed

No CHANGELOG entry: nothing a user sees changes.

🤖 Generated with Claude Code

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>
@utkarsh5026
utkarsh5026 merged commit 6dd46ed into main Oct 17, 2026
8 checks passed
@utkarsh5026
utkarsh5026 deleted the code-style-agent branch October 17, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant