Skip to content

Organizing Issues (best practices) and some Refactoring Opportunities #22

Description

@MegumiinUwU

Fix those when time permits

anyone fixing one or more of them add a comment with which ones you fixed

  • Unstructured/Unordered Imports: Throughout the tools (especially in webfetch.py and bash.py), standard library imports are mixed with third-party imports, violating PEP-8.
  • Missing Docstrings: A vast majority of files (e.g., agent/api/routes/health.py, agent/tools/read_tool/read.py, agent/services/linters/base.py) are missing module-level and class-level docstrings explaining their purpose within the agent framework.
  • Multiple imports on one line: src/agent/tools/mcp_fetch/mcp_tool_fetch.py (Line 4) has import subprocess, json.
  • unnecessary Elif: src/agent/tools/bash_tool/bash.py (Line 168) and server.py (Line 87) use elif statements immediately after a return or raise statement, which is redundant.

Refactoring Opportunities

Massive Code Duplication (Prompts & Schemas): src/agent/utils/init.py reported multiple identical code blocks duplicated across agent.graph.prompts.generator and agent.graph.prompts.planner (specifically the 20+ lines of PUBLIC UPDATE RULES). Similarly, agent.graph.schemas.generator and agent.graph.schemas.planner duplicate the exact same Pydantic field_validator methods for normalizing text fields.
Fix: Extract the update rules into a shared constants.py file, and create a BaseGraphSchema class that both the planner and generator inherit from.

Bash Tool Parsing: Refactor _parse_command_chain in bash.py to use Python's built-in shlex module (shlex.split()). It handles shell syntax, quotes, and escapes accurately out of the box, replacing 30 lines of fragile regex code with a few robust lines.

Tool Signatures: Multiple Langchain tools (bash.py, glob.py, grep.py, webfetch.py) are overriding the BaseTool._run and _arun methods and altering the number of expected arguments (e.g., removing *args or **kwargs variadics). This breaks the Liskov Substitution Principle and can cause LangGraph/LangChain executor callbacks to fail when they expect standard BaseTool signatures. Ensure **kwargs is accepted in the overridden methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions