Skip to content

Conversation

@ctlai95
Copy link
Contributor

@ctlai95 ctlai95 commented Mar 26, 2025

Problem

Tool APIs are not consistent.

Solution

Create a tool util wrapper class around tools to delegate validation, execution, and previews of tools.

So now to use the tools we can do something like:

const tool = ToolUtils.tryFromToolUse(toolUse)

ToolUtils.validate(tool)
ToolUtils.requiresAcceptance(tool)
ToolUtils.queueDescription(tool)
ToolUtils.invoke(tool)

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions
Copy link

  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@ctlai95 ctlai95 marked this pull request as ready for review March 26, 2025 22:03
@ctlai95 ctlai95 requested review from a team as code owners March 26, 2025 22:03
@ctlai95
Copy link
Contributor Author

ctlai95 commented Mar 26, 2025

/retryBuilds

| { type: ToolType.FsWrite; tool: FsWrite }
| { type: ToolType.ExecuteBash; tool: ExecuteBash }

export class ToolUtils {
Copy link

Choose a reason for hiding this comment

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

what's the intent of this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was to have this be a helper class to interact with all the tools and to sort of enforce a common interface (requiresAcceptance, invoke, etc) so that we don't need to keep writing if-else or switch statements just to handle tools. This is how the CLI does it as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like a case where class-based inheritance would fit.

import { ToolResult, ToolResultContentBlock, ToolResultStatus, ToolUse } from '@amzn/codewhisperer-streaming'
import { InvokeOutput } from './toolShared'

export enum ToolType {
Copy link

Choose a reason for hiding this comment

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

I feel like this code is not extensible for when we support MCP-based tools. Can we revisit this after the prototype?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I need to think about how MCP will work here. Happy to revisit later

\`\`\`
using the \`executeBash\` tool.`
}
if (toolUse.name === 'fsWrite') {
Copy link

Choose a reason for hiding this comment

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

I know you didn't change this - but I feel like we should refactor this to have a cleaner interface. Having a giant if/else block doesn't seem like the right solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that was the goal of this PR to have the common interface across all the tools (I just didn't get to refactoring this part yet since @laileni-aws will be integrating his UI changes here)

Copy link

@mr-lee mr-lee left a comment

Choose a reason for hiding this comment

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

I'm approving to unblock - but I also think we need to refactor here.

"type": "shell",
"command": "npm",
"args": ["run", "watch"],
"type": "npm",
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason why this was changed? if it needs to be changed can you make it on master

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I accidentally committed this change to this branch in a previous commit. Here I'm reverting it back to what it is in master.

On another note, my vscode keeps trying to run watch using yarn instead of npm even in master. I noticed this happening for others as well so I'll make this change in master

@mr-lee mr-lee merged commit 8749cd7 into aws:feature/agentic-chat Mar 27, 2025
21 of 22 checks passed
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.

4 participants