package discussant

import (
	"context"
	"fkteams/agents/common"
	"fkteams/config"
	"fmt"

	"fkteams/agentcore"
)

func NewAgent(ctx context.Context, member config.TeamMember) (agentcore.Agent, error) {
	cfg := config.Get()
	modelCfg := cfg.ResolveModel(member.Model)
	if modelCfg == nil {
		return nil, fmt.Errorf("模型 %q 未在配置文件中定义", member.Model)
	}

	chatModel, err := common.NewChatModelWithModelConfig(modelCfg)
	if err != nil {
		return nil, fmt.Errorf("create chat model: %w", err)
	}

	return common.NewAgentBuilder(member.Name, member.Desc).
		WithInstruction(discussantPrompt).
		WithModel(chatModel).
		WithSummary().
		Build(ctx)
}
