mirror of
https://github.com/vxcontrol/langchaingo.git
synced 2026-07-21 00:45:22 -04:00
c2f9ad7f34
* agents: fix handling of observation suffix in tool inputs Add test coverage to ensure the executor properly trims nObservation: suffix from tool inputs before passing them to tools. This prevents tools from receiving malformed input that includes the observation marker. - Add TestExecutorTrimsObservationSuffix to verify trimming behavior - Add test case in MRKL output parser for action inputs with observation suffix - Add tools field to testAgent to support tool testing --------- Co-authored-by: Travis Cline <travis.cline@gmail.com>
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package agents
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/tmc/langchaingo/schema"
|
|
)
|
|
|
|
func TestMRKLOutputParser(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
testCases := []struct {
|
|
input string
|
|
expectedActions []schema.AgentAction
|
|
expectedFinish *schema.AgentFinish
|
|
expectedErr error
|
|
}{
|
|
{
|
|
input: "Action: foo Action Input: bar",
|
|
expectedActions: []schema.AgentAction{{
|
|
Tool: "foo",
|
|
ToolInput: "bar",
|
|
Log: "Action: foo Action Input: bar",
|
|
}},
|
|
expectedFinish: nil,
|
|
expectedErr: nil,
|
|
},
|
|
{
|
|
input: "Action: foo\nAction Input:\nbar\nbaz",
|
|
expectedActions: []schema.AgentAction{{
|
|
Tool: "foo",
|
|
ToolInput: "bar\nbaz",
|
|
Log: "Action: foo\nAction Input:\nbar\nbaz",
|
|
}},
|
|
expectedFinish: nil,
|
|
expectedErr: nil,
|
|
},
|
|
{
|
|
input: "Action: calculator\nAction Input: 5 + 3\nObservation:",
|
|
expectedActions: []schema.AgentAction{{
|
|
Tool: "calculator",
|
|
ToolInput: "5 + 3\nObservation:",
|
|
Log: "Action: calculator\nAction Input: 5 + 3\nObservation:",
|
|
}},
|
|
expectedFinish: nil,
|
|
expectedErr: nil,
|
|
},
|
|
}
|
|
|
|
a := OneShotZeroAgent{}
|
|
for _, tc := range testCases {
|
|
actions, finish, err := a.parseOutput(tc.input)
|
|
require.ErrorIs(t, tc.expectedErr, err)
|
|
require.Equal(t, tc.expectedActions, actions)
|
|
require.Equal(t, tc.expectedFinish, finish)
|
|
}
|
|
}
|