Skip to content

refactor: reduce or remove tools/decorators.py adapter layer around tinyagent #430

@larock22

Description

@larock22

Summary

src/tunacode/tools/decorators.py currently owns a substantial adapter layer between TunaCode tool functions and tinyagent AgentTools. That may be more indirection than we need now that tinyagent handles native tool execution.

This issue is narrower than #388 and focuses specifically on whether base_tool(), file_tool(), to_tinyagent_tool(), and the custom JSON-schema helpers should continue to exist in their current form.

Why this should be revisited

Current flow:

plain async tool fn
  -> @base_tool / @file_tool
  -> to_tinyagent_tool()
  -> custom execute() wrapper
  -> tinyagent execute_tool_calls()

The adapter layer currently mixes several concerns:

  • exception normalization (ToolRetryError, ToolExecutionError, FileOperationError)
  • XML prompt/docstring injection
  • OpenAI-style parameter schema generation from Python signatures
  • tinyagent AgentTool construction
  • prompt-version metadata attachment

That boundary may still be justified, but it currently obscures a simple question: which of these behaviors are actually TunaCode-specific policy, and which are legacy glue that tinyagent can now handle directly?

Goal

Reduce the amount of custom adapter code between TunaCode tools and tinyagent unless a behavior is clearly required and cannot be delegated upstream.

Scope

Evaluate:

  • whether tools should still be authored as plain async functions plus decorators
  • whether to_tinyagent_tool() should shrink to a thin compatibility wrapper or disappear
  • whether custom JSON schema generation should be delegated to tinyagent
  • whether XML prompt loading and prompt-version tracking should be moved into smaller, isolated helpers
  • whether file-specific error mapping belongs in a decorator or in the tool implementations themselves

Constraints

  • Preserve current user-visible tool behavior
  • Preserve retry/error semantics that still matter to the agent loop
  • Preserve XML-backed tool descriptions where they are part of model steering
  • Preserve cancellation/abort behavior

Acceptance Criteria

  • Document what behavior in src/tunacode/tools/decorators.py is still necessary
  • Identify what tinyagent already provides natively
  • Propose the minimal boundary needed between TunaCode tools and tinyagent
  • If the layer remains, split mixed concerns so the code is easier to justify and maintain
  • If the layer is mostly redundant, outline the migration path to remove it

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode restructuring without behavior changetool-lifecycleTool call parsing, execution, and state management

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions