package agents import ( "context" "encoding/json" "fmt" "strings" "g.fc.run/ai/byre/internal/mcp" "g.fc.run/ai/byre/internal/store" ) const messageLeadGuidance = "\n- To contact the human's lead agent, use message_lead with a self-contained message (for example, a task brief the human asked you to pass along). You don't need to find a session or ask the human to paste it. Your final messages also reach the lead automatically." func (m *Manager) messageLeadTool(l *live) mcp.Tool { return mcp.Tool{ Name: "message_lead", Description: "Send a message to this task creator's lead agent. Use it to pass along a task brief, request coordination, or share information the lead needs before your turn ends. Include all the context the lead needs; it cannot see your conversation. Your final messages already reach the lead automatically.", InputSchema: json.RawMessage(`{"type":"object","properties":{"text":{"type":"string","description":"A self-contained message for the lead."}},"required":["text"]}`), Handler: mcp.Typed(func(ctx context.Context, args struct { Text string `json:"text"` }) (string, error) { text := strings.TrimSpace(args.Text) if text == "" { return "", fmt.Errorf("%w: text must not be empty", ErrInvalid) } task, err := m.store.GetTask(ctx, l.taskID) if err != nil { return "", err } _, found, err := m.activeLead(ctx, task.CreatedBy) if err != nil { return "", err } if !found { return "", fmt.Errorf("%w: %s has no lead agent to receive the message", ErrConflict, task.CreatedBy) } signal := fmt.Sprintf("Message from the agent working on %s (project %s):\n\n%s", m.taskLabel(ctx, task.Id), task.ProjectId, text) err = m.addLeadInput(ctx, store.LeadInput{Owner: task.CreatedBy, Kind: store.LeadSignal, Actor: "byre", Text: signal}) if err != nil { return "", err } return "Message sent to the lead.", nil }), } }