Skip to content

Commit a0a346a

Browse files
authored
fix(adk): disable automatic instruction rendering in DeepAgent (#726)
1 parent d970d34 commit a0a346a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

adk/prebuilt/deep/deep.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,24 @@ func New(ctx context.Context, cfg *Config) (adk.ResumableAgent, error) {
114114
MaxIterations: cfg.MaxIteration,
115115
Middlewares: append(middlewares, cfg.Middlewares...),
116116

117+
GenModelInput: genModelInput,
117118
ModelRetryConfig: cfg.ModelRetryConfig,
118119
OutputKey: cfg.OutputKey,
119120
})
120121
}
121122

123+
func genModelInput(ctx context.Context, instruction string, input *adk.AgentInput) ([]*schema.Message, error) {
124+
msgs := make([]*schema.Message, 0, len(input.Messages)+1)
125+
126+
if instruction != "" {
127+
msgs = append(msgs, schema.SystemMessage(instruction))
128+
}
129+
130+
msgs = append(msgs, input.Messages...)
131+
132+
return msgs, nil
133+
}
134+
122135
func buildBuiltinAgentMiddlewares(withoutWriteTodos bool) ([]adk.AgentMiddleware, error) {
123136
var ms []adk.AgentMiddleware
124137
if !withoutWriteTodos {

adk/prebuilt/deep/deep_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,40 @@ import (
3232
"github.com/cloudwego/eino/schema"
3333
)
3434

35+
func TestGenModelInput(t *testing.T) {
36+
ctx := context.Background()
37+
38+
t.Run("WithInstruction", func(t *testing.T) {
39+
input := &adk.AgentInput{
40+
Messages: []*schema.Message{
41+
schema.UserMessage("hello"),
42+
},
43+
}
44+
45+
msgs, err := genModelInput(ctx, "You are a helpful assistant", input)
46+
assert.NoError(t, err)
47+
assert.Len(t, msgs, 2)
48+
assert.Equal(t, schema.System, msgs[0].Role)
49+
assert.Equal(t, "You are a helpful assistant", msgs[0].Content)
50+
assert.Equal(t, schema.User, msgs[1].Role)
51+
assert.Equal(t, "hello", msgs[1].Content)
52+
})
53+
54+
t.Run("WithoutInstruction", func(t *testing.T) {
55+
input := &adk.AgentInput{
56+
Messages: []*schema.Message{
57+
schema.UserMessage("hello"),
58+
},
59+
}
60+
61+
msgs, err := genModelInput(ctx, "", input)
62+
assert.NoError(t, err)
63+
assert.Len(t, msgs, 1)
64+
assert.Equal(t, schema.User, msgs[0].Role)
65+
assert.Equal(t, "hello", msgs[0].Content)
66+
})
67+
}
68+
3569
func TestWriteTodos(t *testing.T) {
3670
m, err := buildBuiltinAgentMiddlewares(false)
3771
assert.NoError(t, err)

0 commit comments

Comments
 (0)