Skip to content

Commit

Permalink
feat(tools): Support customizing Tool input description (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz authored Dec 11, 2023
1 parent cd86478 commit a9a1b2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/langchain/lib/src/agents/tools/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ abstract base class Tool<Options extends ToolOptions>
Tool({
required super.name,
required super.description,
final String inputDescription = 'The input to the tool',
super.returnDirect = false,
super.handleToolError,
}) : super(
Expand All @@ -194,7 +195,7 @@ abstract base class Tool<Options extends ToolOptions>
'properties': {
inputVar: {
'type': 'string',
'description': 'The input to the tool',
'description': inputDescription,
},
},
'required': ['input'],
Expand All @@ -219,6 +220,7 @@ abstract base class Tool<Options extends ToolOptions>
static Tool fromFunction<Options extends ToolOptions>({
required final String name,
required final String description,
final String inputDescription = 'The input to the tool',
required final FutureOr<String> Function(
String toolInput, {
Options? options,
Expand All @@ -229,6 +231,7 @@ abstract base class Tool<Options extends ToolOptions>
return _ToolFunc<Options>(
name: name,
description: description,
inputDescription: inputDescription,
func: func,
returnDirect: returnDirect,
handleToolError: handleToolError,
Expand Down Expand Up @@ -260,6 +263,7 @@ final class _ToolFunc<Options extends ToolOptions> extends Tool<Options> {
_ToolFunc({
required super.name,
required super.description,
super.inputDescription,
required this.func,
super.returnDirect = false,
super.handleToolError,
Expand Down
6 changes: 3 additions & 3 deletions packages/langchain/lib/src/agents/tools/calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ final class CalculatorTool extends Tool<ToolOptions> {
CalculatorTool()
: super(
name: 'calculator',
description: 'Useful for getting the result of a math expression. '
'The input to this tool should be a valid mathematical '
'expression that could be executed by a simple calculator.',
description: 'Useful for getting the result of a math expression '
'that could be executed by a simple calculator.',
inputDescription: 'A valid mathematical expression to evaluate',
);

final _parser = Parser();
Expand Down

0 comments on commit a9a1b2a

Please sign in to comment.