Skip to content

Agent Handoffs do not seem to be handed off #30

Description

@ephraimrothschild

Handoff does not appear to continue the conversation with the new agent, or if it does, it seems to get dropped somewhere and whatever the last message is comes from the original agent rather than the one being handed off to.

For example, I tried the example provided in the example folder:

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	dotenv "github.com/joho/godotenv"
	swarmgo "github.com/prathyushnallamothu/swarmgo"
	"github.com/prathyushnallamothu/swarmgo/llm"
)

func transferToSpanishAgent(args map[string]interface{}, contextVariables map[string]interface{}) swarmgo.Result {
	spanishAgent := &swarmgo.Agent{
		Name:         "SpanishAgent",
		Instructions: "You only speak Spanish.",
		Model:        "gpt-4",
	}
	return swarmgo.Result{
		Agent: spanishAgent,
		Data:  "Transferring to Spanish Agent.",
	}
}
func main() {
	dotenv.Load()

	client := swarmgo.NewSwarm(os.Getenv("OPENAI_API_KEY"), llm.OpenAI)

	englishAgent := &swarmgo.Agent{
		Name:         "EnglishAgent",
		Instructions: "You only speak English.",
		Functions: []swarmgo.AgentFunction{
			{
				Name:        "transferToSpanishAgent",
				Description: "Transfer Spanish-speaking users immediately.",
				Parameters: map[string]interface{}{
					"type":       "object",
					"properties": map[string]interface{}{},
				},
				Function: transferToSpanishAgent,
			},
		},
		Model: "gpt-4",
	}

	messages := []llm.Message{
		{Role: "user", Content: "Hola. ¿Cómo estás?"},
	}

	ctx := context.Background()
	response, err := client.Run(ctx, englishAgent, messages, nil, "", false, false, 5, true)
	if err != nil {
		log.Fatalf("Error: %v", err)
	}

	fmt.Printf("%s: %s\n", response.Agent.Name, response.Messages[len(response.Messages)-1].Content)
}

When using a debugger, here is the what the response messages look like:

Image

This seems to happen across the board, and the response I'm expecting doesn't show up, and instead it seems to look like a response that would come from the original agent doing the handoff.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions