Repository: google/adk-go
File: internal/llminternal/agent_transfer_test.go (Go)

Code before:
	t.Run("AgentWithDisallowTransfer", func(t *testing.T) {
		curAgent := utils.Must(llmagent.New(llmagent.Config{
			Name:                     "Current",
			Model:                    model,
			DisallowTransferToParent: true,
			DisallowTransferToPeers:  true,
		}))
		peer := utils.Must(llmagent.New(llmagent.Config{
			Name:  "Peer",
			Model: model,
		}))
		root := utils.Must(llmagent.New(llmagent.Config{
			Name:      "Parent",
			Model:     model,
			SubAgents: []agent.Agent{curAgent, peer},
		}))

		check(t, curAgent, root, "", nil, []string{"Parent", "Peer", "Current"})
	})
}

func TestAgentTransferProcessRequest_(t *testing.T) {
	// First Tool
	var req llm.Request
	printer := func(ctx tool.Context, input string) string {
		fmt.Print(input)
		return input
	}
	printerTool, err := tool.NewFunctionTool(
		tool.FunctionToolConfig{
			Name:        "print_input",
			Description: "Prints input.",
		},
		printer)
	if err != nil {
		t.Fatalf("NewFunctionTool failed: %v", err)
	}
	requestProcessor, ok := printerTool.(toolinternal.RequestProcessor)
	if !ok {
		t.Fatal("printerTool does not implement itype.RequestProcessor")
	}
	if err := requestProcessor.ProcessRequest(nil, &req); err != nil {
		t.Fatalf("printerTool.ProcessRequest failed: %v", err)
	}
	// Second tool
	transferToAgentTool := &llminternal.TransferToAgentTool{}
	if err := transferToAgentTool.ProcessRequest(nil, &req); err != nil {
		t.Fatalf("transferToAgentTool.ProcessRequest failed: %v", err)
	}

	if len(req.GenerateConfig.Tools) != 1 {

Review comment (bug):
left over for debug, or intended because it's a printer? :-)
It looks like what the function tool does is irrelevant to the tests. So, avoid `fmt.Print` and replace this with a more trivial function. (e.g. `sum`, `identity` ...) Same for other tests in tool/function_test.go

Code after:
		curAgent := utils.Must(llmagent.New(llmagent.Config{
			Name:                     "Current",
			Model:                    llm,
			DisallowTransferToParent: true,
			DisallowTransferToPeers:  true,
		}))
		peer := utils.Must(llmagent.New(llmagent.Config{
			Name:  "Peer",
			Model: llm,
		}))
		root := utils.Must(llmagent.New(llmagent.Config{
			Name:      "Parent",
			Model:     llm,
			SubAgents: []agent.Agent{curAgent, peer},
		}))

		check(t, curAgent, root, "", nil, []string{"Parent", "Peer", "Current"})
	})
}

func TestAgentTransfer_ProcessRequest(t *testing.T) {
	// First Tool
	var req model.LLMRequest
	handler := func(ctx tool.Context, x int) int {
		return x
	}
	identityTool, err := tool.NewFunctionTool(tool.FunctionToolConfig{
		Name:        "identity",
		Description: "returns the input value",
	}, handler)
	if err != nil {
		panic(err)
	}
	requestProcessor, ok := identityTool.(toolinternal.RequestProcessor)
	if !ok {
		t.Fatal("identityTool does not implement itype.RequestProcessor")
	}
	if err := requestProcessor.ProcessRequest(nil, &req); err != nil {
		t.Fatalf("identityTool.ProcessRequest failed: %v", err)
	}
	// Second tool
	transferToAgentTool := &llminternal.TransferToAgentTool{}
	if err := transferToAgentTool.ProcessRequest(nil, &req); err != nil {
		t.Fatalf("transferToAgentTool.ProcessRequest failed: %v", err)
	}

	if len(req.Config.Tools) != 1 {
		t.Errorf("number of tools should be one, got: %d", len(req.Config.Tools))
	}
	if len(req.Config.Tools[0].FunctionDeclarations) != 2 {
		t.Errorf("number of function declarations should be two, got: %d", len(req.Config.Tools[0].FunctionDeclarations))