-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ric Szopa
authored and
Ric Szopa
committed
May 31, 2023
1 parent
5807988
commit 38a2d5c
Showing
7 changed files
with
276 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 12 additions & 14 deletions
26
agent/react/react_prompt.md → agent/react/templates/react_prompt.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package react | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sort" | ||
) | ||
|
||
// Tool is a interface encapsulating a tool that can be used by the agent. | ||
type Tool interface { | ||
// Name returns the name of the tool. | ||
Name() string | ||
// Description returns a description of the tool. | ||
Description() string | ||
// Input returns what kind of input the tool expects. | ||
Input() string | ||
// Work runs the tool. The observation is what is going to be passed to the | ||
// agent. | ||
Work(ctx context.Context, argument, content string) (observation string, err error) | ||
} | ||
|
||
type toolbox struct { | ||
tools map[string]Tool | ||
} | ||
|
||
func (box *toolbox) Tools() (tools []Tool) { | ||
tools = make([]Tool, 0, len(box.tools)) | ||
for _, tool := range box.tools { | ||
tools = append(tools, tool) | ||
} | ||
|
||
// We want them sorted by name. | ||
sort.Slice(tools, func(i, j int) bool { | ||
return tools[i].Name() < tools[j].Name() | ||
}) | ||
|
||
return tools | ||
} | ||
|
||
func newToolbox(tools ...Tool) *toolbox { | ||
tb := &toolbox{ | ||
tools: make(map[string]Tool), | ||
} | ||
for _, tool := range tools { | ||
tb.tools[tool.Name()] = tool | ||
} | ||
return tb | ||
} | ||
|
||
func (box *toolbox) Work(ctx context.Context, argument, content string) (observation string, err error) { | ||
tool, ok := box.tools[argument] | ||
if !ok { | ||
return "", fmt.Errorf("unknown tool: %q", argument) | ||
} | ||
return tool.Work(ctx, argument, content) | ||
} |
Oops, something went wrong.