Skip to content

Commit 6f1aa2f

Browse files
committed
pkg/aflow: ask LLM to call several tools at the same time
This seems to help a bit with number of round-trips.
1 parent cd434a0 commit 6f1aa2f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pkg/aflow/flow_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestWorkflow(t *testing.T) {
184184
if replySeq < 4 {
185185
assert.Equal(t, model, "model1")
186186
assert.Equal(t, cfg.SystemInstruction, genai.NewContentFromText("You are smarty. baz"+
187-
llmOutputsInstruction, genai.RoleUser))
187+
llmMultipleToolsInstruction+llmOutputsInstruction, genai.RoleUser))
188188
assert.Equal(t, cfg.Temperature, genai.Ptr[float32](0))
189189
assert.Equal(t, len(cfg.Tools), 3)
190190
assert.Equal(t, cfg.Tools[0].FunctionDeclarations[0].Name, "tool1")
@@ -444,7 +444,7 @@ func TestWorkflow(t *testing.T) {
444444
Name: "smarty",
445445
Model: "model1",
446446
Started: startTime.Add(4 * time.Second),
447-
Instruction: "You are smarty. baz" + llmOutputsInstruction,
447+
Instruction: "You are smarty. baz" + llmMultipleToolsInstruction + llmOutputsInstruction,
448448
Prompt: "Prompt: baz func-output",
449449
},
450450
{
@@ -586,7 +586,7 @@ func TestWorkflow(t *testing.T) {
586586
Model: "model1",
587587
Started: startTime.Add(4 * time.Second),
588588
Finished: startTime.Add(17 * time.Second),
589-
Instruction: "You are smarty. baz" + llmOutputsInstruction,
589+
Instruction: "You are smarty. baz" + llmMultipleToolsInstruction + llmOutputsInstruction,
590590
Prompt: "Prompt: baz func-output",
591591
Reply: "hello, world!",
592592
Results: map[string]any{

pkg/aflow/llm_agent.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ It must be called exactly once before the final reply.
9393
Ignore results of this tool.
9494
`
9595

96+
const llmMultipleToolsInstruction = `
97+
Prefer calling several tools at the same time to save round-trips.
98+
`
99+
96100
const llmMissingOutputs = `You did not call set-results tool.
97101
Please call set-results tool to provide results of the analysis.
98102
`
@@ -210,6 +214,9 @@ func (a *LLMAgent) chat(ctx *Context, cfg *genai.GenerateContentConfig, tools ma
210214
func (a *LLMAgent) config(ctx *Context) (*genai.GenerateContentConfig, string, map[string]Tool) {
211215
instruction := formatTemplate(a.Instruction, ctx.state)
212216
toolList := a.Tools
217+
if len(toolList) != 0 {
218+
instruction += llmMultipleToolsInstruction
219+
}
213220
if a.Outputs != nil {
214221
instruction += llmOutputsInstruction
215222
toolList = append(toolList, a.Outputs.tool)

0 commit comments

Comments
 (0)