mirror of
https://github.com/vxcontrol/langchaingo.git
synced 2026-07-21 00:45:22 -04:00
agents: fix lint
This commit is contained in:
@@ -3,16 +3,15 @@ package executor
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
// ErrExecutorInputNotString is returned if an input to the executor call
|
||||
// function is not a string.
|
||||
// ErrExecutorInputNotString is returned if an input to the executor call function is not a string.
|
||||
ErrExecutorInputNotString = errors.New("input to executor not string")
|
||||
// ErrAgentNoReturn is returned if the agent returns no actions and no
|
||||
// finish.
|
||||
// ErrAgentNoReturn is returned if the agent returns no actions and no finish.
|
||||
ErrAgentNoReturn = errors.New("no actions or finish was returned by the agent")
|
||||
// ErrNotFinished is returned if the agent does not give a finish before
|
||||
// the number of iterations is larger then max iterations.
|
||||
// ErrNotFinished is returned if the agent does not give a finish before the number of iterations
|
||||
// is larger then max iterations.
|
||||
ErrNotFinished = errors.New("agent not finished before max iterations")
|
||||
// ErrUnknownAgentType is returned if the type given to the initializer is
|
||||
// invalid.
|
||||
// ErrUnknownAgentType is returned if the type given to the initializer is invalid.
|
||||
ErrUnknownAgentType = errors.New("unknown agent type")
|
||||
// ErrInvalidOptions is returned if the options given to the initializer is invalid.
|
||||
ErrInvalidOptions = errors.New("invalid options")
|
||||
)
|
||||
|
||||
@@ -36,11 +36,7 @@ func (e Executor) Call(ctx context.Context, inputValues map[string]any, _ ...cha
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nameToTool := make(map[string]tools.Tool, len(e.Tools))
|
||||
for _, tool := range e.Tools {
|
||||
nameToTool[tool.Name()] = tool
|
||||
}
|
||||
nameToTool := getNameToTool(e.Tools)
|
||||
|
||||
steps := make([]schema.AgentStep, 0)
|
||||
iterations := 0
|
||||
@@ -93,7 +89,7 @@ func (e Executor) GetOutputKeys() []string {
|
||||
return e.Agent.GetOutputKeys()
|
||||
}
|
||||
|
||||
func (e Executor) GetMemory() schema.Memory {
|
||||
func (e Executor) GetMemory() schema.Memory { //nolint:ireturn
|
||||
return memory.NewSimple()
|
||||
}
|
||||
|
||||
@@ -110,3 +106,12 @@ func inputsToString(inputValues map[string]any) (map[string]string, error) {
|
||||
|
||||
return inputs, nil
|
||||
}
|
||||
|
||||
func getNameToTool(t []tools.Tool) map[string]tools.Tool {
|
||||
nameToTool := make(map[string]tools.Tool, len(t))
|
||||
for _, tool := range t {
|
||||
nameToTool[tool.Name()] = tool
|
||||
}
|
||||
|
||||
return nameToTool
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
)
|
||||
|
||||
func TestMRKL(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if openaiKey := os.Getenv("OPENAI_API_KEY"); openaiKey == "" {
|
||||
t.Skip("OPENAI_API_KEY not set")
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"github.com/tmc/langchaingo/tools"
|
||||
)
|
||||
|
||||
const _defaultMaxIterations = 5
|
||||
|
||||
// AgentType is a string type representing the type of agent to create.
|
||||
type AgentType string
|
||||
|
||||
@@ -27,7 +29,7 @@ type Option func(p *options)
|
||||
func defaultOptions() options {
|
||||
return options{
|
||||
"verbose": false,
|
||||
"maxIterations": 3,
|
||||
"maxIterations": _defaultMaxIterations,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +60,12 @@ func Initialize(
|
||||
for _, opt := range opts {
|
||||
opt(&options)
|
||||
}
|
||||
var agent agents.Agent
|
||||
maxIterations, ok := options["maxIterations"].(int)
|
||||
if !ok {
|
||||
return Executor{}, ErrInvalidOptions
|
||||
}
|
||||
|
||||
var agent agents.Agent
|
||||
switch agentType {
|
||||
case ZeroShotReactDescription:
|
||||
agent = mrkl.NewOneShotAgent(llm, tools, options)
|
||||
@@ -70,6 +76,6 @@ func Initialize(
|
||||
return Executor{
|
||||
Agent: agent,
|
||||
Tools: tools,
|
||||
MaxIterations: options["maxIterations"].(int),
|
||||
MaxIterations: maxIterations,
|
||||
}, nil
|
||||
}
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@ package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go.starlark.net/lib/math"
|
||||
"go.starlark.net/starlark"
|
||||
@@ -23,12 +24,13 @@ func (c Calculator) Name() string {
|
||||
return "calculator"
|
||||
}
|
||||
|
||||
// Call evaluates the input using a starlak evaluator and returns the
|
||||
// result as a string.
|
||||
// Call evaluates the input using a starlak evaluator and returns the result as a
|
||||
// string. If the evaluator errors the error is given in the result to give the
|
||||
// agent the ability to retry.
|
||||
func (c Calculator) Call(_ context.Context, input string) (string, error) {
|
||||
v, err := starlark.Eval(&starlark.Thread{Name: "main"}, "input", input, math.Module.Members)
|
||||
if err != nil {
|
||||
return "I don't know how to do that.", nil
|
||||
return fmt.Sprintf("error from evaluator: %s", err.Error()), nil //nolint:nilerr
|
||||
}
|
||||
|
||||
return v.String(), nil
|
||||
|
||||
@@ -21,8 +21,7 @@ var (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiKey string
|
||||
baseURL string
|
||||
apiKey string
|
||||
}
|
||||
|
||||
func New(apiKey string) *Client {
|
||||
|
||||
@@ -46,7 +46,7 @@ func (t Tool) Call(ctx context.Context, input string) (string, error) {
|
||||
result, err := t.client.Search(ctx, input)
|
||||
if err != nil {
|
||||
if errors.Is(err, internal.ErrNoGoodResult) {
|
||||
return "No good Google Search Result was found", nil
|
||||
return "No good Google Search Results was found", nil
|
||||
}
|
||||
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user