tmc / langchaingo

LangChain for Go, the easiest way to write LLM-based programs in Go
https://tmc.github.io/langchaingo/
MIT License
4.41k stars 598 forks source link

When I want to define two tools, I will get an error empty response #765

Open txfsxq opened 5 months ago

txfsxq commented 5 months ago

When I want to define two tools, I will get an error empty response

toolList := []tools.Tool{nex_tools.ProductAnalysis{}, nex_tools.SearchKeywords{}}

    a := NewOpenAIFunctionsAgent(llm,
        toolList,
        NewOpenAIOption().WithSystemMessage("you are a helpful assistant"),
        NewOpenAIOption().WithExtraMessages([]prompts.MessageFormatter{
            prompts.NewHumanMessagePromptTemplate("please be strict", nil),
        }),
    )

    executor := NewExecutor(a, toolList)

    if err != nil {
        t.Errorf("initialize error: %s", err)
        return
    }
    res, err := chains.Run(context.Background(), executor, "Recommend some products and analyze the first product")
    if err != nil {
        t.Errorf("run error: %s", err)
        return
    }

run error: empty response How to solve it?

devalexandre commented 5 months ago

I'll try reproduce it

txfsxq commented 5 months ago

When I only use one tool for calculation, I still get empty response

calculator := tools.Calculator{}

toolList := []tools.Tool{calculator}

a := agents.NewOpenAIFunctionsAgent(llm,
    toolList,
    agents.NewOpenAIOption().WithSystemMessage("you are a helpful assistant"),
    agents.NewOpenAIOption().WithExtraMessages([]prompts.MessageFormatter{
        prompts.NewHumanMessagePromptTemplate("please be strict", nil),
    }),
)

e := agents.NewExecutor(a, toolList)
require.NoError(t, err)

result, err := chains.Run(context.Background(), e, "What is 3 plus 5 equal to?") //nolint:lll
require.NoError(t, err)

fmt.Println(result)

require.True(t, strings.Contains(result, "8"),
    "correct answer 8 not in response")

run error: empty response