Skip to content

core: refactor tool system to remove agent context from initialization#21052

Open
thdxr wants to merge 6 commits intodevfrom
tool-optimization
Open

core: refactor tool system to remove agent context from initialization#21052
thdxr wants to merge 6 commits intodevfrom
tool-optimization

Conversation

@thdxr
Copy link
Copy Markdown
Member

@thdxr thdxr commented Apr 4, 2026

Summary

Refactor the tool system to simplify initialization and remove unnecessary agent context dependencies. This makes tool behavior more predictable and consistent across different agents.

Changes

  • Tool initialization: Remove agent parameter from Tool.init() calls - tools no longer need to know which agent is using them during initialization
  • ToolRegistry API: Replace hardcoded named property with cleaner fromID() method for dynamic tool lookup
  • TaskTool: Display all available subagents without permission filtering during initialization
  • Skill.fmt: Sort skills alphabetically in both verbose and non-verbose output modes for consistent display

Why

Previously, tools received agent context during initialization which led to:

  1. Different tool behavior depending on which agent called init()
  2. Hardcoded references to specific tools (registry.named.task, registry.named.read)
  3. Complex caching logic to handle different agent contexts

Now tools are initialized once and behave consistently regardless of the calling agent.

thdxr added 3 commits April 4, 2026 16:18
Simplify tool initialization by removing unnecessary agent context parameter from
tool.init() calls. This makes tool behavior more predictable and consistent
regardless of which agent is using them.

Replace hardcoded named tool references (registry.named.task, registry.named.read)
with a cleaner fromID() lookup method that works for any tool.

Update TaskTool to display all available subagents without permission-based
filtering, making it easier to discover and use subagents from any context.
Skills are now displayed in alphabetical order when listing available
skills, making it easier for users to locate specific skills in the
output.
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@thdxr
Copy link
Copy Markdown
Member Author

thdxr commented Apr 4, 2026

fyi this removes the agent permission filtering from tool init - we'll need to add that back at execution time instead. right now task/skill tools show everything regardless of whether the agent can actually use them.

thdxr added 3 commits April 5, 2026 17:56
Document two approaches for handling synthetic messages in prompt hooks:
- Option 1: Separate PromptMessage type for lightweight prompt surgery
- Option 2: PromptEditor API with append/prepend/insert mutators

This enables plugin developers to inject instructions or context into prompts without manually fabricating message IDs and timestamps. The design supports resumable sessions while keeping the API simple for common prompt manipulation use cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant